2 Replies Latest reply on Aug 6, 2009 1:55 PM by kglad

    HELP!!! how to call actionscript on specific frames??

    TheMskel Level 1

      My actionscript plays through out the entire animation. Is there a way to have it play on specific frames? Here is the code I'm using:

       

      package{
         
          import flash.display.*;
          import flash.geom.*
          import flash.events.Event;
         
          public class Particle extends Sprite {
             
              private var _xpos:Number;
              private var _ypos:Number;
              private var _xvel:Number;
              private var _yvel:Number;
              private var _grav:Number;

       

              public function Particle(xp:Number, yp:Number, xvel:Number, yvel:Number, grav:Number, col:uint) {
                  _xpos = xp;
                  _ypos = yp;
                  _xvel = xvel
                  _yvel = yvel
                  _grav = grav;
                 
                  var ball:Sprite = new Ball();
                  addChild(ball);
                 
                  x = _xpos;
                  y = _ypos;
                  alpha = .8;
                  scaleX = scaleY = Math.random() * 1.9 + .1;
                 
                 
                 
                  addEventListener(Event.ENTER_FRAME, onRun, false, 0, true);
              }
             
              private function onRun(evt:Event):void {
                  _yvel += _grav;
                  _xpos += _xvel;
                  _ypos += _yvel;
                  x = _xpos;
                  y = _ypos;
                  if (_xpos < 0 || _ypos < 0 || _xpos > stage.stageWidth || _ypos > stage.stageHeight) {
                     removeEventListener(Event.ENTER_FRAME, onRun);
                     parent.removeChild(this);
                  }
              }
          }
      }

       

      package {

       

          import flash.display.Sprite;
          import flash.events.Event;

       

          public class ParticleDemo extends Sprite {

       

              public var emitterX:Number = 700;
              public var emitterY:Number = 350;

       

              public function ParticleDemo() {
                  stage.addEventListener(Event.ENTER_FRAME,onLoop, false, 0, true);
              }
             
              private function onLoop(evt:Event):void {
                  var p:Particle = new Particle(emitterX,
                                                emitterY,
                                                Math.random()*11 - 6,
                                                Math.random()*-20,
                                                1,
                                                Math.random()*0xFFFFFF);
                  addChild(p);
              }
             
          }
      }