I have a flash movie containing to scenes: scene1, scene2. I have chosen the order so that scene1 starts first, I was requested to add a functionality to allow flashvars to be passed, i开发者_如何学运维f fv_change equals one then scene2 should be the first to appear when the movie is loaded.
I have included the following code in scene1 first frame of some layer:
this.onEnterFrame = function() {
delete this.onEnterFrame;
if (isset==undefined && _root.fv_change && _root.fv_change==1) {
isset = true;
gotoAndStop("scene2",1);
}
}
when testing in my flash environment everything worked fine, when I exported it to an HTML & SWF combo I got random results, I refreshed the page several times and some of the times scene2 appeared and some of the times it stayed with scene1.
Am I doing something wrong? what is the correct way to change scene order using AS2 and external data(flashvars for that matter).
At a guess, it's probably failing to jump to Scene 2 in cases where that frame hasn't loaded yet - try testing it in the IDE with simulated loading (press ctrl+Enter twice) to be sure. If that's the problem, try adding a preloader until the frame you want (or the whole movie) is loaded. (See sample code here.)
Found a solution thanks to your proposal and some googeling. It seems the movie had not finished loading so what I did was create a scene named preloader which ran as the first scene. Inside it on Frame 2 (I found out that frame 1 doesn't always work best):
this.onEnterFrame = function(){
this.stop();
if(this.getBytesLoaded() >= this.getBytesTotal() && this.getBytesLoaded() > 0){
if (_root.fv_change && _root.fv_change ==1) {
_root.gotoAndPlay("frameLabelForScene2Frame1");
} else {
_root.gotoAndPlay("frameLabelForScene1Frame1");
}
delete this.onEnterFrame;
}
};
As you recall scene1 was supposed to run first. if a parameter was supplied scene2 was supposed to run first. The points I think should be emphasized are:
- Use the second frame on the preloader
- Have the code to wait for loading to finish
- IMPORTANT use frame labels instead of scene names with gotoAndPlay
- use _root.gotoAndPlay and not just gotoAndPlay.
- just to be safe I included the 'else' part, the preloader would go to scene1 eventually but I wanted to make sure it did
Hope this helps anyone
精彩评论