在AS3中,怎样给按钮添加动作

在AS3中,怎样给按钮添加动作,第1张

因为你用的是actionScriot3.0的脚本,as3不像as2一样什么地方都能写代码,as3不能把代码写在按钮上!

as3加按钮的方法是:

先给的按钮起个名字,比如叫btn

btn.addEventListener(MouseEvent.CLICK,btnClick)

function btnClick(e:MouseEvent){

stop()//这里就是点击后的动作

}

MouseEvent.CLICK是点击

MouseEvent.ROLL_OVER是鼠标放上

MouseEvent.ROLL_OUT是鼠标离开

还有一些不常用的,可以看下帮助

首先要知道你的主页是在帧上还是在另一个场景里?

如果是在帧上的话:

Button.addEventListener(MouseEvent.CLICK,fanhui)

fanhui(e:MouseEvent):void{

gotoAndPlay(帧)

}

如果在另一场景,那个场景一定要有stop()

然后在当前场景输入:

Button.addEventListener(MouseEvent.CLICK,fanhui)

fanhui(e:MouseEvent):void{

gotoAndPlay(帧,场景名)

}

btn0到btnz 加上侦听事件。在共有事件里用var key=e.currentTarget .name.substr(3,1) 可以得到键盘按钮值。最后 : 文本框.text=key

btn0.addEventListener(MouseEvent.CLICK,inputphone)

btn1.addEventListener(MouseEvent.CLICK,inputphone)

btn2.addEventListener(MouseEvent.CLICK,inputphone)

btn3.addEventListener(MouseEvent.CLICK,inputphone)

btn4.addEventListener(MouseEvent.CLICK,inputphone)

btn5.addEventListener(MouseEvent.CLICK,inputphone)

btn6.addEventListener(MouseEvent.CLICK,inputphone)

btn7.addEventListener(MouseEvent.CLICK,inputphone)

btn8.addEventListener(MouseEvent.CLICK,inputphone)

btn9.addEventListener(MouseEvent.CLICK,inputphone)

btna.addEventListener(MouseEvent.CLICK,inputphone)

.......

btnz.addEventListener(MouseEvent.CLICK,inputphone)

btndel.addEventListener(MouseEvent.CLICK,del)

//input key

function inputphone(e:MouseEvent)

{

if (txtinput.text.length <11)

{

var key = e.currentTarget.name.substr(3,1)

//trace(key)

txtinput.appendText(key)

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11904924.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存