在Flash/Actionscript中添加指向Button的链接

vin*_*nas 0 flash actionscript button

如何在Flash影片剪辑中的按钮上建立链接?

typ*_*ror 5

假设您的按钮的实例名称为"myButton",则在您的按钮位于时间轴中的帧上,您将添加以下(或类似)Actionscript.

AS2

myButton.onPress = function()
{
   getURL("http://stackoverflow.com", "_blank");
}
Run Code Online (Sandbox Code Playgroud)

AS3

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

myButton.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(event:MouseEvent):void
{
   var request:URLRequest = new URLRequest("http://stackoverflow.com");
   request.method = URLRequestMethod.GET;
   var target:String = "_blank";
   navigateToURL(request, target);
}
Run Code Online (Sandbox Code Playgroud)

向后兼容的ASUR的getURL

/**
 * Backwards compatibility for global getURL function.
 *
 * @param url     Url to go to.
 * @param method  'get' or 'post'.
 * @param target  Window target frame [ex. '_blank'].
 */
public static function getURL(url:String, target:String = '_blank', method:String = 'get'):void
{
    method = method.toUpperCase();
    target = target.toLowerCase();

    if (method != URLRequestMethod.POST && method != URLRequestMethod.GET) method = URLRequestMethod.GET;
    if (target != "_self" && target != "_blank" && target != "_parent" && target != "_top") target = "_blank";
    var request:URLRequest = new URLRequest(url);
    request.method = method;
    navigateToURL(request, target);
}
Run Code Online (Sandbox Code Playgroud)

请注意,在AS2和AS3中,您可以在类中编写此代码,并将该类设置为button/movieclip的导出类.这可能有点复杂了.