我对包装非常新,所以请原谅我的简单问题。如何初始化docTwo类和构造函数?我想出了如何从主类调用静态函数,而不是初始化另一个类。谢谢
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!");
}
}
}
答案 0 :(得分:2)
尝试像这样更改myDocClass
:
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();
...
...
请注意,它们都放在同一个包中。