4 Replies Latest reply on Jul 6, 2008 9:27 AM by Rothrock

    an unresolved issue that i need your help for

    elyelyely Level 1
      well let me explain the situation and get all of your opinion on this matter...

      a while back i worked on making where everytime i loaded the swf file it will load a random background. basically 1/3 will randomly load...

      the code i used was this one...

      var randomBg:int = Math.ceil(Math.random()*3);
      switch (randomBg) {
      case 1 :
      gotoAndStop(1);
      trace(1);
      break;
      case 2 :
      gotoAndPlay(2);
      trace(2);
      break;
      case 3 :
      gotoAndPlay(3);
      trace(3);
      break;
      default :
      gotoAndStop(3);
      trace(3);
      break;
      }


      well it will always load 2/3 backgrounds and never the third one when i try running it from the swf..(does this mean i need a preloader or a code issue...)

      but if publish it and run it from iexplorer then it works well and displays 3/3 on the backgrounds....

      so is my script buggy or its swf fault .....

      also i did further study.... right now in this scanrio my as3 code is placed in the first frame so at this point it would only load 2/3 backgrounds running via swf....BUT if i place the as3 in the third frame then it will properly display the random background 3/3.....

      so is it the place i put the code or the fact it should work properly if was placed in the first frame...

      thank you and any insight be good on this.... an unresolved issue in a long time...
        • 1. Re: an unresolved issue that i need your help for
          Rothrock Level 5
          I think this will be the last time I answer your question. And the answer is always the same! This actually has been resolved for a long time now!

          You need a preloader. If Frame 3 isn't loaded and the code runs then there is NO WAY for it to send the player to Frame 3! It is as simple as that. There is no other answer.

          If you put the code on frame 3 then of course it works because the code doesn't execute before frame 3 is loaded. Again very simple.

          Why is it you ask and ask and refuse to listen to the correct answer that is given to you?


          • 2. Re: an unresolved issue that i need your help for
            elyelyely Level 1
            i apologize sir/miss.

            i must of interpreted what you said differently.

            i will make a preloader and see how things perform. Its just the thing isnt heavy in graphics and yet unable to load third frame which surprises me...thats all

            but will try your method and i only asked unless there is another method of doing it...as you may agree two different people can do the same thing two different ways....

            thank you for understanding and will try a preloader
            • 3. Re: an unresolved issue that i need your help for
              elyelyely Level 1
              Well RothRock it worked i used a flash cs3 component UILOADER and it worked...i guess to use it for the rest of my app. the question is as graphics get more intense will i need to use a better preloader or this should do the job.

              thank you
              • 4. Re: an unresolved issue that i need your help for
                Rothrock Level 5
                Great. Glad that worked out for you. As for the futures. I'm not sure. Pretty much if it checks to see if the whole thing is loaded and that is what you want then that will work out just fine.

                However here are some things to think about.

                Most people who are developing their own stuff don't use the prebuilt flash components. The components do exactly what they do pretty well, but if you want to do something custom or a little different they just are a pain. Also some of them do have some very esoteric bugs or gotchas that just can make you crazy!

                Another problem down the road is if you start using items in your library and you export for Actionscript in the first frame. This puts the assets in the first frame of your swf. (You can't see them on stage but they are there!) All the content of the first frame must be loaded before the first frame of code can be executed. So this can cause the user to wait quite a bit before they actually see your preloader.

                The Flash components do this and put about a minimum of 80K or so in your first frame. So just be aware of that.

                So I would encourage you to build your own preloader code. Here is a basic set up that I might use to accomplish what you are doing. First make sure to delete the component from your library. Even if you don't use them, just having them in the library means they will be exported in the first frame and bloat your swf file. Next move your different back grounds to frames 2 to 4 and leave a blank key frame in frame 1. Then add the code bellow to frame 1.

                This doesn't give any feedback to the user. But that is easy enough to add. You could just put a simple little movie clip on frame one that spins and blinks the word loading. Or you could get more complex and use the percent value to scale a clip or feed a dynamic text box.

                Good luck and post back if you have any other ideas or questions about preloading.