AS3 Clicktag Error #1010

2019-08-04 00:23发布

I got this clicktag but it does not work:

MyClickTagButton.addEventListener(
  MouseEvent.CLICK,
  function():void {
    if (root.loaderInfo.parameters.clickTAG.substr(0,5) == "http:") {
      navigateToURL(
        new URLRequest(root.loaderInfo.parameters.clickTAG), "_blank"
      );
    }
  }
);

When I click it I get this error:

TypeError: Error #1010: A term is undefined and has no properties.
           at Function/< anonymous >()

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-04 00:37

Using anonymous functions as event handlers is a bad practice…

Secondly, do your button has an instance name MyClickTagButton? If not you either has to change its instance name either alter the code to match existing instance name.

MyClickTagButton.addEventListener(MouseEvent.CLICK, onButtonClick);
//this has to match the instance name of the button

function onButtonClick(e:MouseEvent):void 
{
    if (root.loaderInfo.parameters.clickTAG.substr(0,5) == "http:") 
    {
         navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTAG), "_blank");
    }
}

Ah, and the last thing: when you test it in the standalone player the clickTAG parameter is not set, so probably nothing will happen when you click the button.

查看更多
登录 后发表回答