A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: loadclip in as2.0 class

Threaded View

  1. #3
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    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...

    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);
    	}
    }
    Last edited by Lexicon; 02-16-2006 at 11:27 AM.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center