Deactivating a Hyperlink Navigational Button

Hi:

As shown via http://www.kirupa.com/developer/mx/hyperlink.htm – I can create a Hyperlink Navigational Button

However, how does one deactivate a hyperlink navigational button that is self-linked or self-referenced?

In other words, most web sites have multiple pages with a standard set of navigational buttons appearing on each page. Typically, when the user clicks a button, he/she is sent to that page. But, what if the user clicks a button that is linked to the page currently shown? If the button is active, then the page reloads – which is a waste of time and something I don’t want. However, if the button is deactivated, then nothing would happen – which is what I want.

So, how does one deactivate the button who’s hyperlink is the same page?

To do this, the button must somehow know the current page. I know I can get the current page from a call to the CGI environmental variable SCRIPT_NAME, but I don’t know how to do this from flash.

I have searched for over a week now through all the reference material I can find with no idea of how to do what I want. Furthermore, I have posted this question my times in several different forums without a single reply. I would think would be a common problem and, as such, how does everyone solve it?

Any ideas or solutions?

Many thanks for any replies.

tedd

Hi tedd, welcome.
Depends how your site is set up.
If you check out www.flasheyez.com,
i have the nav menu in a top frame, and the content in another below.
whenever a button is clicked, i just disable that button, untill another button is clicked;
then all buttons get re-enabled, and the newly clicked disabled.
i use movieclips for the buttons.

i will not be able to answer any further questions as going on holliday for a week, if you still have questions after nov 20th, bump this thread,
but i’m sure the gang here will help ya out…
:slight_smile:

kirupa:

Ahhh, some of the brightest things are the simplest. I was looking for something a bit more complicated.

So, I take it that you have several global flags so when one button is clicked it is marked as disabled (the rest then enabled) and thus is not available for clicking again. Something like (not tested):

