View comments | RSS feed

MovieClipLoader


Object
    |
    +-MovieClipLoader

public class MovieClipLoader
extends Object

This class lets you implement listener callbacks that provide status information while SWF, JPEG, GIF, and PNG files are being loaded into movie clips. To use MovieClipLoader features, use MovieClipLoader.loadClip() instead of loadMovie() or MovieClip.loadMovie() to load SWF files.

After you issue the MovieClipLoader.loadClip() command, the following events take place in the order listed:

When MovieClipLoader.onLoadInit has been invoked, you can set properties, use methods, and otherwise interact with the loaded movie.

If the file fails to load completely, the MovieClipLoader.onLoadError listener is invoked.

Availability: ActionScript 1.0; Flash Player 7

Property summary

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Event summary

Event

Description

onLoadComplete = function([target_mc:MovieClip], [httpStatus:Number]) {}

Invoked when a file that was loaded with MovieClipLoader.loadClip() is completely downloaded.

onLoadError = function(target_mc:MovieClip, errorCode:String, [httpStatus:Number]) {}

Invoked when a file loaded with MovieClipLoader.loadClip() has failed to load.

onLoadInit = function([target_mc:MovieClip]) {}

Invoked when the actions on the first frame of the loaded clip have been executed.

onLoadProgress = function([target_mc:MovieClip], loadedBytes:Number, totalBytes:Number) {}

Invoked every time the loading content is written to the hard disk during the loading process (that is, between MovieClipLoader.onLoadStart and MovieClipLoader.onLoadComplete).

onLoadStart = function([target_mc:MovieClip]) {}

Invoked when a call to MovieClipLoader.loadClip() has begun to download a file.

Constructor summary

Signature

Description

MovieClipLoader()

Creates a MovieClipLoader object that you can use to implement a number of listeners to respond to events while a SWF, JPEG, GIF, or PNG file is downloading.

Method summary

Modifiers

Signature

Description

 

addListener(listener:Object) : Boolean

Registers an object to receive notification when a MovieClipLoader event handler is invoked.

 

getProgress(target:Object) : Object

Returns the number of bytes loaded and the total number of bytes of a file that is being loaded by using MovieClipLoader.loadClip(); for compressed movies, returns the number of compressed bytes.

 

loadClip(url:String, target:Object) : Boolean

Loads a SWF, JPEG, progressive JPEG, unanimated GIF, or PNG file into a movie clip in Flash Player while the original movie is playing.

 

removeListener(listener:Object) : Boolean

Removes the listener that was used to receive notification when a MovieClipLoader event handler was invoked.

 

unloadClip(target:Object) : Boolean

Removes a movie clip that was loaded by using MovieClipLoader.loadClip().

Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


Spirale said on Nov 2, 2005 at 7:11 AM :
Loading of images in GIF and PNG formats is ONLY available with the Flash player 8 and above.
__james__ said on Nov 2, 2005 at 12:49 PM :
After almost pulling out all of my hair I finally discovered that if you convert a Flash MX 2004 file to a Flash 8 file, .png's will not load using MovieClipLoader.

Try this:
Create a file in Flash MX 2004...
Put this code in the first frame

var myClip = this.createEmptyMovieClip("myMc", this.getNextHighestDepth());
var myLoader = new MovieClipLoader();
var myListener = new Object();
myListener.onLoadInit = function () {
trace("load init");
};
myLoader.addListener(myListener);
myLoader.loadClip("some.jpg", myClip);

Test it and make sure it works.



Now close the file, and launch Flash 8.
Put in the same code...make sure it still loads the jpg.
Now try to load a png instead.

var myClip = this.createEmptyMovieClip("myMc", this.getNextHighestDepth());
var myLoader = new MovieClipLoader();
var myListener = new Object();
myListener.onLoadInit = function () {
trace("load init");
};
myLoader.addListener(myListener);
myLoader.loadClip("some_other.png", myClip);

It won't load the png!!!

