Flash CS4: Unresponsive error when using "Loader.contentPath"?
I want to display http://www.flash-mx.com/images/image1.jpg image as a thumbnail box in my flash SWF file. TO do so I have taken a Loader control in my flash movie and named it as my_thumb
and then writing the code as:
_parent.my_thumb.contentPath = "http://www.flash-mx.com/images/image1.jpg";
But I am getting following error after adding above line in my flash code.
---------------------------
Flash Player
---------------------------
A script in this movie is causing Flash Player to run slowly.
If it continues to run, your computer may become unres开发者_如何学编程ponsive.
Do you want to abort the script?
---------------------------
Yes No
---------------------------
And If I am removing the above line form my code then it works fine, no issues.
I am not able to figure out why this is occurring. I am a beginner in flash and do not have much idea about these kind of error.
Please check!
Thanks
var url:String = "http://www.helpexamples.com/flash/images/image2.jpg";
var movieClip:MovieClip = createEmptyMovieClip("movieClip", 0);
movieClip.loadMovie(url);
movieClip._x=200;
movieClip._y=200;
function onEnterFrame(){
//trace(movieClip._width);
//trace(movieClip._height);
if (movieClip._width!=0){
setDimension(movieClip,100,100);
delete onEnterFrame;
}
}
function setDimension(mc:MovieClip,w:Number,h:Number){
mc._width=w;
mc._height=h;
}
The mistake that you do is that you are trying to use AS3 code to do something in AS2. (contentPath is specific to AS3)
In order to load a picture in AS2 you are better using MovieClipLoader class instead of loadMovie. MovieClipLoader let's you keep track of the loading progress and as well it can tell you when you can access specific properties like _width and _height.
Here's a script that does the above. Simply paste it in a new AS2 Fla and run it. Hope it helps and good luck in your journey learning Flash! :)
var container:MovieClip = createEmptyMovieClip("container", getNextHighestDepth());
var mcLoader:MovieClipLoader = new MovieClipLoader();
var listener:Object = new Object();
mcLoader.loadClip("http://www.flash-mx.com/images/image1.jpg", container);
listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void
{ trace(target + ".onLoadProgress with " + bytesLoaded + " bytes of " + bytesTotal); }
listener.onLoadInit = function(target:MovieClip):Void
{ trace("The picture has been loaded, now you can access information about it like width and height");
trace(container._width+" "+container._height);
//or
trace(target._width+" "+target._height) }
mcLoader.addListener(listener);
I am not familiar with AS2, but this page says that the contentPath
property must be a
string that indicates an absolute or relative URL of the file to load into the loader. A relative path must be relative to the SWF file that loads the content. The URL must be in the same subdomain as the loading SWF file.
You can use loadMovie to load external images in ActionScript-2. Use the Loader class in AS3.
精彩评论