[AS3]as3.0中按钮加链接的写法代码示例
对所有按钮按顺序命名 比如btn1 btn2 btn3 btn4 btn5,[AS3]as3.0中按钮加链接的写法代码示例
对所有按钮按顺序命名 比如btn1 btn2 btn3 btn4 btn5
然后
- import flash.events.MouseEvent;var urlArr:Array = ["1.htm","2.htm","3.htm","4.htm","5.htm"]for
(var i:uint=1; i<6; i++){ this["btn" + i].addEventListener(MouseEvent.CLICK,fun1);}
function fun1(_evt:MouseEvent):void{ var u:String =
urlArr[uint(_evt.target.name.substring(3))-1] trace(u)}- import fl.controls.Button;
- import flash.net.URLRequest;
- import flash.net.navigateToURL;
- var btn1:Button= new Button();
- addChild(btn1);
- btn1.addEventListener(MouseEvent.CLICK, this.onClickBtn4);
- function onClickBtn1(e:MouseEvent) {
- //用String方式赋值
- var m_urlList:String=new String("http://www.89525.com");
- var m_request:URLRequest = new URLRequest(m_urlList);
- navigateToURL(m_request,"_blank");
- }
- //用textField文本方式赋值
- function onClickBtn2(e:MouseEvent) {
- var m_urlList:TextField=new TextField();
- m_urlList.text="http://www.towncool.com";
- var m_request:URLRequest = new URLRequest(m_urlList.text);
- navigateToURL(m_request,"_blank");
- }
- function onClickBtn3(e:MouseEvent) {
- //用数组方式赋值,适用于调用按钮执行多个链接
- var m_urlList:Array=["http://www.towncool.com","http://www.89525.net","http://www.baidu.com"];
- var m_request:URLRequest = new URLRequest(m_urlList[2]);
- navigateToURL(m_request,"_blank");
- }
- function onClickBtn4(e:MouseEvent) {
- //直接赋值
- var m_request:URLRequest = new URLRequest("http://www.89525.com");
- navigateToURL(m_request,"_blank");
- }
热门文章推荐
- [HLS]做自己的m3u8点播系统使用HTTP Live Streaming(HLS技术)
- [FMS]FMS流媒体服务器配置与使用相关的介绍
- [AS3]什么是M3U8,与HTML5的区别是什么
- AS2.0 让flash自适应全屏,并且不自动缩放
- [AS3]as3.0的sound类常用技巧整理
- [AS3]as3与ByteArray详解、ByteArray介绍、ByteArray用法
- 关于RTMP,RTMPT,RTMPS,RTMPE,RTMPTE协议的介绍
- [JS]分享浏览器弹出窗口不被拦截JS示例
请稍候...