gotoAndPlay vs calling a .swf file

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
mariana
Posts: 77
Joined: 26 Mar 2007, 11:15
Location: Buenos Aires, Argentina

gotoAndPlay vs calling a .swf file

Postby mariana » 14 Aug 2007, 14:52

My game needs several (some 5-6) quite separate functions, which include calls to graphics, etc.

I have 2 possible strategies:

1. from one "parent" .swf file I call all the other functions, each residing in its own swf file, which then returns control to the parent swf file; or

2. I have only one big swf file and use "gotoAndPlay" to go to different frames where I place each of the functions and then return control to the "game" frame.

Up to now, I've been using strategy 1 (it is easier to program) and it works well on a local server situation (127.0.0.0); I don't know what will happen once I go internet with it.

It would be easy to change over to strategy 2; however, I remember once getting this advice from Lapo:

Actually frame changes in multiplayer apps (which rely on asynchronous messages) are quite evil! Twisted Evil You should reduce them to the minimum possible.


Can somebody advise which is the best way to go? :(

Thank you,

Mariana
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 14 Aug 2007, 15:29

Yep, Lapo is right as always :)

Anyway if you don't want for some reason to load external swf you can place the functions you need to movieclips and place them on the same frame.

Btw what you mean with function - may be it's better to use objects(objects in the meaning of OOP).
User avatar
mariana
Posts: 77
Joined: 26 Mar 2007, 11:15
Location: Buenos Aires, Argentina

Postby mariana » 15 Aug 2007, 16:14

Thanks for your answer, Patso.

What I mean by a function is a complete .fla file, which contains several movieclips, buttons, etc. and has fairly complicated code. So I came up with this idea of just loading the resulting .swf files into a blank movieclip in my "base" screen. ( I have about 5 different .fla files...)

I don't know how I could make all these .fla files into as many movieclips, can you point me in the right direction?

Again, thanks

Mariana
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 15 Aug 2007, 16:36

First I want to clarify something - the variant with loading external swf in most cases is the best one. But because you've asked I've decide that may be there is some reason because you don't to load external swf files or consider it as bad idea.

mariana wrote:I don't know how I could make all these .fla files into as many movie clips, can you point me in the right direction?


Depends on the .fla files structure - if they are single frames(contains only one frame) I have one idea. Maybe it'll work if there are more than one frames - not sure. If you really want to do that i'll check.

p.s. The last paragraph maybe is better to be read as "I don't know" :) .
User avatar
mariana
Posts: 77
Joined: 26 Mar 2007, 11:15
Location: Buenos Aires, Argentina

Postby mariana » 16 Aug 2007, 07:57

Patso:
the reason I dont want to use a multiple "swf" file solution is because I think it may not be good for users to have to download several files over the Internet as the game calls for them.... it may be better to just wait at the start of the game for one big file and then start playing without interruptions.

Do you agree with this?

My .fla files have several frames each, and each fla file contains several movieclips with 3-4 frames each. :cry:

Anyway what is SO wrong about changing frames in multiplayer games? is there anything documented?

Thanks,
Mariana
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 16 Aug 2007, 14:38

Anyway what is SO wrong about changing frames in multiplayer games? is there anything documented?


Nothing in particular, but in general it doesn't help having code in multiple places... it makes it more difficult the debugging and maintenance processes. In a multiplayer application there's an evil scenario when you fire a server request on one frame but you handle the response on another one, which your jumping to.

It might happen that the server response arrived before the response handler in your new frame is ready to do its work
Lapo
--
gotoAndPlay()
...addicted to flash games
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Postby patso » 16 Aug 2007, 17:21

To what Lapo says I want just to add that in apps that rely on asynchronous messages you may have some synch issues. Solving this issues can be hard if your application is with multiple frames.
(off topic: in the list of the words that may be included in the reserved words in the future versions of AS in synchronize - so who know may be well have synchronize in Flash at last)

Also by my opinion frames are only for animations - they must not be used for performing actions such as displaying dialog boxes, panels and other thing of this kind. Especially with the new Display architecture introduced in Flash CS3. There is nothing so bad to use the frames in such manner but the code will be hard to maintain - searching AS code in multiple frames make the code less readable and less extensive.

Code: Select all

the reason I dont want to use a multiple "swf" file solution is because I think it may not be good for users to have to download several files over the Internet as the game calls for them.... it may be better to just wait at the start of the game for one big file and then start playing without interruptions.


Basically minimizing the number of files is good practice (more about how to increase your site performance you can read here - http://developer.yahoo.com/performance/rules.html#num_http). But in this case we talk about swf files - they are a bit larger than javascript and css - even the image files - so the time for the initiating HTTP session it's not such a big percentage. Also five is not so big number.

Also I want to say few things. After Flash downloads the movie clip it caches it so next time you try to download it just takes it from the cache.
Next you can load the external swf only once - you don't have to download them every time you call them.

Now - for the user is all the same if you load 1 or 100 swf files. For him/her just meters the speed with which it downloads the app.

Here is some tricks:

* Let's suppose you app consist of lobby and game. So you can do this - just load the lobby(instead the lobby + game) and then display it. So we reduce the time from the moment user click on the link that opens the flash and the moment he/she can interact with it. Now you can do two things:
1. Load the game in the background - while the user is in the lobby you can load the whole(or at least part of the game). If it tries to play before the game is loaded you can display the loading progress bar. This way we reduce the overall time user waits the app to download.
2. Load the game after the user begins new game - this way we split the wait time in two.

Of course 1. can be implemented even in single swf but only if it's with multiple frames - for example you can wait to load the frame with the lobby not for the entire movie. The flash player will download the rest of the swf in background - you need just to add load progress code before the game frame. If it's loaded ok - go ahead - if it's not just show the progress bar and wait :) .

Of course this is simple example - external swf have other advantages. Lapo promise to post an article about that how to increase the app security loading external swf (actually this will increase the download time too because the swf are not cached and the user must download them again next time he/she visit the site). But it shows that it's possible using multiple swf to reduce the time the user waits the app to download.

I hope I've been useful and this post help you to orient in the jungle of the swf :).
User avatar
mariana
Posts: 77
Joined: 26 Mar 2007, 11:15
Location: Buenos Aires, Argentina

Postby mariana » 17 Aug 2007, 16:43

Hey, thanks, Patso, and Lapo, your comments are very useful; I will wait to read Lapo's article before making a final decision. Meanwhile I continue testing my .fla files one by one (I have a "tester" .fla file for each one to make this task doable).

Also, I'm going to look into Flash CS3 to see what you mean by their new Display architecture.

Normally, Flash documentation is awful.... can you suggest somewhere I can read about CS3 without wasting HOURS at the screen?

Mariana

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 36 guests