Ryan
Ryan

Reputation: 10049

Actionscript (AS3) : call function only if visible

I have an "intro" screen and I have a "play" screen.
As the intro screen starts it sets the play screen visible = false;

First the intro screen shows itself and the user has to press a button to go to the play screen, once the play screen shows itself actionscript moves a graphic from right to left.

The problem is that even when the play screen visible is false, it is still executing the actionscript (timers/enterframes etc)

is there some way to set the actionscript so that if self.visible==false dont play?

Please note that I am new to AS3/Flash and the code is in the movieclip itself not in a class.

Upvotes: 2

Views: 322

Answers (1)

Glitcher
Glitcher

Reputation: 1184

To do something totally automatically as you want it, you're best bet would be to extend the visible setter like so:

override public function set visible(value:Boolean):void
{
    if(value)
    {
        this.play();
    }
    else
    {
        this.stop();
    }
    super.visible = value;
}

that should go into your play screen's document class. If you're not using a document class this might work on the timeline.

Upvotes: 2

Related Questions