Skip to main content
Inspiring
July 22, 2007
Answered

using loadmovienum + calling function

  • July 22, 2007
  • 14 replies
  • 974 views
Hi,

I would like to load a new swf into level 2 (previously empty) and then - on the next line of the calling function - call a function in the newly loaded swf on level 2. Is this possible?

It seems to me that I should use an .onload event, or similar to determine if the new swf on level 2 has finished loading and the scripts in it are available. But what would I use, how would I determine that?

My script currently:

*********************
loadMovieNum("data/games/games.swf", 2);
tBGcolor = gamesArr[clickedUnit][2];
tGamePath = gamesArr[clickedUnit][1];
_level2.playGame(tBGcolor, tGamePath);
*********************

Many thanks,

Nik
This topic has been closed for replies.
Correct answer kglad
you can use something like:

14 replies

kglad
Community Expert
Community Expert
July 25, 2007
you're welcome.
nik_cAuthor
Inspiring
July 25, 2007
you are very good! I'd like to be able to write such short code that does that much!
It all works now and I have learnt a lot.
thanks, kglad

nik
nik_cAuthor
Inspiring
July 24, 2007
thanks - I thought of something along the lines of the watch(), but wasn't sure how to go about it in Flash (yet, -- kind of a steep learning curve on some things coming from Director .. ;)

nik-c

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
July 25, 2007
you can use something like:

kglad
Community Expert
Community Expert
July 24, 2007
there are several ways you could handle this.

you could just have the external swf call its own function when the data needed by that function are ready.

or you could use a watch() function in your _level0 swf that checks for a variable in your _level2 swf to change value indicating everything is ready to go for calling that _level2 swf.

or you could use a loop like onEnterFrame or setInterval to repeatedly check if the _level2 function is ready to use.
nik_cAuthor
Inspiring
July 24, 2007
OK, I think I know what is causing this current problem of mine. The external swf executes some XML loading code, that in itself has some stuff happening on the XMLs .onload (success).

So this may cause the code that depends on the successfull loading of the XMLs (there are 2) to execute after the 'normal' code of that first frame has executed and also after the 'lo.onLoadInit' has executed.

Is there a way of making the 'lo.onLoadInit' dependant on the successful loaing and execution of the XMLs? I got 2 scripts dependant on the XMLs (one constructing a menu based on the XML, the second one for configuring it)?

Thanks,
Nik
nik_cAuthor
Inspiring
July 23, 2007
Hi,

I have sorted most of the issues out now. It boild down to the 'lo.onLoadInit' actually not executing AFTER the first frames scripts, but before them. [for reference from the flash help page: The MovieClipLoader.onLoadInit handler is invoked after the actions in the first frame of the clip have executed, so you can begin manipulating the loaded clip. --> is this wrong then?]

This meant that the code on this script which sets up the games section ready with game one selected, always executed AFTER the playGame I wrote to set up the screen with the game, background colour,e tc I needed for the game.

In essence the way this worked was that I sent all the right stuff along to playGame, it was set up correctly, then the finctions on the page executed and undid everything.

Is there a way of getting my playGame to execute last? I have moved the script all the way down on the page, hoping it will have an effect on the order in which scripts are executed, but this didn't work.

Thanks.

NIk
kglad
Community Expert
Community Expert
July 23, 2007
frame 1 code in your external swf executes first, then the onLoadInit() method executes.
kglad
Community Expert
Community Expert
July 23, 2007
you're welcome.
nik_cAuthor
Inspiring
July 23, 2007
No, it won't solve my problem. Ithink there is something else not quite right with the assets I am loading in, or the path from the shell swf to the final games, I'll have to investigate ....

Thanks,
Nik
kglad
Community Expert
Community Expert
July 23, 2007
the path to games_bg_mc shouldn't be a problem if by, "This works fine when I access the games directly though." you mean the color changes when you call playGame from within your loaded swf. is that what you meant?

the setRGB() method works for as2 so that's not causing the problem. you'll have greater control of the color by using the color transform, but it won't solve your problem.
nik_cAuthor
Inspiring
July 23, 2007
Hi, yes, tBGcolor and tGamePath are defined and deliver the right values to playGame() .

Is there a way to further target the 'games_bg_mc' ? Could it be a path issue to the movieclip?

Should I use the flash.geom.ColorTransform instead? I just read in the help files that the color constructor has been deprecated?

Thanks,

Nik