Groups | Blog | Home
all groups > flash actionscript > march 2006 >

flash actionscript : Button down state & links


Jekyl1
3/22/2006 10:50:40 PM
Hi, very very new to Flash. I have looked at other posts regarding this topic,
but I don't quite understand them and/or they don't quite apply to my situation.

I was hoping one of you experts out there may be able to help me out.

Ok, I have a Navigation Bar. It look like a flower. Each petal is a different
button which takes the user to a different page. This .swf will be within HTML
pages.

So, my problem is: I know nothing. No, seriously, I just don't understand all
the techno-speak. I want threethings to happen:
1. When the user rolls over a petal, the color of that petal changes.
2. When the user clicks that button, they are taken to the HTML page which
corresponds to that button
3. When the new page loads, the button that the user clicked (i.e. the current
page) remains in it's down state and the previous button from the previous page
reutrns to it's up state.

The first 2 I have already accomplished by creating 6 different buttons and
adding a getURL action to each. But I do not understand variables that well,
and it seems that's what I need for #3. Also, it seems that with buttons, you
can't specify which state (up, over, down) you want to be displayed.

Any and all help is extraordinarily appreciated.

Thanks!
kglad
3/22/2006 11:50:37 PM
Jekyl1
3/23/2006 12:55:26 AM
kglad,
What is a movie clip button? Again, very VERY new to Flash. Speak to me like
I'm a really dumb child ;-)
I did try to create a movie clip in which there were 3 frames: one for each
button state. However, then when I try to add a "on rollover" action, it says
that I can only use those for button instances.

I really need someone to take me through step by step if possible.
kglad
3/23/2006 3:28:14 AM
you can use all the same mouse handlers for movieclips that you can use for
buttons. so, if you have a movieclip with frame 1 being the up state (attach a
stop() ), a "down" frame and an "over" frame you can use:



yourMCBtn.onRollOver=function(){
this.gotoAndStop("over");
}
yourMCBtn.onPress=function(){
this.pressed=1;
//loop through your other buttons and set their pressed property to false and
direct them to their "up" frame.
this.gotoAndStop("down");
}
yourMCBtn.onRollOut=function(){
if(!this.pressed){
this.gotoAndStop("up");
}
}
Jekyl1
3/23/2006 10:48:35 PM
OKAY!! This is starting to work! Thank you!

Here's what I have so far. Attach to my movie clip button is this:

onClipEvent (load) {

//rollover function
this.onRollOver=function(){
this.gotoAndStop("down");
}
this.onRollOut=function(){
this.gotoAndStop("up");
}
}

//takes user to selected page
on (release) {
getURL("page2.html");
}


Hopefully that is clear, I don't know how to attach code so it looks good.
Anyway, the final part of this puzzle is I need a way to have the HTML page
pass a variable to the .swf file. This variable, let's call it "currentPage",
will tell the .swf file which page of the site is currently being shown. The
..swf file will then switch the appropriate button to it's "down" state.

So, if a user clicks on the "watch" button, they are taken to "watch.html".
The .swf file will reload and should be able to know that the current page is
"watch.html" and switch the watch button to it's down state.

Any ideas on how to do this in conjunction with the above code?

Thanks again, you have already helped me incredibly.
kglad
3/24/2006 12:00:00 AM
Jekyl1
3/24/2006 12:00:00 AM
TimSymons
3/24/2006 1:03:34 AM
You could attach the information the web page that you are calling like this:

getURL("page2.html?currentPage="+currentPage);

Then in the page2.html file you could use JavaScript to strip out the value
and then when you are loading the SWF file again, just attach the variable to
the name like this:

swffile.swf?currentPage=thePage

In your SWF file you should have a variable named "currentPage" then this
variable will be filled with the value you passed.

A good resource for JavaScript code is:
http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/

You will want to look at the "document.location" object.

Tim
TimSymons
3/24/2006 1:22:33 AM
I just realized too that you could use frames and then just target the one
frame to load the pages. Your frameset might look like this:

<frameset cols="200,*">
<frame name="menu" src="your.swf">
<frame name="content" src="page1.html">
</frameset>

Then your actionscript would look like this:

