I try to display this little example code by using two classes. For some reason, I can’t show up if I use two classes.
In my main.fla, I added document class: main and set to the right set Path.
error msg: “Implicit coercion of a value of type test to an unrelated type flash.display:displayObject”
If I added an “extends Sprite” in public class test, I won’t get any error but it won’t display the rectangle… why?
“file: test.as”
package {
import flash.display.Sprite;
public class test {
public function test():void {
var rect:Sprite = new Sprite();
rect.graphics.beginFill(0x666666);
rect.graphics.drawRect(10,10,100,200);
rect.graphics.endFill();
}
}
}
“file: main.as”
package {
import flash.display.Sprite;
public class main extends Sprite {
var m_rect:test;
public function main():void {
m_rect = new test();
addChild(m_rect);
}
}
}