PDA

View Full Version : navigating web pages with actionscript 3



Rokit
09-27-2009, 05:48 PM
I just watched the video "adding actionscript to buttons" for Flash 8, but I'm running into a problem. I'm using Flash 10 and whenever I right click my button and select "actions" it says "Current selection cannot have actions applied to it." My button is a symbol, it is a button, and I gave it a unique name, but I'm not sure what else I have to do to setup an action.

Also, since getURL is not used in actionscript 3, I was wondering if anyone could explain the new way of doing things? I appreciate the help.

Rokit
09-27-2009, 08:02 PM
I figured out how to do it. I'm sure there are other ways, but this one worked for me.

In the main timeline (scene 1), add a new layer called "actions" (this is just to keep the scene organized) right click on the first frame, choose "actions", and add the following script:


// add event listeners to buttons and tell which function to call for each button
this.homeBtn.addEventListener(MouseEvent.CLICK, goToHome);
this.videosBtn.addEventListener(MouseEvent.CLICK, goToVideos);

// functions
function goToHome(e:MouseEvent):void
{
var homeURL:URLRequest = new URLRequest("http://www.yoursite.com/index.html");
navigateToURL(homeURL);
}

function goToVideos(e:MouseEvent):void
{
var videosURL:URLRequest = new URLRequest("http://www.yoursite.com/videos.html");
navigateToURL(videosURL);
}

This also works for local files if you are just testing your site. For example:


var aURL:URLRequest = new URLRequest("file:///C:/Users/YourUser/Desktop/Blah%20Blah%20Blah/A%20Page.html");

The %20 is included in the place of spaces. The cool thing is that if you copy and paste the local directory in the flash script editor, the %20s are included automatically.

Hopefully, this will at least get you navigating pages.

Regards,
Rokit

Rokit
09-27-2009, 08:56 PM
One more thing. If you want to open the page in the same window you can supply an extra argument to the navigateToURL method. For example:


navigateToURL(videosURL, "_self");

Other arguments are: "_parent", "_blank", or "top".

seph1603
09-27-2009, 11:25 PM
you have to do a new flash file (actionScript 2), to follow the flash 8 training, flash file (actionScript 3), has a diferent programming form.

mirkov sasa
01-13-2010, 01:37 AM
in actionscript 3 you can not code in object, you place all of you code in keyframes in timeline.