Opening a swf file from another swf with different default values

I hope this will not be considered as asking the same question twice ...

So, I am working on a Flash website (in AS2) that has an external swf index that loads sub swf files using loadMovie("subfoo1.swf", placeToShowSwf) . They, in turn, download an xml file that tells which content to download. Everything works peachy, but we would like to add a button to the swf index, which opens the sub swf file with one or two different values ​​for one or two variables.

Unfortunately, just adding a button that says

 loadMovie("foo1.swf", placeToShowSwf); placeToShowSwf.openProject(x); 

not working, I assume openProject(x) is being called in a file that is not fully loaded. I know that there is no problem with the code because I made a button in another place that only calls placeToShowSwf.openProject(x) and there are no problems.

I see two solutions, both of which I'm not sure how to do.

  • Change the desired value when the swf file is created, for example, the constructor for the class. But is there any constructor function for swf files? It would be very nice to say loadMovie(new foo1.swf(x), placeToShowSwf) or something like that.
  • Wait until swf (and probably xml) is loaded, and then call placeToShowSwf.openProject(x) .

Has anyone received any guidance on any of these solutions, or perhaps in a different way that my brain could not understand?

+4
source share
4 answers

Number 2 is what you should do. Unfortunately, you are still stuck in the land of ActionScript 1, and ActionScript 3 has been around for a couple of years. So I don’t know the exact syntax (first I started with flash on ActionScript 2), but # 2 (expecting SWF to finish loading and then tell me what to do) is what I will do.

If you don't mind learning a bit of AS2 (you can easily mix AS1 and AS2 without too much trouble) then you should watch MovieClipLoader. It provides callbacks to inform you when the sub SWF has finished loading.

0
source

Three easy ways to approach this:

(1) - change the direction of the team. That is, in the parent SWF, you have:

 projectType = "x"; loadMovie("foo1.swf", placeToShowSwf); 

And this SWF file (downloaded) has:

 openProject( _parent.projectType ); 

You get the idea. This will not work if the child SWF is loaded from another server, unless you specify problems with cross-domain scripts.

(2) - wait for the MC to load. Unfortunately, AS2 does not have built-in load events that you can use, so a common method is to use onEnterFrame as follows:

 someMovieClip.onEnterFrame = function() { if ( path_to.placeToShowSwf.openProject ) { path_to.placeToShowSwf.openProject(x); this.onEnterFrame = null; } } 

This will be if you want to call the method as soon as it is available; if you want to wait until the child swf is fully loaded, you want to check the SWF getBytesLoaded() and getBytesTotal() methods for children.

(3) Use a component like MovieClipLoader to complete the download - just follow the docs . Below the surface, this is similar to (2), but the details are tidied up inside the MovieClipLoader class.

0
source

The fenomas answers are pretty decent, but there are also less "hacked" if you use AS2, load swfs using the MovieClipLoader class. It has events that you can listen to, and you will be interested in the onLoadInit Event. Although people can understand that it fires when the boot process is initialized, and onLoadComplete is what you need to use, it is not.

onLoadComplete starts when all bytes complete loading onLoadInit starts when all ended byte loads and classes in loaded swf are initialized (so you can access the loaded SWF files methods and properties)

Take a look at the sample code in MovieClipLoader> onLoadInit in the as2.0 documentation

http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/js/html/wwhelp.htm?href=Part4_ASLR2.html

Good luck.

0
source

The way you did this is correct, except that you need to wait for the onLoadInit callback before trying to access your sub-click.

0
source

All Articles