Go Back   kirupaForum > Flash > Flash CS3

Reply
 
Thread Tools Display Modes
Old 11-19-2009, 05:54 PM   #1
Solidus
you're not your khakis
 
Solidus's Avatar
This cant be the best way to make Button Rollovers...

I currently have a flash file that has a whole bunch of buttons that are MC's with rollover and out states that open up a PDF when clicked.



For each number (12-33) I have the MC with a new instance name and I am calling them with the following code:

Code:
stop();
over12.addEventListener(MouseEvent.CLICK, over12Click);
over12.addEventListener(MouseEvent.MOUSE_OVER, over12Over);
over12.addEventListener(MouseEvent.MOUSE_OUT, over12Out);
function over12Click(event:MouseEvent):void {
    navigateToURL(new URLRequest("catalog/12.pdf"));
}
function over12Over(event:MouseEvent) :void
{
    event.currentTarget.gotoAndPlay("over");    
} 
function over12Out(event:MouseEvent) :void
{
    event.currentTarget.gotoAndPlay("out");    
}
So for each button I have this huge mess of code. There has to be a cleaner and more efficient way of doing this. Can you guys suggest anything?
Solidus is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 11-19-2009, 06:53 PM   #2
_kp
 
 
_kp's Avatar
You already did the right thing to reference the buttons by using event.currentTarget
You still need to add a listener to each button but all can use the same function:
ActionScript Code:
over12.addEventListener(MouseEvent.MOUSE_OVER, overOver);
over13.addEventListener(MouseEvent.MOUSE_OVER, overOver);
//...
over33.addEventListener(MouseEvent.MOUSE_OVER, overOver);

function overOver(event:MouseEvent) :void
{
    event.currentTarget.gotoAndPlay("over");   
}


This won't work right away with overClick because you need to get that number from somewhere.
The best way to do this would be using a dictionary, a fast way to do this would be setting the buttons names to file names they should open
_kp is online now   Reply With Quote
Old 11-19-2009, 07:03 PM   #3
Solidus
you're not your khakis
 
Solidus's Avatar
_kp I am pretty sure it has been you that's helped me on numerous other stuff so thanks again for the help I really appreciate it.

Everything you wrote makes sense to me except for:

Quote:
This won't work right away with overClick because you need to get that number from somewhere.
The best way to do this would be using a dictionary, a fast way to do this would be setting the buttons names to file names they should open
Do you mean a literal dictionary? Or is that some flash terminology? The names of all the PDF's are the number plus extension for instance 13.pdf, 14.pdf, and so on. Is there a way to use variable that plugs in for the NavigatetoURL?
Solidus is offline   Reply With Quote
Old 11-19-2009, 07:17 PM   #4
Solidus
you're not your khakis
 
Solidus's Avatar
Ha okay it is a new Flash thing!
I am looking it up right now and it seems really powerful. So your suggesting I name the instance of my MovieClip mouseovers to the name of the file they open?

If its not to much trouble could you give a example of what the code would look like?
Solidus is offline   Reply With Quote
Old 11-19-2009, 07:25 PM   #5
_kp
 
 
_kp's Avatar
here's some useful information if you haven't already found it: http://www.gskinner.com/blog/archive...ictionary.html

with a dictionary you can use something like this:
navigateToURL(new URLRequest("catalog/"+dict[event.currentTarget]));

If your button were of a custom class you could simply create a variable inside of it and assign the value.

Naming the buttons '12', '13' ... and using something like navigateToURL(new URLRequest("catalog/"+event.currentTarget.name+".pdf"); should work too but it's some quick and dirty misuse of the name attribute.

Nice to know someone remembered me
_kp is online now   Reply With Quote
Old 11-19-2009, 07:44 PM   #6
Solidus
you're not your khakis
 
Solidus's Avatar
I do man. You seem to be the guy that always ends up helping me. You and Senocular. You guys are awesome.

Okay I checked that link out and it is so over my head I am embarrassed to admit it.

I understand the basic principle is that:
The buttons have a variable.
That Variable is remembered by flash when someone rollovers the button.
If they click Flash inputs the value of that variable into the extension were trying to open.

I understand how to do that with Global.Variables and such I just don't get how it works with this dictionary thing.



Do I create a new button for each number that opens a PDF and assign it a identifer? Where am I declaring the value of each button so that the dictionary can find it?
Solidus is offline   Reply With Quote
Old 11-19-2009, 09:13 PM   #7
_kp
 
 
_kp's Avatar
Me and Senocular mentioned in the same sentence, I'm honored

The Dictionary class is not that complicated once you get the hang of it.
(I avoided it too the first time I saw it )

here's an example:
ActionScript Code:
var dict:Dictionary = new Dictionary(true);
var s1:Sprite = new Sprite();
var s2:Sprite = new Sprite();

dict[s1] = "foo";
dict[s2] = "123";

trace(dict[s1]); // traces: foo
trace(dict[s2]); // traces: 123
 


You assign objects as a keys (s1, s2) and link them to other objects, in this case Strings.

And that's exactly what you need, after creating your buttons you put them in the dictionary and assign a string or maybe even better an urlRequest to it:

dict[over12] = new URLRequest("catalog/12.pdf");

And call it in your function with

navigateToURL( dict[event.currentTarget] );

_kp is online now   Reply With Quote
Old 11-20-2009, 07:56 PM   #8
Solidus
you're not your khakis
 
Solidus's Avatar
KP that worked perfectly!
Perfect explanation man I was actually able to understand that.

You have been a huge help bro thanks for yet again educating me.
Solidus is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:40 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com