19 Replies Latest reply on Oct 11, 2007 2:53 PM by kglad

    Problem with multiple .swf in the same page

    Yyyeah
      Hi everybody,

      I got a small animation written in actionscript 2.0. I need to load it several times in a webpage (about 20 instances), but seems to be too many work and the web browser freezes.

      Anyway, it's a relatively simple script (not complex arithmetics per cycle, although two or three color gradient refreshing), so I think the problem could be the fact of having so many instances running at the same time...

      Is there any way to fix this problem without reducing the quality of the animation?

      Thanks a lot!
        • 1. Re: Problem with multiple .swf in the same page
          kglad Adobe Community Professional & MVP
          when you say the web browser freezes do you really mean your animation stutters or do you really mean the animation stops?
          • 2. Re: Problem with multiple .swf in the same page
            Yyyeah Level 1
            The animation stops. In fact, the browser warns me about a script running that never stops, asking me if I want to stop it, but whatever I choose I have to force the application to close, receiving the typical "Application not responding..."
            • 3. Re: Problem with multiple .swf in the same page
              kglad Adobe Community Professional & MVP
              that's a coding (not optimization) problem: you have some coding error(s).

              start to debug by checking while-loops or for-loops that are not terminating.
              • 4. Re: Problem with multiple .swf in the same page
                Yyyeah Level 1
                I appreciate your interest, but there is no coding errors. The animation works fine if I got one instance running. The problem comes when I load too many of them at the same time.
                • 5. Re: Problem with multiple .swf in the same page
                  clbeech Level 3
                  kglad's right, you must have some conflicts in the code to get that error. I'm just guessing here, but it may be that you're calling to _root to get a variable for the animation and making adjustments to the variable in the same way. Depending on your method of loading the animations, this might be the problem considering that it runs fine as a single. If you call to the 'ground floor' so to speak, to retrieve a value that is named the same for each instance, it may be causing this problem. can you post the code you are using for the animation.
                  • 6. Problem with multiple .swf in the same page
                    Greg Dove Level 4
                    Can you clarify? Do you mean you are loading 20 instances of a separate swf into a single parent or by different "instances" do you mean completely separately embedded flash objects in the html.

                    If its the latter (kinda sounds like it) then perhaps its something else (It may be not a sensible thing to do - I would try to avoid doing things that way if its posible). I've never embedded 20 separate flash objects on the same web page so I couldn't say. If I absolutely had to make this work...then I'd be checking a) make sure you have completely unique object id attribute or name for the embed tags and b) Do all the instances try to use ExternalInterface or something unusual like that? i.e. perhaps the problem is outside flash. Beyond that.... I have no more ideas.


                    • 7. Re: Problem with multiple .swf in the same page
                      kglad Adobe Community Professional & MVP
                      umm, you want to bet about a coding error?

                      i'll bet i can get your application to run without freezing and without that warning and still load all 20 of your animations.
                      • 8. Problem with multiple .swf in the same page
                        Yyyeah Level 1
                        Sorry Kglad, I didn't mean to be rude. With "No coding errors" I meant the animation itself runs with no errors. I'm sure you could run the 20 instances with no freezing (that's why I put the post :) ) But I'm affraid it is an animation for a client, so I cannot distribute the code.

                        Perhaps I didnt explain the situation clearly enough (in part because of my poor english...).-
                        - By 20 instances I mean 20 separated embedded objects in the html
                        - The animation is relatively simple. A turned on candle, in each cycle I calculate the next position of the flame (that oscilates from left to right). The flame is composed by 4 concentric gradients. There is NO loops, only an 'onEnterFrame' function refreshing the flame each time.
                        - It's true that I got plenty variables at the _root level. If that could be the problem, how can I workaround it?
                        - It is my first time trying to embed so many objects at the same time too. No idea if the problem could be the way I embed the object from the html :(

                        - The only thing I can guess is that when a cycle of one of the object is running, the other 19 objects must wait their turn. That would explain why the more instances I run, the worst results I get. In that case, I wonder if there's a way to run them in a kind of asynchronous mode, just guessing...

                        Any other comment would be appreciated. Anyway, thanks a lot everybody for your colaboration.
                        • 9. Re: Problem with multiple .swf in the same page
                          Greg Dove Level 4
                          kglad: you're probably right...but if its the second scenario I described above and one 'player' is running OK... then it is possible also that it may not be internal. It is strange that the script timeout doesn't occur with one. There could be a memory leak I guess which would then be multiplied by 20 and killing the browser in which case you'll win your bet. I have previously also encountered a flash script timeout from an ExternalInterface call to what turned out to be some recursive javascript.
                          It also might be the lack of unique IDs on the embedding if the scenario I described above applies.

                          I just did a quick search and there have been historic issues with earlier players, so it may be an older player as well:

                          http://blog.scottgmorgan.com/php/default.php?topicID=170&contentID=739&rowID=127
                          • 10. Re: Problem with multiple .swf in the same page
                            Greg Dove Level 4
                            Yyyeah : just saw your reply: what embedding method are you using and do they all have unique IDs in the object tags for example?
                            • 11. Re: Problem with multiple .swf in the same page
                              Yyyeah Level 1
                              I've just looked GWD. I'm not too experienced embedding flash in html :(, I use the code that flash generates when I publish the movie, something like this

                              <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=" http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="200" height="500" id="VelaFinal" align="middle">
                              <param name="allowScriptAccess" value="sameDomain" />
                              <param name="allowFullScreen" value="false" />
                              <param name="movie" value="VelaFinal.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /> <embed src="VelaFinal.swf" quality="high" bgcolor="#000000" width="200" height="500" name="VelaFinal" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage=" http://www.macromedia.com/go/getflashplayer" />
                              </object>

                              Basicly, I copy/paste it till reach 20 (not too sofisticated, I guess...) So, if I got to change any Id, you're right, they're all the same... but not sure if you mean classid or id
                              • 12. Problem with multiple .swf in the same page
                                Greg Dove Level 4
                                No, not classid that needs to be the same. Each object tag needs a unique id attribute id="movie1" and then id="movie2" etc. Or in your case id="VelaFinal", id="VelaFinal2", id="VelaFinal3" etc
                                • 13. Re: Problem with multiple .swf in the same page
                                  Greg Dove Level 4
                                  And you need to match that in the embed tags for the name attribute
                                  • 14. Re: Problem with multiple .swf in the same page
                                    Greg Dove Level 4
                                    You should also be aware that just placing these tags in the page like that means a couple of things - a) the page is not valid xhtml - in case your client requires that and b) Internet explorer will have the click-to-activate behaviour.

                                    One way around that is to use either adobe's activecontent fix, swobject, ufo or or other javascript replacement methods. For what you're doing you could do all the embedding with a few lines of javascript instead of the large chunks of html that you have.
                                    • 15. Re: Problem with multiple .swf in the same page
                                      Yyyeah Level 1
                                      Ok, I tried with unique ids getting the same results :(
                                      I'll give it a try with some of those methods to load the script. Thank you very much!
                                      • 16. Re: Problem with multiple .swf in the same page
                                        Greg Dove Level 4
                                        It still could be exactly what kglad said. If you have a code error in each clip that is consuming memory. But you would need to post your code to get that fixed here and it seems you can't do that.
                                        • 17. Re: Problem with multiple .swf in the same page
                                          Yyyeah Level 1
                                          I'm affraid not. Anyway, at first I could only load less than 10 instances. I tried to simplify the animation (at first there were up to 5 gradients refreshing every frame, and when I erased 2 of them I could run up to 14 instances) Could it be the gradients that are consuming that memory?
                                          • 18. Re: Problem with multiple .swf in the same page
                                            Greg Dove Level 4
                                            Its pretty hard to answer that without seeing your code. Animating multiple gradients shouldn't continuously grow memory use if the number remains constant, but it might give your CPU a workout with that many 'players'- depending on your system specs and what the animation is doing (multiple gradients with alpha etc). If you're using windows just take a look at whats happening to memory and CPU usage for your browser in the process tab.

                                            I've got nothing left sorry. Beyond that kglad has the bet running and is obviously keen to review your code... and... unless you have some old player in your browser that's causing the problem... then I think he would win the bet. ;)
                                            • 19. Re: Problem with multiple .swf in the same page
                                              kglad Adobe Community Professional & MVP
                                              why are you embedding more than 1 swf in your html page?