Create a NEW Flash 8 file:
Put in the same code as above to load the png...voila! It works!
No screen name said on Jan 19, 2006 at 9:53 PM :
I can also identify with __james__. I noticed that my file, (previously a 2004 MX file) when SAVED as a Flash 8 file, my png's still wouldn't load. Maddening!
But then I just happened to notice that in my publish settings, the "Version" select box was still set to Flash 7!

IMPORTANT: Saving your file as Flash 8 does NOT change your publish settings accordingly!

Once I changed my player version in my Publish Settings, and re-published, the file worked perfectly.
djtechwriter said on Jan 24, 2006 at 10:57 AM :
Spirale and "no screen name" are correct: You have to have your Publish setting set for "Version: Flash Player 8". Otherwise, only SWF and JPEG formats are supported for earlier versions of the player.
No screen name said on Feb 11, 2006 at 3:49 PM :
beware of the MovieClipLoader's event handlers not firing in certain browsers when what you're trying to load is already in the cache. I'm running across a problem in IE where if an image i'm loading via a MCL is already in the cache, onLoadInit doesn't fire in my swf. but in firefox, the event handlers run perfectly.
William_Donelson said on Mar 17, 2006 at 3:49 AM :
If a movie fails to load, then unloadClip still leaves the object on the level, even though it returns "true".
No screen name said on Mar 18, 2006 at 12:06 PM :
Yes, No screen name, you are exactly right: If the image you are loading is already in cache, it doesn't load to replace the existing MovieClip's content.

Wow, that's a serious (and for my application, disastrous) bug!
No screen name said on Mar 18, 2006 at 12:24 PM :
Until Macromedia release a fix for the Internet Explorer cache load bug, here is a workaround that allows you to use the old MovieClip.loadMovie function and execute code when the clip's new content has loaded:

Before calling myClip.loadMovie, store any properties you will need later as properties in myClip's _parent, since these will be lost when the new content loads:

myClip._parent.resizeX = myClip._width;
myClip._parent.resizeY = myClip._height;

Add this code into myClip's actions directly in the timeline where it sits. (I haven't been able to attach this script dynamically):

onClipEvent(data)
{
if (this.getBytesTotal()>100)
{
if (this.getBytesLoaded() >= this.getBytesTotal()) {
// The new content has loaded. You can call any script you want here. For example, resize to fit original MC dimensions. :
this._width = this._parent.resizeX ;
this._height = this._parent.resizeY;
}
}
}

Or, you could have defined a callback function in myClip._parent:

myClip._parent.callbackFunc = someFunctionName;

and then in the onClipEvent inner if block, call that function: this._parent.callbackFunc;
brittons said on Jun 28, 2006 at 8:29 AM :
Using MovieClipLoader or loadMovie to load progressive jpg will not render in flash player 7. The externally loaded jpg must be saved as non progressive in order to see it in fp 7. (confrimed with 7,0,14,0 - probably affects all versions 7 and earlier).
ssubbu said on Jul 7, 2006 at 2:40 AM :
In the document, it is mentioned that the MovieClipLoader class is available from Flash Player 7, ActionScript 1.0. But, the class failed when I tried to load a .png file. Please let me know whether it was a bug or not. However, it workied fine when I targetted ActionScript 2.0, Flash Player 8.
peterd_mm said on Jul 7, 2006 at 5:04 PM :
ssubbu,

The MovieClipLoader class works in Flash Player 7 and later, as well as ActionScript 1.0 and later. Unfortunately, the ability to dynamically load PNG files wasn't added until Flash Player 8, so in order to load a PNG you must target Flash Player 8+ (using either ActionScript 1.0 or 2.0).

For example, consider the following ActionScript code:
[ActionScript]
this.createEmptyMovieClip("img_mc", 10);
var mcl = new MovieClipLoader();
mcl.onLoadInit = function(target_mc) {
trace("initted!");
}
mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);
[/ActionScript]