getURL("page2.html", "content");

Anyway, it is just another idea and this way you won't have to pass a variable
to your SWF file.

Tim
kglad
3/24/2006 1:51:49 AM
you don't need to pass any variables. flash can handle that without problem.
in fact, the code i gave in my original message has flash detecting the current
page and keeping the corresponding button in the "down" frame.
Jekyl1
3/24/2006 2:45:28 AM
kglad,
maybe I'm doing something wrong, but the code you gave me doesn't seem to
detect the current page and keep the pressed button in the down state.

I have the code attached to the movie clip button itself, not on the timeline.
Does that matter? I tried to put in its own frame in an "actions" layer, but I
got an error saying that the code had to be within an on handler and that an on
handler could only be attached to clips, etc.

And I don't see how flash could know what to do unless I specify what to do
for each page, being that when the user clicks a button, the html page changes
and by changing the html page, the flash movie ends and is reloaded with the
new page.

Of course I could just be spouting ridiculousness right now and you may have a
simple solution!

Thanks again...


PS Tim, I'm gonna take a stab at the variable option you laid out. Keep in
mind, I'm a virtual vegetable with this stuff...
kglad
3/24/2006 3:35:38 PM
Jekyl1
3/24/2006 4:12:27 PM
kglad,
thank you so much for helping me out on this. I really appreciate it.

But, unfortunately, when I upload the .swf to my site, and I press the watch
button, I get a "The system cannot find the file specified. " error, and the
URL reads "undefined".
I even tried to test it by taking out all the other btnA and targetA entries
except for "mc_watch" and "watch.html", but to no avail.

Any ideas?

Thanks!
Jekyl1
3/24/2006 6:21:24 PM
kglad,
okay, so i figured out the "undefined" error. So, the parts that work now are:
1. The rollover. When I rollover the button, it changes to the down state.
2. The link. When I click the button, it takes me to the desired page.
What's still not working is when that desired page is loaded, I want the
button that was just clicked to load in it's down position. But it seems that I
need some kind of "if statement" saying "if the current page is watch.html,
then mc_watch.gotoAndStop("down").

Does that make any sense?

You're saving my life,
Thanks
kglad
3/25/2006 4:42:06 PM
why are you reloading the swf? that's not good design.

Jekyl1
3/25/2006 5:45:56 PM
Yeah, I realize it's not the right way to do it, but I don't really know the
right way. I don't understand how it's possible to have a new html page load
without closing the .swf file. Isn't the .swf embedded in the html? That's how
it appears to be in Dreamweaver. Keep in mind, I'm not building a Flash site. I
have 6 .html pages (designed in dreamweaver), and within those six pages I want
to put this menu/swf.

I think that's why some people have suggested passing a variable to the .swf
so that when the new page loads, there is a variable loaded, the .swf reads
that variable and reacts accordingly.

I understand how to add a variable in the html
(menu.swf?currentPage=variable), but what I don't get isw how to have Flash
pick up that variable and use it.

Thanks.


PS I can't tell how thankful I am that you are spending so much time on this.
TimSymons
3/25/2006 9:20:39 PM
Jekyl1,

When you pass the variable using this method:

myfile.swf?currentPage=page.html

Just have a variable defined on the very first frame of your movie. For
example, when I connect my e-Learning courses to a server I have to pass 2
values. I call my SWF as above and in the 1st frame of my SWF file I have the
following:

var aicc_url:String;
var aicc_sid:String;

The are not assigned any values within the SWF file but when I call the SWF
file like this:

my.swf?aicc_url=value&aicc_sid=value

Then those variables are automatically assigned those values.

Even though this works, I would still recommend using frames as I mentioned in
a previous post. It would be a better design with less coding in Flash to have
your menu automatically set a button to down state when loaded.

Tim
Jekyl1
3/26/2006 6:55:49 PM
Tim and kglad,

Thank you both so much for all of your help. Based on your suggestions, I was
able piece together something that works exactly the way I want it to. I know
it's not the best way to do it, but it works, and I understand a liitle bit
more about how it works.

Thank you again, you both really helped me out.
AddThis Social Bookmark Button