Skip to main content
Participating Frequently
May 22, 2009
Answered

Control animation play() and stop() from class

  • May 22, 2009
  • 2 replies
  • 711 views

Hello,

I have created some functions to manage timed pause/play in an animation and I am trying to make a class from them, but it does not work, the play() and stop() functions I use have no effect. The functions work as intended when not in the class.

Here is my code:

package anim {
     import flash.utils.Timer;
     import flash.events.TimerEvent;
     import flash.display.MovieClip;
     
     public class Case extends MovieClip {

          public var tempsMulti:Number = 1.0;
          
          public function Case():void {
               trace("init");
               stop();
          }
          
          public function setTempsMulti(temps:Number):void {
               this.tempsMulti = temps;
          }

          public function attends(tps:Number):void {
               trace("attends");
               var temps:Number = tps * this.tempsMulti;
               
               var timer:Timer = new Timer(temps, 1);
               stop();
               
               timer.addEventListener("timer", this.suivant);
               timer.start();
          }
          
          private function suivant(event:TimerEvent):void {
               trace("suivant");
               play();
          }
     }
}

I checked that the functions are executed with the trace() and it is the case, so the problem really comes from the play() and stop() functions, and I do not receive any error at compilation or runtime.

Thanks for your help.

This topic has been closed for replies.
Correct answer kglad

and instantiating a class member that way is why it doesn't work.  lacase doesn't have graphic presence.  and if it did it still wouldn't be displayed because you didn't add it to the display list.

try this:  remove the code from your fla, click on an empty part of the stage (or off-stage) and in the properties panel where is has a document class box type anim.Case then retest.

2 replies

PalcaAuthor
Participating Frequently
May 22, 2009

Works fine now, thanks!

kglad
Community Expert
Community Expert
May 22, 2009

you're welcome.

kglad
Community Expert
Community Expert
May 22, 2009

the movieclip you're trying to control is a Case instance?

PalcaAuthor
Participating Frequently
May 22, 2009

The MovieClip is the Flash animation itself, so on the first frame of my animation, I just add this:

import anim.Case;

var lacase:Case = new Case();

And then I use the functions just like

lacase.attends(3000);

The functions work as I receive the trace() contents, but they have no effect.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 22, 2009

and instantiating a class member that way is why it doesn't work.  lacase doesn't have graphic presence.  and if it did it still wouldn't be displayed because you didn't add it to the display list.

try this:  remove the code from your fla, click on an empty part of the stage (or off-stage) and in the properties panel where is has a document class box type anim.Case then retest.