if homeButton == _false
{
on (release)
{
getURL( "www.youdomain.com/home.html)
homeButton = _true
contactButton = _false
mapButton = _false
ssiteButton = _false
}
}

Is that it?

tedd

they don’t need to be global flags per se, you could always just create a boolean variable on your movie clip called “enabled” and when you click a movie, set it to false, then when you click another movie, just set all of the other movie clips’ enabled properties to true… You could get fancier than that, but it would definitely do the trick.

Thanks – can you show me?

tedd

Well, this isn’t how I would go about doing this, ultimately, I would probably create a button component that would take care of this, or who knows… maybe something more complex… But I’m a super geek, so it’s not worth talking about that… But to do what I think you want, you could just do something like this:

Make a movie with 4 instances of a button symbol you’ve created. Name the instances btn1, btn2, btn3, and btn4…

Put this bit of code on each button:

[AS]
on(release) {
if (this.enabled) {
btn1.enabled = true;
btn2.enabled = true;
btn3.enabled = true;
btn4.enabled = false;
}
}
on(rollOver) {
if (!this.enabled) this.useHandCursor = false;
}
[/AS]

Change each button to enable the OTHER buttons, and disable itself.

And I think you’ll get the idea… You could put more code to do your get URL or LoadMovie or whatever you use for navigating the site inside of the if(this.enabled) function.

I think that should do it for ya … (the rollOver part is just to make it so the cursor stays an arrow when you roll over a disabled button.)

justchad:

I must be in the Twilight-Zone, because I’ve tried it all sorts of ways. I know it should work, but I suspect that I’m somewhere I shouldn’t be. You see, don’t fully understand where the code should be or when the code actually runs.

I’m using the code –

on(release) {
if (home.enabled) {
getURL(“http://symboldomains.com”);
home.enabled = false;
information.enabled = true;
}
}

– where the “Actions - Button” portion of the button “home”

I’m also using –

on(release) {
if (information.enabled) {
getURL(“symbols-as-domains.shtml”);
home.enabled = true;
information.enabled = false;
}
}

– where the “Action - Button” portion of the button “information”

I have attached a zip file that shows what I’m doing.

But, the critter still doesn’t work.

Many thanks for your help.

tedd

Could you post the FLA also? I’m sure I can figure out what’s up, and tell you what you need to know in order to get it working.

justchad:

Sorry, I thought I posted that.

This zip file includes both the .fla and .swf files for the problem at hand.

Many thanks for your interest and time.

tedd

OK… It looks alright. The issue you’re having is pretty straight forward. The problem has two parts.

The first part is that each button instance on your stage needs to have a name applied to it. So the button instance that is sitting over home, and is being called “home” in your code needs to have an instance name of “home”. If you change each instance name to the corresponding button’s name, your code will work as expected.

The OTHER problem doesn’t really make things not work, but as it stands you’re not taking advantage of the object oriented nature of the Flash authoring environment. You have a symbol created for each button on your stage. This is unnecessary! :nerd:

All you need to do is create ONE button symbol, and then drag it repeatedly onto the stage. Each instance can have its own instance name, and its own code to go along with it. This makes your files a bit smaller (though small vector based things such as buttons don’t really effect file size that much, it’s still not a best practice to have multiple copies of essentially the same thing in your library) and makes your FLA a bit easier to work with. (it doesn’t seem so bad when all you have is 4 or 5 buttons, but when you’ve got an application where each library has 100+ components/symbols in it, you’ll appreciate any reusability you can get!)

Also, no problem at all. I’m not busy with work (until after MAX), so I’ve been bored! :crazy:

justchad:

Okay, two things:

  1. You are absolutely right – I understand (in this example) why I should not create more than one button symbol – it was the same button over and over again. However, I did this because when I started the buttons were different for each navigation item. In other words, the “Home” button acted differently than the “Information” button. But, the process degraded (simplified) when it didn’t work.

  2. More importantly, I don’t understand the “instance” thing. When I look at the “Properties” window – the home button states that it has the instance of “home”. And, when I click on “Edit the action script for this object”, my code comes up. How do I change the instance name of a button more than that?

tedd

justchad:

Never mind, I just found it. I’ll let you know it it works.

tedd

Cool. Let me know if you need any more help.

justchad:

Okay, I redid everything from scratch. I made one button with five instances of it with code as you suggested.

While it pulls up the URL’s I want, it still doesn’t stop the reloading of the current page. In other words, the homeBtn.enabled thing is not working as it should.

What now?

tedd

PS: Code is attached.

Your problem is that you need to have some sort of frame specified in your getURL() call. What you’re going to want to do is have your menu in one frame, and then have the content open in another frame. Then, when you call getURL(), pass it the frame’s ID. This will cause the file to open in that frame, rather than in the frame that the menu is loaded in. This will keep the menu’s state the same after clicking, while still updating the information on the screen.

justchad:

Huh? Do you mean something like:getURL(“symboldomains.com”,_self)

That’s a default, isn’t it?

_blank open a new page – I don’t want that.

_parent – I haven’t a clue what that does.

_top – still clueless.

I think it’s something else that’s wrong.

tedd

Hehe… no no… What you need is in your HTML, you’ve got a <frame> or <iframe> tag, right? Give that tag a name atribute… Like this :

<frame name=“content”>

Then when you do your

getURL(), say getURL("www.myURL.com", "content") 

to get your file to load in that frame. :slight_smile:

justchad:

Negatory there chad dude – no frames. Check out the site for the html code, namey:

http://symboldomains.com

I just placed the swf file in my HTML document insetad of making a navigation set of buttons. But, there are no frames – I don’t like them much, bad search engine stuff.

tedd

PS: Got to go pick up the kids – be back soon.

Well, if you’re going to use a SWF to load new content on a page, and the content has to be HTML files, and not just swapping movies out, then you’re stuck with Frames. :frowning:

I can talk more on the issue if need be, but for now, I’ll let you get the kids.