PDA

View Full Version : Link Button


Mark Han
11-23-2010, 02:17 PM
Okay, got a tiny bit of experience using AS3 now, so here's a rundown of what I'm now attempting to do - if you spot major flaws in my plan please do point them out:

I want a link button. This will be a Button, with a Normal, Over and Hit states.

The Normal state is fine. On Over, I'm thinking of having a short MovieClip, so that a text box "grows" rather than simply appears suddenly. I think I'm okay with this, but will there be any issues with the Normal and Over being different sizes?

Then, I want the user to be sent to a particular web page/site upon a mouse click on the Button. I'm thinking I can add some AS for the Hit state, but I don't know what the required code is?

I am right in thinking that I want to use the "HIT" state? Or should it be the "DOWN" state?

Thanks,
Mark.

Eralmidia
11-24-2010, 05:00 AM
The frame called HIT is really there to define what area of the screen is clickable. It's the up, over and down which represents the states really. If you require more control, you should do this by adding listeners.

I wouldn't really put code inside the button myself. I would gather the code in the main timeline, not spreading it all over the file. If the code gets to big for the timeline, it's over to an object oriented approach.

Mark Han
11-24-2010, 10:40 AM
Hmm,

Thanks for that. Yes, I see the sense in putting the AS all in one place. Would, you, however, bear with my precociousness when I suggest that it may be better for me to have the link code within the Button.

My reasoning is that I want this movie to be easily editable: I want to remove mc's and replace/add new mc's. I'm concerned that if I add the link AS in the main timeline, that there will be so much code to edit. I already have the Play/Pause, RW and FF codes that will need editing. If I have the link AS within each button, I can easily delete a button and add a new one.

Only my thoughts - I am very new to this and may be totally wrong on this!

Mark.

Eralmidia
11-24-2010, 08:04 PM
What I threw at you here is probably the common approach. But in the end, its just simple advice, and it all comes down to what you're comfortable with. If it's a fairly small project, it really doesn't matter. You'll always have the tool called movie explorer panel, which can list the places in your fla where the code resides, so it's not like the code will go missing if you don't gather it on the main timeline.

So, do what you feel is right, and if it works that fine, if not you'll experience what problems arises and you can go look for a solution to them. It's useful knowledge to do something wrong too (not that I'm saying your approach in this case is wrong).

I myself, would probably create a class for the button. If you need a lot of those buttons. Where exactly are you planning to set the actual link value? Remember that if you double click something on the stage, you'll actually edit the object, not the instance, so if you set an address inn the button, all buttons will have the same address. So you will have to set this address at some point, unless you're planning to create a new button for every address?

Mark Han
11-29-2010, 11:02 AM
What I am thinking of doing is having separate buttons for each URL, with text to tell the visitor where he is going.

I was thinking I could add the link URL on to the Button - I was thinking as AS for the Down state? I could be totally wrong with this approach.

What I am totally unsure about is adding hyperlinks per se. Is there an AS3 script that will act as a link?

Thanks,
Mark.

Eralmidia
11-29-2010, 11:16 PM
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/package.html#navigateToURL%28%29

You call the function navigateToURL which in turn requires a URLRequest object, which basically is just a container for the address in which you want to navigate to.

Mark Han
12-01-2010, 10:24 AM
Thank you Eralmidia,

I'm hoping to find time to attempt this today. I'll take a look at the Adobe site.

Mark.