Copy link to clipboard
Copied
Hi,
I can I get this class to store the last frame number so I can use it in the next frame I go to?
package {
public class GlobalNumber {
private var _theNumber:Number;
public function GlobalNumber(num:Number) {
_theNumber=num;
}
public function set theNumber(num:Number):void {
_theNumber=num;
}
public function get theNumber() {
return _theNumber;
}
}
}
On frame 1
import GlobalNumber; // imports the class
var frameNumber:GlobalNumber = new GlobalNumber(1); // creates an instance of the class and sets the value = 1
trace(frameNumber) // 1 (playhead is arriving from frame 2 then I want it to =2 NOT =1)
On frame 2
frameNumber.theNumber = currentFrame;
// sets the class variable to 2
but when I mouseDown on a movieClip and send the playhead back to frame 1 the variable = 1 again
Is it because it's recreating the variable?
Should I delete the variable? If I do, how would I store the value?
The ultimate goal is to remember the last frame I was on.
thanks,
Copy link to clipboard
Copied
You could try making your getter and setter static:
package {
public class GlobalNumber {
private static var _theNumber:Number;
public static function set theNumber(num:Number):void {
_theNumber=num;
}
public static function get theNumber() {
return _theNumber;
}
}
}
Then on the timeline frame 1:
import GlobalNumber;
trace(GlobalNumber.theNumber) // NAN first run, then 2 on return
GlobalNumber.theNumber=1
trace(GlobalNumber.theNumber) //1
And on frame 2:
trace(GlobalNumber.theNumber) // 1
GlobalNumber.theNumber=currentFrame
trace(GlobalNumber.theNumber) // 2
gotoAndStop(1);