Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Preloading the Timeline with Flash CS3

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. We ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 27-09-07, 09:29
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Preloading the Timeline 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:
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');
}
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.

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:
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');
		}
	}
}
Source files:
Attached Files
File Type: zip timeline_preloading.zip (5.81 MB, 145 views)

__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !

Last edited by Flep; 28-08-08 at 07:02..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 14-10-08, 19:36
Junior Member
 
Join Date: Oct 2008
Posts: 1
Rep Power: 0
djmontra is on a distinguished road
Re: Preloading the Timeline with Flash CS3

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Preloader della Timeline con Flash CS3 Flep Articoli e tutorials 8 03-07-08 21:32
problemi Preloading (action script 2.0) gabrius88 Flash CS3 | PHP | mySQL 5 16-06-08 08:40
Preloading Error! freesoul Actionscript 3.0 newbies 2 04-12-07 06:10
Riferimento: Preloader della Timeline con Flash CS3 eturella Actionscript 3.0 base 1 15-11-07 15:18
Preloader della Timeline con Flash CS3 mariano.martucci AIUTO utilità free 5 06-08-07 10:53


All times are GMT. The time now is 14:42.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap