Papa De Beau
Papa De Beau

Reputation: 3828

as3 initialize class constructor from another class

I am very FRESHLY new to packages so forgive my simple question. How do I initialize the docTwo class and constructor function? I figured out how to call a static function from the main class but not to init another class. Thanks

myDocClass.as

package  {

import flash.display.MovieClip;
import docTwo;



public class myDocClass extends MovieClip 
{

    var Hello:String = "Hi there";

    public function myDocClass () 
        {
        trace("And all the people said...  " + Hello);
        docTwo.docTwo(); /// Does NOT WORK. How do I call this or init class? 
        thisWorks();
                    // Below call Works
        docTwo.docTwoFunction();
        }

        public function thisWorks()
        {
            trace("Cool Beans! This one worked");
        }

}/// end of Class


}

docTwo.as

package  {
import flash.display.MovieClip;

public class docTwo{

    public function docTwo() 
    {
        trace("Trying to get this to work!");
        docTwoFunction(); // How do I call this from here?
    }

    static public function docTwoFunction()
    {
        trace("I am inside docTwo. Woo hoo!");
    }

}

 }

Upvotes: 0

Views: 697

Answers (1)

Ivan Chernykh
Ivan Chernykh

Reputation: 42166

Try to change your myDocClass like this:

public class myDocClass extends MovieClip 
{

    var Hello:String = "Hi there";
    var myDocTwo:docTwo ;

     public function myDocClass () 
        {
           trace("And all the people said...  " + Hello);
           myDocTwo = new docTwo();

    ...
    ...

Note , they're both placed in the same package.

Upvotes: 2

Related Questions