views:

471

answers:

3

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

A: 

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.

Amarghosh
@Amarghosh: I don't think I have the issue what you mentioed above, because I tried running my file form the same domain from where I am loading an image file still its not running. :(
Prashant
Basically I want to display thumbnail of the image. In a 100x100 image box, but I dont know what exactly to use in flahs to display an image. from http://www.republicofcode.com/tutorials/flash/portfolio_2_bc/index.phplink I got to know about Loader component but its not working. If you knwo any other way or any tutorial link online which can help me, please provide me. Thanks.
Prashant
+1  A: 

Hi Prashant, 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);
Oliver
Hi @Oliver: I tried the first solution in this link http://actionscriptexamples.com/2008/03/02/dynamically-loading-an-image-in-actionscript-20-and-actionscript-30/ (provided above by @Amarghosh). But I want to ask how to set width, height and position of this movie clip??
Prashant
The position of the movieclip can be set anytime, for the _width and _height a sollution would be to check every frame when the width and height is different than 0 ( that is happening when the picture has finished loading ) and set the dimensions then.Remember to delete the onEnterFrame afterwards.Please see the code posted in my next answerCheers
Oliver
+1  A: 
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;
}
Oliver
BTW ,You are better off with MovieClipLoader, the ability to add events and determine when it has loaded makes it simpler.
Oliver
Prashant
The above code sets it to 100x100 even though the image is a 400 by 267. I'm sure it must be something in your code.Maybe paste it somewhere and I'll take a look
Oliver