Skip to main content
February 17, 2010
Answered

I want to learn AS3 by comparison to AS2 starting with a btn getURL

  • February 17, 2010
  • 1 reply
  • 480 views

Hi

I've tried a free online tutorial and my tutor was as usual slightly incoherent!

So here goes with I hope a forum based learning curve with-out the head banging.

What is to equivalent to this getURL btn AS2 btn function please?

on(release){
getURL("mainFrame1.html", "mainFrame");
}

It is just a script I use for a Dreamweaver frameset. I know from the AS2 tutorial the AS3 equivalent will be longer and probably be assigned to the frame the btn is on and not the btn.

I so leave this tender place of instruction in the hope of sober enlightenment.

Sabby76

This topic has been closed for replies.
Correct answer Ned Murphy

Don't get your hopes up about this being a place of instruction.  It's moreso a place to get help solving problems where you can show code that is troubling you.  That said, there are some things that come up often enough to warrant a little copy and paste....

Let's say you create a button symbol.  Since it is a button, it is already a self animating object that will react to mouse interactions, but only visually at this stage.  The first thing you need to do to make it useful code-wise is to assign it a unique instance name.  So you drag a copy of it out to the stage from the library, and while it's still selected, you enter that unique instance name for it in the Properties panel... let's say you name it "btn1"


In AS3, to make a button work with code, you need to add an event listener and event handler function for it.  You might need to add a few (for different events, like rollover, rollout, clicking it, but for now we'll just say you want to be able to click it to get a web page to open.  In the timeline that holds that button, in a separate actions layer that you create, in a frame numbered the same as where that button exists, you would add the event listener:


btn1.addEventListener(MouseEvent.CLICK, btn1Click);

The name of the unique function for processing the clicking of that button is specified at the end of the event listener assignment, so now you just have to write that function out:


function btn1Click(evt:MouseEvent):void {

   var url:String = "http://www.awebsite.com/awebpage.html";

   var req:URLRequest = new URLRequest(url);

   navigateToURL(req);

}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
February 17, 2010

Don't get your hopes up about this being a place of instruction.  It's moreso a place to get help solving problems where you can show code that is troubling you.  That said, there are some things that come up often enough to warrant a little copy and paste....

Let's say you create a button symbol.  Since it is a button, it is already a self animating object that will react to mouse interactions, but only visually at this stage.  The first thing you need to do to make it useful code-wise is to assign it a unique instance name.  So you drag a copy of it out to the stage from the library, and while it's still selected, you enter that unique instance name for it in the Properties panel... let's say you name it "btn1"


In AS3, to make a button work with code, you need to add an event listener and event handler function for it.  You might need to add a few (for different events, like rollover, rollout, clicking it, but for now we'll just say you want to be able to click it to get a web page to open.  In the timeline that holds that button, in a separate actions layer that you create, in a frame numbered the same as where that button exists, you would add the event listener:


btn1.addEventListener(MouseEvent.CLICK, btn1Click);

The name of the unique function for processing the clicking of that button is specified at the end of the event listener assignment, so now you just have to write that function out:


function btn1Click(evt:MouseEvent):void {

   var url:String = "http://www.awebsite.com/awebpage.html";

   var req:URLRequest = new URLRequest(url);

   navigateToURL(req);

}

February 17, 2010

To Ned Murphy

The background information you added to the AS3 script explained the Flash GUI's inter-acting architecture protocol and relevant connecting behaviours.

The whole page will go into my word file as a example.

Thank you

Sabby76

Ned Murphy
Legend
February 17, 2010

You're welcome