PDA

View Full Version : Keeping Track of Multiple Instances of a Class?


rosem
11-17-2008, 04:17 AM
Hey Everyone,

I'm working on charting/graphic in AS3 and have a quick question. I have a Bar class, and a Tooltip class. When you click any Bar on the graph a Tooltip pops up to display the data for that Bar.

My question is, how do I tell the Tooltip class to close when another Tooltip is opened? So if I click on the 5th Bar and a Tooltip comes up, how do I get it to go back down when I click on the 9th Bar?

Is there a design pattern for this? Would I make a custom event listener? I'm not sure what would be the best way to do this.

Thanks,
Mike

ljuwaidah
11-17-2008, 04:25 AM
You can use mouseout to close it. Once the mouse leaves the bar it closes.

Or (I'm not sure about this one) you can make Tooltip a singleton class, that way you always have one instance only.

Do let me know which one works :)

rawmantick
11-17-2008, 04:28 AM
Don't invent the wheel, it's already invented:)

http://www.hotscripts.com/Detailed/73300.html
http://www.dzone.com/links/actionscript_30_tooltip_for_flash_programmers.html
http://www.search-scripts.com/scripts/flash/components/tooltip-as3.0.html
http://blog.nerdbucket.com/actionscript-3-0-tooltip-for-flash-programmers/article

rosem
11-17-2008, 05:17 AM
The tooltip class is already made. I just need some info on. I controlling/managing it.

rawmantick
11-17-2008, 05:25 AM
Usually tool tip class contains static array of objects, that have tips. The class add event listeners to eacj of them. Additionaly it has a static varibale (only one) that is a current tool tip (or null if none). Once any of the tool tip sources dispatch event, your varibale starts to reference it. So the only one (or none) is referenced at a time. When source changes - you simply add a grpahics on the top of stage. Here you go... That's how I'd do it. That's how almost all the tooltop managers a made through the internet...