The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • Flash Professional
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 Flash Professional

  • cmoore Author 
    • 576 
    • 0 
    • 9 
    Preloader in AS3?
    geo_speed

    Last reply Aug 21 2007, 06:59 AM

    by geo_speed

    Posted: Aug 21 2007, 12:27 AM

    by cmoore

     

Hello,

I’m not exactly a Flash Professional, but I’m hoping most of you are. I’ve chosen to do a site in AS3 because I like Tween Class. I’ve run into a serious snag though. Preloaders and loadMovie. I’ve searched and searched google and I’ve gotten nothing but extremely vague results.

I have a main movie that I would like to preload. This movie will load one additional movie on top of it (nothing complex). But in AS3, it seems to be a chore.

Do any of you knowledgeable folks at ultrashock have a step by step tutorial or even willing to post the steps/code here?

I appreciate any information you have to offer. Remember, try to respond to this thread in the most basic of terms. I am not a coder, but I’m trying.

Thanks,

Cmoore

  9 REPLIES
 
Nutrox
1  
Nutrox

Hi cmoore, welcome to Ultrashock. ultrashock

The Loader class is what you need to be looking at really. It is the main class you will use to load external SWF and image files.

It is difficult to tell how much of this you have already picked up but here is a quick example of how to load an external SWF file and listen for progress/complete events.

[as]// A URLRequest object pointing to the external movie.
var mainURL:URLRequest = new URLRequest( “movie.swf” );

// A Loader object (use to load SWF, PNG, GIF, JPG).
var mainMovie:Loader = new Loader();

// Add listeners to the Loader.contentLoaderInfo object.
mainMovie.contentLoaderInfo.addEventListener( ProgressEvent.PROGRESS, progressListener );
mainMovie.contentLoaderInfo.addEventListener( Event.COMPLETE, completeListener );

// Load the external movie using the URLRequest.
mainMovie.load( mainURL );

// Invoked while the exteral movie is loading.
function progressListener( event:ProgressEvent ):void
{
trace( “progress = ” + event.bytesLoaded );

// This is where you would update the progress bar.
}

// Invoked when the external movie has completed loading.
function completeListener( event:Event ):void
{
trace( “complete” );

addChild( mainMovie );

// It would be a good idea to remove the
// mainMovie.contentLoaderInfo listeners here as well.
}[/as]
If you need any more help feel free to ask.

smilie

  • 21 August 2007 01:35 AM
  •  
cmoore Author 
2  
cmoore

Thank you so much for your help. I used the code and it works. The only thing that really confused me is where you said…

// This is where you would update the progress bar.

The way I used to do it was with a dynamic text field. Is this what you mean? Do you mean using a progress bar component? If you meant the text field, what would I call it?

Thank you again. I really appreciate it.

Cmoore

  • 21 August 2007 02:26 AM
  •  
Nutrox
3  
Nutrox

Originally posted by cmoore
...
Do you mean using a progress bar component? If you meant the text field, what would I call it?
...

It depends on what you want to do really. I added that comment into the progressListener() function because that is where you can grab the number of bytes loaded and do the percentage calculations etc, so it would be the easiest place to update your progress bar or text field.

[as]function progressListener( event:ProgressEvent ):void
{
trace( “progress = ” + event.bytesLoaded );

var percent:int = 0;

if( event.bytesTotal > 0 && event.bytesLoaded > 0 )
{
  percent = (100 / event.bytesTotal) * event.bytesLoaded;
}

myTextField.text = percent + “%”;
}[/as]

  • 21 August 2007 02:36 AM
  •  
cmoore Author 
4  
cmoore

Worked great. Thanks for your time. Just curious, but are load levels now obsolete? If not, how are they determined? Is it by the order they are loaded? I’m just curious, because I might be loading a second swf into this mainmovie.

Take care and thanks again Nutrox.

Cmoore

  • 21 August 2007 03:09 AM
  •  
geo_speed
5  
geo_speed

Cool One Nutrox. And, How can i control the loaded swf?
I mean stop the movie or play the movie and those things.

  • 21 August 2007 04:25 AM
  •  
Nutrox
6  
Nutrox

@cmoore

Levels no longer exist in AS3, instead everything is displayed and arranged in display lists. You should take a look at the DisplayObjectContainer class (or the Sprite or MovieClip class) because it contains the functions you will need such as addChild() removeChild() getChildIndex() swapChildren() and so on.


@geo_speed

You need to access the loaded SWF file via the Loader.content property, so once the external SWF file has loaded you could then do something like this:

[as]MovieClip(myLoader.content).gotoAndStop( 10 );[/as]
Where myLoader is your Loader object.

  • 21 August 2007 04:47 AM
  •  
geo_speed
7  
geo_speed

Thanks Nutrox, But it’s not working.

[AS] function completeListener( event:Event ):void
{
      trace( “complete” );
    // trace(mainMovie);
      addChild(mainMovie);
  MovieClip(mainMovie.content).gotoAndStop( 100 );
    // me add the line here
      // It would be a good idea to remove the
      // mainMovie.contentLoaderInfo listeners here as well.
}[/AS]

I used your code only.

  • 21 August 2007 05:46 AM
  •  
Nutrox
8  
Nutrox

Does the SWF file you are loading have 100 frames?

  • 21 August 2007 06:08 AM
  •  
geo_speed
9  
geo_speed

Yeah… sorry its working now.
Before that I tried with one video swf. I think there is the problem.

Very thanks Mr.Nutrox smilie

  • 21 August 2007 06:59 AM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 775  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,724  Assets
  • Profiles 282,659  Members
  • Topics 93,762  Topics
  • Blog 4  Blog
  • Facebook 1,680  Facebook
  • Twitter 1,165  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 04, 2012 - 19:42:00