Have loaded a php variable into flash but cant apply it in a function
hi I have created an actionscript function whi开发者_StackOverflow社区ch stops an animation on a specific frame which works fine. I have then loaded in a php file with a variable which will contain the number for the frame i want the animation to stop on. This has loaded in fine and i have loaded it in a function. what i cant seem to do is to get the variable into the function which tells the animation to stop playing.
here is my code:
//load variables
varReceiver = new LoadVars(); // create an object to store the variables
varReceiver.load("http://playground.nsdesign6.net/percentage/external.php");
//load variables
//function1
varReceiver.onLoad = function() {
//value is the var that is created.
var paul = this.percentage;
}
//function1
//function2
this.onEnterFrame = function() {
if(this._currentframe==(percentage)) {
this.stop();
this.onEnterFrame = undefined;
}
}
play();
//function2
cheers paul
I think the problem is that percentage
is not defined within the scope of function2.
Try something like this:
//function1
varReceiver.onLoad = function() {
//value is the var that is created.
var _level0.paul = this.percentage;
}
//function1
//function2
this.onEnterFrame = function() {
if(this._currentframe==paul) {
this.stop();
this.onEnterFrame = undefined;
}
}
Another thing to be aware of is that you've already been through a couple of frames by the time your onLoad function is called, so maybe you should change your test in function2 to be if(this._currentframe>=paul)
just in case paul is a small number.
//load variables
var paul; // <- !!!
varReceiver = new LoadVars(); // create an object to store the variables
varReceiver.onLoad = function() {
//value is the var that is created.
paul = this.percentage; // <- !!!
play();
}
//function1
//function2
this.onEnterFrame = function() {
if(this._currentframe==(paul)) { // <- !!!
this.stop();
this.onEnterFrame = undefined;
}
}
//function2
varReceiver.load("http://playground.nsdesign6.net/percentage/external.php");
or better:
//load variables
varReceiver = new LoadVars(); // create an object to store the variables
varReceiver.onLoad = function() { // onLoad
if(this.percentage!=undefined){ // check if percentage exist
_root.onEnterFrame = function(){ // register event function
if(_currentframe == varRecivier.precentage) { // function body
_root.stop();
_root.onEnterFrame = null;
}
play();
}else{ // no variable "precentage" in loaded data
gotoAndPlay("error"); // loading error handling
}
}
精彩评论