This code will load and display an image in Flash Player 7 (ActionScript 1.0 and 2.0) as well as Flash Player 8 (ActionScript 1.0 and 2.0). If you try and load image1.png instead of image1.jpg, it will only display the image when targetting Flash Player 8 (either ActionScript 1.0 or 2.0). In Flash Player 7, the onLoadInit() event hander is still executed, but the image will not be visible on the Stage.

Hope that helps,
Peter
Flash Player documentation
elstinko said on Aug 1, 2006 at 1:26 PM :
Great! now how does one control the position in which this created clip is displayed? Right now it appears in upper left corner at x0y0.
delta9design said on Aug 20, 2006 at 11:19 AM :
I have a problem with the MovieClipLoader. I have a form with TextInput and ComboBox instances. When i add a MovieClipLoader to the library (linkage set to import in first frame) The TextInput background and border disappear. The same happens with the ComboBox instances (therefore disabling user input). Is this a bug?
lenfaseler said on Sep 28, 2006 at 11:46 AM :
This is close, but your thread may provide an answer that we've been looking for - I've got a post on the Macromedia Flash set....

Our application displays images for scrolling links on the desktop...by necessity, it needs to display swf, gif, and jpg file (since they are pulled from websites).

If an SWF file displays, you can continue to display jpgs, but gif's will not display until rebooted. Your discussion sounds close, even referring to a cache bug. We use "loadmovie" language in our code.

Is it possible to get an answer here or comment directly from anyone who has a clue?

Thanks in advance.

s/Len Faseler
biteuljiouce said on Oct 8, 2006 at 1:47 AM :
a quick solution to BROWSER CACHE BUG and onLoadInit that doesn't trigger is :
loadClip("your_file" + "?".Math.random())
the file is always reloaded.
I know, it's a poor fix, but i can help if you're in a hurry.
No screen name said on Nov 14, 2006 at 10:23 AM :
I have noticed that if you close a pop-up browser window with a movie that is downloading more then two (2) clips with the MovieClipLoader Class the browser will lock up and refuse to load any more content from that domain. I have verified this with flash 8 & 9 and IE 6 & 7 (Firefox – does not exhibit this behavior).
No screen name said on Jan 18, 2007 at 1:02 PM :
In the code given by peterd_mm, if you change the declaration of mcl to strictly type it :

var mcl:MovieClipLoader = new MovieClipLoader();

the code no longer works. What's going on?
Holoville said on Jan 21, 2007 at 9:49 AM :
If you issue unloadClip while a clip is loading with movieClipLoader, it still continues to load. How can movieClipLoader be interrupted succesfully?
No screen name said on Feb 3, 2007 at 5:05 AM :
I've found a way to bypass the IE caching issue, using the MovieClipLoader class. The way I did was, on the very first frame of the SWF being loaded, put the following code:

if (this != _level0 && !_global.blnLoaded) stop();

Then, on the Loader SWF you have to define a _global.blnLoaded = false.

And then, on the MovieClipLoader.onLoadComplete event, put the following code:

loadListener.onLoadComplete = function(target_mc:MovieClip):Void
{
_global.blnLoaded = true;
target_mc.play();
}

It seems the issue on IE Flash Player is because the same frame of the loading movie is called back again when the play() on the onLoadProgress is fired.

Well, hope it helps!
Rapatski said on Feb 6, 2007 at 1:53 AM :
Just press F1 and look up ._x, or ._y, for that matter
No screen name said on Feb 8, 2007 at 1:00 PM :
Hi,

I would like to use MovieClipLoader, but ... old function of movieClip class 'loadMovie' has one perfect parameter [method]. So I can call some server script (ASP/PHP etc.) and send some data using GET or POST and this script return me some swf file.
I would ask if in class MovieClipLoader exists same functionality.

thaks
mi4k
NPaquin said on Feb 21, 2007 at 8:44 AM :
I have a big problem to notice and workaround are welcome !!!

