As3 AddChild() in a Class
Im in as3 and Im trying to add a MovieClip inside of a Class I don't get any errors but my image does not show up.
This is my Class Code, my MovieClip is called woopa开发者_如何学JAVA1
package
{
import flash.display.MovieClip;
import woopa1;
public class koopa extends woopa1
{
public function koopa()
{
trace(woopa1);
var woopa:woopa1 = new woopa1();
addChild(woopa);
woopa.x=100;
woopa.y=100;
woopa.height = 60;
woopa.width = 38;
}
}
}
It traces [Class woopa1] this is my Code in the frame calling the class
function onenterEnemy(event:Event):void
{
var enemy:koopa = new koopa();
}
Why doesn't my image show up?
Have you added your enemy
instance to the display list?
var enemy:koopa = new koopa();
addChild(enemy);
Also since you create an instance of your woopa1
class and add it to koopa
, your koopa
class should probably extend MovieClip
or Sprite
instead of your woopa1
class.
On a separate note, you may also want to name your classes with names that start with an uppercase character. So koopa
should be Koopa
and woopa1
should be Woopa1
.
精彩评论