Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / General Flash Topics / July 2008



Tip: Looking for answers? Try searching our database.

an unresolved issue that i need your help for

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
elyelyely - 05 Jul 2008 05:18 GMT
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 [B]first[/B] frame so at this point it would only load 2/3 backgrounds
running via swf....BUT if i place the as3 in the [B]third[/B] 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...
Rothrock - 05 Jul 2008 15:47 GMT
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?
elyelyely - 05 Jul 2008 15:53 GMT
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
elyelyely - 06 Jul 2008 16:17 GMT
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
Rothrock - 06 Jul 2008 17:27 GMT
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.

stop();
this.onEnterFrame = function() {
    var bLoaded:Number = this.getBytesLoaded();
    var bTotal:Number = this.getBytesTotal();
    var percent:Number = bLoaded/bTotal*100;
    if (bLoaded>4 && percent>=99) {
        delete this.onEnterFrame;
        // below makes a number between 2 and 4
        this.gotoAndStop(Math.ceil(Math.random()*3)+1);
    }
};
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.