I want to add a movieClip into an loaded swf using MovieClip.attachMovie() function, but it simply does not work ! Example:

this.createEmptyMovieClip("img_mc", 10);
var mcl = new MovieClipLoader();
mcl.onLoadInit = function(target_mc) {
trace("initted!");
_level0.img_mc.attachMovie("Symbol1", "myAttachedMC", _level0.img_mc.getNextHighestDepth());
}
mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg", img_mc);


Yes, I have a object in my library named "Symbol1" exported at runtime ...
When I try this folling code, it works:

this.createEmptyMovieClip("img_mc", 10);
_level0.img_mc.attachMovie("Symbol1", "myAttachedMC", _level0.img_mc.getNextHighestDepth());

But why can't I attach a MC into a loaded swf ??
jojospecial said on Mar 2, 2007 at 3:12 AM :
I have encountered a very strange problem.
Using the MovieClipLoader to load swf files, and then unloading the swf with unloadClip, the actionscript of the uloaded swf or maybe only the callback functions remain loaded, with strange results. In simple words, the callback function keeps on running at the background in the predefined interval of time, even after unloading the swf file that containded it.
replaysMIKE said on Mar 5, 2007 at 1:30 AM :
Argh, when I load a clip with MovieClipLoader(), it breaks all of my alpha masks in the loaded swf. What is up with this and how can it be fixed? I have an example of the problem here: http://www.360replays.com/test/alphamask.html

The masks are completely broken. I'm using cacheAsBitmap=true and dynamically setting the mask using setMask("mask"). SWF works fine on its own, but not through MovieClipLoader().

Aarraggh, frustrated...
No screen name said on Apr 23, 2007 at 9:27 PM :
this.createEmptyMovieClip("mCirclesSWFHolder",
this.getNextHighestDepth());
var mlSWFLoader:MovieClipLoader = new MovieClipLoader();
mlSWFLoader.loadClip("http://www.person13.com/asb/circles.swf?nCircles=20",
mCirclesSWFHolder);

with this piece of code it SHOULD send the variable query with it...but it is not.

Is this an error with the class or anybody know how to get it to work?
No screen name said on Apr 24, 2007 at 10:14 AM :
Hi all!

I use a MovieClip to load SWF games. Is there any way to know the "document" size of a loaded SWF? I mean the white working area of flash.

it is mainly because some programmers are used to put some object on the stage outside of the "document", but this spoil my resizing when i resize the loaded SWF to fit my game viewer.
degrate said on May 2, 2007 at 8:55 PM :
I am a novice scripter so excuse me if my question is elementary. I
am using the MovieClip.loadMovie() function to load external swfs into
another swf file. It works fine when I test it and publish it, but it only
works if I open the swf. If I try to open the html file that I publish with it.
The load doesn't work. The coding is so simple it doesn't require I
post it. I didn't know if this is a bug or just something simple I'm not
doing. This happens also with an image viewer I made. The swf
works fime, but trying to view it through html and I get nothing. Any
ideas?
No screen name said on Jun 4, 2007 at 4:00 PM :
My biggest problem with MovieClip loader is a sandox error message that occurs when acting on a clip before it is fully loaded.

In my specific case, it is a keyboard onKeyDown event that is invoked and moves the stage and loads new clips. If the clips are already fully loaded--no error; if the clips are still loading--error. The code works just fine actually--the images load perfectly--but I am plagued with these errors that I cannot get rid of!

*** Security Sandbox Violation ***
SecurityDomain 'http://somedomain.com/somefile.jpeg' tried to access incompatible context 'file:///HadDrive/Path/someswf.swf'
Wakebrad said on Jun 24, 2007 at 8:11 PM :
Does anyone know if the cache bug in IE is fixed in version 9? None of the work-arounds are working for me.
ChrisRauh said on Jul 23, 2007 at 4:18 PM :
Implementing MovieClipLoader.onUnload() breaks MovieClipLoader on IE.

If you avoid it, things should work fine.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002538.html