-
loadclip in as2.0 class
Hi,
I've got a problem using loadclip in a as2.0 imagecontainer class.
It works fine when i place the image container on Stage, but when I attach the clip dynamically with attachmovie, nothing happens. this is what the class looks like. Does anybody have any ideas about this?
when i do a trace in the loadImage function everything seems to be normal, nothing is null or undefined...
Code:
class imagecontainer extends movieclip
{
function imagecontainer()
{
target = createEmptyMovieClip("target")
}
function loadImage( file )
{
var lc = new MovieClipLoader()
lc.addListener(this)
lc.loadclip( file, target )
}
}
in the .fla file i write something like this:
var im = attachMovie("imagecontainer", "image", 10)
im.loadImage( 'file.jpg' )
-
i still havn't figured this out. nobody? pleazze :)
-
The code you posted should have thrown up loads of errors. You should take care with the casing of your code, i.e. MovieClip instead of movieclip etc.
With a class using listeners I usually prefer there to be a way of removing listeners so I can keep things clean and keep memory useage etc down. This would involve declaring the MovieClipLoader object outside of the loadImage function. That said, the reason I do that is because of the size of the projects I work on where every optimisation counts; you probably won't have an issue with that. Also, I think I would prefer to create a specific listener object rather than use the class object itself, but hey, if it floats your boat... :D
Anyway this is a fixed up version of your class that works. The other problems with your class was that the target property was not declared outside the constructor (and so was undefined in the loadImage function) and the createEmptyMovieClip was missing a required parameter (depth).
Code:
class imagecontainer extends MovieClip
{
var target:MovieClip;
function imagecontainer()
{
target = this.createEmptyMovieClip("target", 0);
}
function loadImage(file:String):Void
{
var lc = new MovieClipLoader();
lc.addListener(this);
lc.loadClip(file, target);
}
function onLoadInit(mc:MovieClip):Void
{
trace("Loaded: "+mc);
}
}