A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS3 importing from library

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Location
    UK
    Posts
    10

    Post AS3 importing from library

    Hi guys, does anyone know if it's possible to use variables to call objects from your library onto stage like this:

    I have an object in my library called Level01 as is it's linkage

    Actionscript Code:
    var MyMap:String = "Level01";

    addEventListener(Event.ENTER_FRAME,LoadMap);
    function LoadMap(event:Event) {
        var myLVL:MovieClip = new MyMap();// how do you use the variable here?
        this.addChild(myLVL);
        myLVL.x = 0;
        myLVL.y = 0;
        removeEventListener(Event.ENTER_FRAME,LoadMap);
    }

    if i call it directly using:
    Actionscript Code:
    var myLVL:MovieClip = new Level01();
    it works fine but i want to use variables to call the correct object.

    Any Ideas?

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Instead of movieclip you would us Class.

    var myLVL:Class = new MyMap();

    Maybe DisplayObject would also work. I usually use getDefinitionByClass

    var myLCLisplayObject = new MyMap();

    Since all MCs are subs of DisplayObject.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Location
    UK
    Posts
    10
    Hmm still doesn't seem to work. Here's an example of how i've set it up but it's not bringing it out of the library.
    Attached Files Attached Files

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    My computer is going through issues and I currently don't have CS3 install or any version for that fact. Are you still getting errors?
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var myMap:String = "level01";
    addEventListener(Event.ENTER_FRAME,LoadMap);
    
    function LoadMap(event:Event) {
    	var ClassReference:Class = getDefinitionByName(myMap) as Class;
    	var myLVL:DisplayObject = new ClassReference();
    	this.addChild(myLVL);
    	myLVL.x = 200;
    	myLVL.y = 200;
    	removeEventListener(Event.ENTER_FRAME,LoadMap);
    }

Tags for this Thread

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