A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] Instance Reference from within a custom class

  1. #1
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685

    [RESOLVED] Instance Reference from within a custom class

    I created a custom class, ThisTest:
    Code:
    class ThisTest{
    	function ThisTest(){
    		trace("This: " + this); 
    	}
    }
    and put the following code on the frame of a new fla.

    Code:
    import ThisTest;
    anInstance = new ThisTest();
    the output window shows:
    Code:
    This: [object Object]
    instead of what I expected:
    Code:
    This: anInstance
    Duh, generic objects return Object to normal this calls...

  2. #2
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    anInstance is just a reference(pointer) to the myTest object you have created in memory.

    The object instance itself does not have a reference back to the reference (pointer) aInstance

    as an anology consider a dog called Toby. Toby is just a reference (name) by which you can tell the dog to do things. The dog itself is not Toby, (its just an object, if u can call it that).

    Hope that makes a bit of sense
    Last edited by silentweed; 06-09-2007 at 04:08 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  3. #3
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    so is there a way within a class to reference that specific instance of the class? Or to tell some third party that that instance exists? or, does it all have to happen externally to the class definition, where the instance was created?

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    Are you just creating one instance of the class? If so you can create a static property of the class that references the object.

    Code:
    class ThisTest{
    
            public static var instance:ThisTest;
    
    	function ThisTest(){
    		ThisTest.instance = this;
    	}
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    my hope was to be able to create multiple instances, so I would be able to re-use the code.

    However, I now believe that I was chasing down the wrong problem. And creating a reference to an object is not my issue.

    SW thanks for your help.

  6. #6
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    your welcome
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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