AS3 external as alpha problem

  • Rika
  • Newbie
  • Newbie
  • Rika
  • Posts: 14
  • Loc: Singapore

Post 3+ Months Ago

I have created an object class with a ball. Trying to make the ball fade in, however i do not know where to insert ball.alpha = 0;
Can anyone help with this?

Code: [ Select ]
package //DOCUMENT CLASS
{
    import flash.display.Sprite;
    import flash.events.*;
    
    public class learnEasing3 extends Sprite
    {
        private var ball:Ball;
        private var targetAlpha:Number=1; //where to insert ball.alpha=0;
        private var easing:Number = 0.2;
        
        public function learnEasing3()
        {
            init();
        }
        private function init():void
        {
            ball = new Ball();
            addChild(ball);
            addEventListener(Event.ENTER_FRAME, onEnter);
        }
        
        private function onEnter(event:Event):void
        {
            var vx:Number = (mouseX - ball.x) * easing;
            var vy:Number = (mouseY - ball.y) * easing;
            ball.x += vx;
            ball.y += vy;
            ball.alpha += (targetAlpha - ball.alpha)*easing;

        }
    }
}
  1. package //DOCUMENT CLASS
  2. {
  3.     import flash.display.Sprite;
  4.     import flash.events.*;
  5.     
  6.     public class learnEasing3 extends Sprite
  7.     {
  8.         private var ball:Ball;
  9.         private var targetAlpha:Number=1; //where to insert ball.alpha=0;
  10.         private var easing:Number = 0.2;
  11.         
  12.         public function learnEasing3()
  13.         {
  14.             init();
  15.         }
  16.         private function init():void
  17.         {
  18.             ball = new Ball();
  19.             addChild(ball);
  20.             addEventListener(Event.ENTER_FRAME, onEnter);
  21.         }
  22.         
  23.         private function onEnter(event:Event):void
  24.         {
  25.             var vx:Number = (mouseX - ball.x) * easing;
  26.             var vy:Number = (mouseY - ball.y) * easing;
  27.             ball.x += vx;
  28.             ball.y += vy;
  29.             ball.alpha += (targetAlpha - ball.alpha)*easing;
  30.         }
  31.     }
  32. }


Code: [ Select ]
package //OBJECT CLASS
{
    import flash.display.Sprite;
    public class Ball extends Sprite
    {
        public var radius:Number;
        private var color:uint;
        public function Ball(radius:Number=30, color:uint=0xff0000)
        {
            this.radius = radius;
            this.color = color;
            this.alpha = 1;
            
            init();
        }
        public function init():void
        {
            graphics.beginFill(color);
            graphics.drawCircle(0, 0, radius);
            graphics.endFill();
        }
    }
}
  1. package //OBJECT CLASS
  2. {
  3.     import flash.display.Sprite;
  4.     public class Ball extends Sprite
  5.     {
  6.         public var radius:Number;
  7.         private var color:uint;
  8.         public function Ball(radius:Number=30, color:uint=0xff0000)
  9.         {
  10.             this.radius = radius;
  11.             this.color = color;
  12.             this.alpha = 1;
  13.             
  14.             init();
  15.         }
  16.         public function init():void
  17.         {
  18.             graphics.beginFill(color);
  19.             graphics.drawCircle(0, 0, radius);
  20.             graphics.endFill();
  21.         }
  22.     }
  23. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • zhaojany
  • Student
  • Student
  • User avatar
  • Posts: 79

Post 3+ Months Ago

Fade in for once, just insert the "ball.alpha = 0" right after it is instanced ("ball = new Ball(); ball.alpha = 0").

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 11 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.