Hey everyone,
I'm using Flash AS3.0 and I am struggling to load an Image from an XML file to a movieclip in my flash project.

I have the XML loaded fine, here is my XML content:

<GALLERY>
<IMAGE TITLE="school" image="image1.jpg">pic 1</IMAGE>
</GALLERY>

It loads with this code:

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("content.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
{
myXML = new XML(e.target.data);
}

If I have a movieclip "image_mc" in the library in flash, any idea what action script would load the image into the mc???

Any help would be great, thanks!

Eric

Are you trying to download the "image1.jpg" then load it to an mc or is it a resource in your project that you just want to trigger to load? Either way, if I understand you correctly, you just want to do... myMC.addChild(Bitmap(myLoader.content)); or myMC.addChild(Bitmap(myBitmapData));

Are you trying to download the "image1.jpg" then load it to an mc or is it a resource in your project that you just want to trigger to load? Either way, if I understand you correctly, you just want to do... myMC.addChild(Bitmap(myLoader.content)); or myMC.addChild(Bitmap(myBitmapData));

I have the image that I want to call into the movie clip in the same directory as my .fla file, and that is where I want to call it from. This way making changes in the future is easier.

Just wondering about your first suggestion... myMC.addChild(Bitmap(myLoader.content)); should I swap the ".content" for the file name or location?

thanks for the help,
eric

Still not positive how you want it to end up. Is the image you're talking about going to change or is it always going to be the same? I'm assuming it's dynamic and you're looking to load it at runtime...

If the image is dynamic and you want to load it at runtime, then you should load it the same way you loaded the XML file with

myLoader.load(new URLRequest("image1.jpg"));

And in your completion function, use the line

myMC.addChild(Bitmap(myLoader.content));

where myMC is the movieclip you want to add to. The .content should stay as is. Also if you're reusing myLoader, make sure to remove the old listener and add a new one pointing to your image complete function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.