Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

actionscript _currentframe from within a symbol

Status
Not open for further replies.

peterworth

Programmer
Aug 18, 2004
80
GB
hi, i'm trying to use the current frame to determine what to do when an event occurs in a symbol, but _currentframe seems to always be 1 when the event gets triggered, no matter where in the animation we actually are. i guess this is because the script for the event handler is in frame 1 of the symbol's timeline. is there any way around this?

in this script:

this.onRollOut = function()
{
trace(_currentframe);
if (this._currentframe < 40)
{
gotoAndPlay("_out");
}
trace(_currentframe);
}

the first trace is always 1 (wrong) and the second trace is always 40 (right).
 
The best practice is to place your code in the main timeline, not in the symbol instance timeline:
Code:
//Main timeline
yourSymbolInstance.onRollOut = function() {
	trace(_currentframe);
};
If you want to place your code in the instance timeline, you'll need to do it like this:
Code:
//Your instance timeline
this.onRollOut = function() {
	trace(_parent._currentframe);
};


Kenneth Kawamoto
 
ah ok, i can see it would be good practice to keep things in the parent timeline, but that still doesnt solve the issue, because the information i need is the current frame of the symbol animation, not of the root timeline.

now i've got this in the main timeline:

BtnPageOne_mc.onRollOut = function()
{
trace(BtnPageOne_mc._currentframe);
if (BtnPageOne_mc._currentframe < 40)
{
BtnPageOne_mc.gotoAndPlay("_out");
}
trace(BtnPageOne_mc._currentframe);
}

and the first trace is still always coming out as 1, even if the anamination is midway through.
 
Sorry, I thought you wanted to get the main timeline's current frame!

Code:
BtnPageOne_mc.onRollOut = function() {
	trace(this._currentframe);
};

If your trace is 1, then the current frame is indeed 1. You can verify that with Debugger (Control > Debug Movie).


Kenneth Kawamoto
 
thanks, i'm now using onEnterFrame to update a variable every frame, so that i can use this variable in other event handlers to check which frame the animation is in. not sure if this is the right way to do it though?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top