我正在学习Flash / Actionscript 3,我正在尝试使用已放置在场景中的对象创建一个新对象,这是它的代码:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Scene1 extends MovieClip
{
{
{
{
var theRoot:MovieClip = MovieClip(root);
var mouse:mouse1 = new mouse1();
//Scene1(void);
//onClipEvent(30);
function Scene1():void
{ this.addEventListener(MouseEvent.MOUSE_MOVE, Joe);
}
public function Joe(event:MouseEvent):void
{
mouse.x = mouseX;
mouse.y = mouseY;
mouse.x = 160;
mouse.y = 160;
trace(mouse.x + " " + mouse.y + " " + mouse.z);
}
}
}
}}};
它确实跟踪了它应该是的位置(160,160),即使我改变了Z,也不会渲染bu对象..但是,在它们的视图中没有任何对象会阻挡它。
这是mouse1:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class mouse1 extends MovieClip
{
{
{
var theRoot:MovieClip = MovieClip(root);
mouse1(void);
//onClipEvent(30);
function mouse1():void
{
//this.z = -20;
trace("WROKZZZ");
}
public function Joe(event:MouseEvent):void
{
//this.x = mouseX;
//this.y = mouseY;
}
}
}
}};
答案 0 :(得分:1)
除了使用new
创建对象之外,还需要在呈现之前将其添加到显示列表(请参阅此处:http://www.adobe.com/devnet/flash/quickstart/display_list_programming_as3.html),因此请使用stage.addChild(mouse)
执行此操作