I am creating a banner in flash using AS3 and want to be able to click on the banner to link to a webpage.
I created a clear button to the size of the banner and have placed it on the top layer, named click.
I put this code in the first frame of the click layer:
buttonOne.addEventListener(MouseEvent.CLICK, launchOne);
function launchOne(event:MouseEvent):void {
var swfOne:URLRequest=new URLRequest("http://www.mypage.com");
navigateToURL(swfOne, "_self");
}
Flash automatically added to the top:
import flash.events.MouseEvent;
import flash.net.URLLoader;
When trying to run the code, I get the error message:
Scene 1, Layer 'click', Frame 1, Line 4 1120: Access of undefined property buttonOne.
All I want to do is be able to link to a website with AS3…can someone provide me the code?
Thanks!
Click on your button and go to the Properties Menu. From there, at the top, make sure where it says “Instance Name,” you type buttonOne.
This will tell Flash to create a public variable named buttonOne that you can manipulate with code.
Your code is fine, Flash just doens’t know what “buttonOne” is referring to.