Flash Pro Hyperlink button error

夙愿已清 提交于 2019-12-12 04:52:57

问题


I have created a button using flash Pro cc I've been doing research but was unable to find why a TypeError stating

TypeError: Error #1009: Cannot access a property or method of a null object reference.at PD3Subscribenow_fla::MainTimeline/frame1()

I have placed my code on a action layer on frame 1:

import flash.events.MouseEvent;
sub_btn.addEventListener(MouseEvent.CLICK, myButtonFunction);
function myButtonFunction(event: MouseEvent) {
var request:URLRequest = new URLRequest("http//:www.google.com");
navigateToURL(request, "_blank");
}

and gave the instance name of my button "sub_btn".

Can you tell me where I have gone wrong.


回答1:


You issue is that on the frame where the code executes, sub_btn does not yet exist (as you state in your comments that it is on a later frame).

You either need to:

  1. Move the button to the first frame,

or

  1. Move the code that references it to the frame with the button.



回答2:


The problem maybe that Flash does not recognize that your button exists yet. In Flash Builder I would use

 creationComplete="init()"

and then

 private function init():void{
    sub_btn.addEventListener(MouseEvent.CLICK, myButtonFunction)
 }


来源:https://stackoverflow.com/questions/26995720/flash-pro-hyperlink-button-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!