-
Senior Member
Loading external jpg in actionscript 3
Hi
How can I load a external jpg into this movie clip that I created via Actionscript 3?
var LoaderImagesMC:MovieClip = new MovieClip();
LoaderImagesMC.x = 0;
LoaderImagesMC.y = 0;
addChild(LoaderImagesMC);
Thanks
Alex
-
I'd just been working on loading external images with a tutorial from 'actionscript 3.0 beyond the basics' from Lynda.com
This works for me:
var LoaderImagesMC:MovieClip = new MovieClip();
LoaderImagesMC.x = 0;
LoaderImagesMC.y = 0;
addChild(LoaderImagesMC);
var imageLoader:Loader;
var goat:XML;
var goatList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("data/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
goat = XML(event.target.data);
goatList = goat.children();
for(var i:int = 0; i < goatList.length(); i++)
{
imageLoader = new Loader();
imageLoader.load(new URLRequest(goatList[i].attribute("thumb")));
imageLoader.x = 25;
imageLoader.y = i * 150 + 25;
LoaderImagesMC.addChild(imageLoader);
}
}
-
Senior Member
Thanks Joe Meering,
But that looks like a lot of extra code for what I need, plus why the xml?
-
I'm sure there's a simpler way. This tutorial was for xml in AS3.0.
However I'm learning that XML is actually a very easy code. Embrace it!
A quick search and http://manfred.dschini.org/2007/06/1...ternal-images/ seems to show a different way. Just don't forget to alter LoaderImagesMC.addChild(whatever variable - he uses thumbnail); at the end of the code.
Joe
-
Hey. Try something like this:
PHP Code:
var myImageLoader:Loader = new Loader(); var imageURLRequest:URLRequest = new URLRequest("image.jpg"); var myBitmapData:BitmapData; var myImage:Bitmap;
myImageLoader.load(imageURLRequest); mycoverloader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
function imageLoaded(e:Event):void { myBitmapData = new BitmapData(myImageLoader.width, myImageLoader.height); myBitmapData.draw(myImageLoader); myImage.BitmapData = myBitmapData; addChild(myImage); }
Last edited by KevinDoom; 06-13-2008 at 01:29 PM.
-
sorry, posted twice by accident.
-
Senior Member
Thanks KevinDoom,
For some reason your code is not working for me
-
Must've been some typos in there. I just tried the following and it worked:
PHP Code:
var imageURLRequest:URLRequest = new URLRequest("image.jpg");
var myImageLoader:Loader = new Loader();
myImageLoader.load(imageURLRequest);
myImageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
function imageLoaded(e:Event):void {
var myBitmapData:BitmapData = new BitmapData(myImageLoader.width, myImageLoader.height);
myBitmapData.draw(myImageLoader);
var myBitmap:Bitmap = new Bitmap;
myBitmap.bitmapData = myBitmapData;
addChild(myBitmap);
}
-
Senior Member
Thanks KevinDoom,
Your code now works, but what I really want is not just to load a external image, but to load it via a movieclip sitting on a layer, so I can put a mask on the layer above it.
-
Originally Posted by KevinDoom
Hey. Try something like this:
PHP Code:
var myImageLoader:Loader = new Loader();
var imageURLRequest:URLRequest = new URLRequest("image.jpg");
var myBitmapData:BitmapData;
var myImage:Bitmap;
myImageLoader.load(imageURLRequest);
mycoverloader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
function imageLoaded(e:Event):void {
myBitmapData = new BitmapData(myImageLoader.width, myImageLoader.height);
myBitmapData.draw(myImageLoader);
myImage.BitmapData = myBitmapData;
addChild(myImage);
}
hello
i'm using your code to present images (it's just perfect) but i have textfields on the document that stay under the image, making impossible to read . How can i put the image under the others objects of the document? I'm getting the texts and image from a xml file..
if anyone knows the answer please help.. thank you
regards
-
Just last week I published a wrapper class to automate image loading - you guys might find it easier.
@akira: change addChild(myImage) to addChildAt(myImage, 0);
-
thanks neznein9 it worked out just fine x)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|