For some reason when i use this, It loops over and over, How can i get it to stop t the end of my imported swf movi? in the imported SWF movie it does have a stop action at the end of the time line
This is a discussion on Preloading the Timeline with Flash CS3 within the Tutorials forums, part of the Flash English category; zzzzzzzzzzzzup ! Here we are with a new article (the third of a series) dealing with preloaders with Flash CS3. ...
zzzzzzzzzzzzup !
Here we are with a new article (the third of a series) dealing with preloaders with Flash CS3.
We saw in another article Preloader with Flash CS3 how to create a preloader using the Document Class combined with a second class. A discreet level of knowledge of Actionscipt 3.0 was needed to understand it.
Next, we saw in the article Preloader for beginners how to create a preloader using only timeline coding which as the title says is for beginners.
Both preloaders have a common point very easy to find out: they both preload the main SWF in an empty SWF. This due to the fact that the MovieClip class of Actionscript 3.0 does not have any more the methods getBytesLoaded and getBytesTotal available but instead does use now the URLLoader class created to upload external files.
Do you remember that with Flash 8 and Actionscript 2.0 we could create a preloader in the first timeline's key frame which was monitoring the bytes loaded of the SWF itself while loading (using the two above methods)'
Surely, lots of you will have to try doing the same thing with Flash CS3 with no result.
Is it not possible doing so'!'
Of course it is! FlepStudio created it for you.
In this article we will see how to create a preloader inside the main SWF itself without the need to do it inside a second SWF.
We will see it in two ways:
-*preloading from the timeline
-*preloading from the Document Class
Let's start swinging'
Let's start with the codes from the timeline.
I create a FLA and save it 'test.fla'.
Into it, I create a second keyframe on the timeline.
I add a stop() to both of the frames.
In the second keyframe, I add a dynamic text field named 'info_txt'.
Back to the first keyframe, after the stop() added first, I insert the following codes:
Observing the code, we can notice that using the ENTER_FRAME I retrieve the property loaderInfo from the timeline asking it to display the values of loaded bytes and total bytes.Code:this.addEventListener(Event.ENTER_FRAME,checkProgress); function checkProgress(_progress:Event):void { var bytes_loaded:Number=_progress.target.loaderInfo.bytesLoaded; var bytes_total:Number=_progress.target.loaderInfo.bytesTotal; var percent:Number=Math.round(bytes_loaded/bytes_total*100); info_txt.text=percent.toString()+' %'; if(percent>=100) { this.removeEventListener(Event.ENTER_FRAME,checkProgress); this.gotoAndPlay(2); lets_go(); } } function lets_go():void { trace('ready to start'); }
I compare those two values and when the result is equal to 100, I stop the ENTER_FRAME, move the playhead of one frame using gotoAndPlay(2) and call a function which will start the full application (in this case a simple trace).
Some of you will wonder why using gotoAndPlay instead of nextFrame'
Or, why not remove the stop on the second keyframe and use instead gotoAndStop(2)'
I would like to be able to give you a logical answer to it but I am sorry to say that at the moment I do not have it yet. I tried both ways and with no result.
Instead, with the gotoAndPlay and the stop on the second keyframe, it works a charm!
We can now take a look at how to do the exact same thing from the Document Class.
I use the same 'test.fla' but this time, associated to a Document Class named 'Test.as', implemented in nearly the same way as the first example:
Source files:Code:package { import flash.display.MovieClip; import flash.text.TextField; import flash.events.Event; public class Test extends MovieClip { public function Test() { stage.frameRate=31; this.addEventListener(Event.ENTER_FRAME,checkProgress); } private function checkProgress(_progress:Event):void { var bytes_loaded:Number=_progress.target.loaderInfo.bytesLoaded; var bytes_total:Number=_progress.target.loaderInfo.bytesTotal; var percent:Number=Math.round(bytes_loaded/bytes_total*100); info_txt.text=percent.toString()+' %'; if(percent>=100) { this.removeEventListener(Event.ENTER_FRAME,checkProgress); this.gotoAndPlay(2); lets_go(); } } private function lets_go():void { trace('ready to start'); } } }
Last edited by Flep; 28-08-08 at 06:02.
For some reason when i use this, It loops over and over, How can i get it to stop t the end of my imported swf movi? in the imported SWF movie it does have a stop action at the end of the time line
Bookmarks