PDA

View Full Version : Image loader to movieclip from extern .as



BACH
July 24th, 2008, 04:19 AM
Hi all!

I'm new here at Kirupa and also pretty noob when it comes to AS3.

I'm working on a slideshowproject (like all newbees do!) and I'm stuck trying to load an image into a movieclip.

I have my loader in a class called "Image.as" and by doing some traces I can see it works fine. But when i try to send the image to the movieclip (which I have named "_mc") I have on the stage I just get the "Acces of undifined property _mc". What am I missing? After the file has loaded from the Internet the Image.as calls the function imageLoaded:


function imageLoaded(e:Event):void {
//Load billedet
_mc.addChild(pictLdr);
trace("If you see this, the file has loaded correctly.");
}

In my .fla I have done this to add the empty movieclip to the stage:

var _mc:MovieClip = new MovieClip;
//Add _mc to stage
addChild(_mc);
_mc.width = 550;
_mc.height = 400;

var imageloader:Image = new Image;

I think I'm too old to learn anything new! ;( Been stuck for days!

If you need to see all of the code I can copy/paste it. It's not that large.

Enebreus
July 24th, 2008, 09:52 AM
Hey, I'm a little confused about the code...
is your imageloaded function inside of Image.as?

If it is I think you have a scoping issue. Your image.as class instance won't be able to see the _mc movieclip above it.

If this is the case:
I think you should have your imageloaded function dispatch an event telling your main class that it's finished loading an image. Then your main class can reach into the Image.as instance and grab the bitmap.

Sorry, if I misunderstood something.

BACH
July 24th, 2008, 11:09 AM
I think you understood everything I tried to say! I'll try what you said. :disco:

Enebreus
July 24th, 2008, 01:38 PM
Oh, just thought of something.
On my blog I did a sorta similar project except I'm loading the external image from Flickr. But you can totally see the whole dispatching/Event listener model in action if you'd like.

http://blog.organa.ca/?p=19
The source is available there.