在AS3中的getURL,怎么样?

时间:2013-03-22 21:22:01

标签: actionscript-3 actionscript flash-cs5

您好我多年没有使用过Flash,需要在新的AS3横幅中使用一些旧的跟踪代码。我注意到在3.0中,你不能在时间轴上将动作脚本放在对象上。

我需要转换这个As2脚本,我通常会在标有' my_button'

的按钮上进行转换
on (release) { 
getURL (_level0.clickTag, "_blank"); 
}

在标有' my_button'?

的按钮的时间轴上使用的等效代码段是什么?

4 个答案:

答案 0 :(得分:5)

这是Google的clickTag建议:

import flash.events.MouseEvent;

import flash.net.URLRequest;

// ......

someButton_or_displayObject_to_receive_mouseClick.addEventListener(MouseEvent.CLICK,
                   function(event: MouseEvent) : void {
                   flash.net.navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG), "_blank");
                   } 
);

答案 1 :(得分:3)

我看到了几个不同的例子,但没有一个与我使用的方法相同;

这是完整版,只需复制并过去并添加您的网址AS3

import flash.events.MouseEvent;
import flash.net.URLRequest;

// add event listener to listen for "btnOpen" click
btnOpen.addEventListener(MouseEvent.CLICK,openFuction);

// add our openFuction
function openFuction(e:MouseEvent){
    var openPage:URLRequest=new URLRequest("https://mysite.co.uk")
    navigateToURL(openPage,"_blank");
        }

答案 2 :(得分:2)

还有另一种方法,它不一定依赖于ExternalInterface类的使用。您也可以尝试这样的事情(假设舞台上的对象的实例名称为“mybtn_mc”:

mybtn_mc.addEventListener(MouseEvent.CLICK, openWebpage);
//
function openWebpage(e:MouseEvent):void {
    var my_url:URLRequest = new URLRequest("http://stackoverflow.com/questions/15580069/geturl-in-as3-how-to/15639569");
    flash.net.navigateToURL(my_url, "_self");
}
// if you want the object to act like buttons do in AS2
// with the handcursor effect when you mouse over them,
// you would include the following lines:
mybtn_mc.buttonMode = true;
mybtn_mc.useHandCursor = true;

答案 3 :(得分:0)

这是用时间轴风格写的,这不是我赞同的。但我觉得你甚至还没准备好收听课程以及它们是如何运作的。

myButton.addEventListener(MouseEvent.CLICK, openWebpage);

function openWebpage(e:MouseEvent):void {
   if (ExternalInterface.available) {
      var callReturn:String = ExternalInterface.call('function(){window.open("http://www.yourURL.com", "_blank", "top=0,left=0,width=800,height=600");}');
   }
}

请注意,您不应该尝试超出当前MC的范围,但如何做其他事情超出了本答案的范围。如果有兴趣,请搜索依赖注入。