A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How can I use a class' function after passing it as a parameter?

  1. #1
    Junior Member
    Join Date
    Mar 2016
    Posts
    1

    How can I use a class' function after passing it as a parameter?

    Hello, I'm having trouble putting this into words so I left a brief example below of three classes.

    When I create an instance of the Holder class I pass an instance of TestClass (which I intend to use from both the Main & Holder classes). I would like to be able to store this reference in my Holder class and be able to call functions from TestClass. I can run the 'testFunction' from the pass variable 'newTest', but when I try running 'testFunction' from the 'test' variable it results in this error: '1061: Call to a possibly undefined method test through a reference with static type flash.display:Sprite.'

    I'm pretty sure I'm running into a design error here. Any help appreciated. Thanks in advance!

    Code:
    public class TestClass extends Sprite {
    
         public function TestClass () : void {
         }
    
         public function testFunction () {
              trace ("works");
         }
    }
    Code:
    public class Holder extends Sprite {
    
         var test:TestClass;
    
         public function Holder (newTest:TestClass) : void {
              test = newTest;
    
              test.testFunction ();
         }
    }
    Code:
    public class Main extends Sprite {
         
         var myTestClass = new TestClass ();
         var myObject = new Holder (myTestClass);
    }

  2. #2
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Try using
    PHP Code:
    import flash.display.Sprite 
    on all

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