flash as3.0键盘控制移动问题,如下列代码
我想用键盘控制我添加的元件,但键盘操作没效果,大侠帮我看看哈先画个圆package{importflash.display.Shape;importflash.displ...
我想用键盘控制我添加的元件,但键盘操作没效果,大侠帮我看看哈
先画个圆
package
{
import flash.display.Shape;
import flash.display.Sprite;
/**
* @author Administrator
*/
public class Circle extends Sprite
{
public function Circle()
{
var circle1:Shape = new Shape();
circle1.graphics.beginFill(0x006633);
circle1.graphics.lineStyle(2, 0x000000);
circle1.graphics.drawEllipse(100, 100, 100, 100);
circle1.graphics.endFill();
addChild(circle1);
}
}
}
对图形操作
package
{
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
/**
* @author Administrator
*/
public class Test01 extends Sprite
{
public var child1:Circle = new Circle();
public function Test01()
{
addChild(child1);
child1.addEventListener(KeyboardEvent.KEY_DOWN, listener1);
child1.addEventListener(MouseEvent.CLICK, listener2);
}
public function listener1(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case Keyboard.LEFT:
this.child1.x -= 10;
break;
case Keyboard.RIGHT:
this.child1.x += 10;
break;
case Keyboard.UP:
this.child1.y -= 10;
break;
case Keyboard.DOWN:
this.child1.y += 10;
break;
}
}
public function listener2(e:MouseEvent):void
{
child1.x -= 10;
}
}
}
另外,我想移动一个MC界面上的MC元件,该用什么命令 展开
先画个圆
package
{
import flash.display.Shape;
import flash.display.Sprite;
/**
* @author Administrator
*/
public class Circle extends Sprite
{
public function Circle()
{
var circle1:Shape = new Shape();
circle1.graphics.beginFill(0x006633);
circle1.graphics.lineStyle(2, 0x000000);
circle1.graphics.drawEllipse(100, 100, 100, 100);
circle1.graphics.endFill();
addChild(circle1);
}
}
}
对图形操作
package
{
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.ui.Keyboard;
/**
* @author Administrator
*/
public class Test01 extends Sprite
{
public var child1:Circle = new Circle();
public function Test01()
{
addChild(child1);
child1.addEventListener(KeyboardEvent.KEY_DOWN, listener1);
child1.addEventListener(MouseEvent.CLICK, listener2);
}
public function listener1(e:KeyboardEvent):void
{
switch(e.keyCode)
{
case Keyboard.LEFT:
this.child1.x -= 10;
break;
case Keyboard.RIGHT:
this.child1.x += 10;
break;
case Keyboard.UP:
this.child1.y -= 10;
break;
case Keyboard.DOWN:
this.child1.y += 10;
break;
}
}
public function listener2(e:MouseEvent):void
{
child1.x -= 10;
}
}
}
另外,我想移动一个MC界面上的MC元件,该用什么命令 展开
展开全部
child1.addEventListener(KeyboardEvent.KEY_DOWN, listener1);
键盘事件只监听当前焦点对象,用鼠标点一下或者加一句stage.focus = child1;
最好的方法还是改为直接监听舞台的键盘事件
键盘事件只监听当前焦点对象,用鼠标点一下或者加一句stage.focus = child1;
最好的方法还是改为直接监听舞台的键盘事件
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
this.addChild(child1);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询