Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flash Map 1

Status
Not open for further replies.

MGCGuy

Technical User
Oct 1, 2006
6
0
0
CA
Hi,

I'd like to make a map of an area that lets a user click a button to display local points of interest, another button that displays historical buildings, etc., that can be enabled individually or together.

Any ideas on how (using layers, masking, etc.)? Please let me know. Thank you!


Michael
 
Create separate MovieClips contain the base map, points of interest, historical buildings, etc. Then place them on top of each other (the map will go to the bottom of the stack). Then just toggle MovieClips' "_alpha" value between 0 and 100 (or toggle "_visible" between true/false) with the buttons.

Kenneth Kawamoto
 
Thanks Bill and Kenneth!

Bill, I was using a map as more of a metaphor for what I'm trying to do, since most people have seen the sort of thing I have in mind used in that context. So, it's not technically a map, per se, but more of an image with overlays that need to be switched on and off, in combinations or individually, with a descriptive button for each (possibly transparent, but not definitive yet) overlaid image. Thank you very much for the link, it's very useful for future projects and greatly appreciated.

Kenneth, it sounds like you've done this before. If so, do you have any more details or code that you can share? I'm far from an "expert" user and I'd really appreciate any nudges in the right direction! :)

Thank you, gentlemen, for your kind responses and I'm open to more ideas from anyone.

Kind regards,
Michael
 
Oh yes I do this kind of thing all the time.

I'd use only ActionScript to accomplish this though - everything dynamic, nothing on the Stage/Timeline... Anyway, here's how, using the Timeline approach.

1. Go to Timeline and name the layer as, say, "Map".
2. Select the frame 1 of the layer "Map", and draw something on Stage. A blue square will do.
3. Select the blue square on Stage and press F8 key. "Convert to Symbol" box appears. Convert it to a MovieClip and name it to, say, "mcMap".
4. Ensure the blue square is still selected, then go to "Properties" panel and change the Instance Name to "mcMap". Now you have a MopvieClip instance called "mcMap" on Stage in the frame 1 of the Timeline layer "Map".
5. Lock the Timeline layer "Map" so that you won't to mess up with "mcMap".
6. Create a new layer above the "map" layer, and call it, say, "Interest".
7. Select the frame 1 of the layer "Interest", and draw something on Stage. A red circle will do.
8. Select the red circle on Stage and press F8 key to convert it to a MovieClip and name it to, say, "mcInterest".
9. Ensure the red circle is still selected, then go to "Properties" panel and change the Instance Name to "mcInterest". Now you have a MopvieClip instance called "mcInterest" in the frame 1 of the Timeline layer "Interest".
10. Create another layer and name it "Button".
11. Select the frame 1 of the layer "Button", and then drag a Button component from Components panel to the Stage.
12. Go to Properties panel and name the Button component instance to "btn".

Now, let's move on to scripting.

13. Create a new layer and name it "Actions".
14. Select the frame 1 of "Actions" layer.
15. Go to "Actions" panel. Make sure the panel says "Actions - Frame".

Then type in the following:
Code:
mcInterest._visible = false;
btn.onPress = function():Void  {
	mcInterest._visible = !mcInterest._visible;
};
stop();
That's basically it.

Kenneth Kawamoto
 
Hi Kenneth,

That's awesome! You explained that extremely well and made it seem amazingly easy. It works perfectly. Thank you very much! :)

Just wondering, now we have "Interests," and to add the other buttons, like, let's say, "ATMs," or "Post Offices" to my "map," do I need to create additional action layers and use more component buttons? I'm not sure how the other buttons would be enabled. May I impose on you to explain that, too? ;)

Thank you so much again!


Regards,
Michael
 
You can drag the same Button component from Library to the Stage again and again to create more instances. Make sure to give different names to them, for example "btnInterest", "btnATM", "btnPostOffice", etc.

As for the Actions, it's best to keep all the codes in one place.

So, let's say you now have the following MovieClips on top of each other:
(top to bottom)
mcPostOffice
mcATM
mcInterest
mcMap

And you have the following Button component instances on Stage too:
btnInterest
btnATM
btnPostOffice

Then the script in the Actions layer would be:
Code:
mcInterest._visible = false;
mcATM._visible = false;
mcPostOffice._visible = true;
 
btnInterest.onPress = function():Void  {
    mcInterest._visible = !mcInterest._visible;
};
btnATM.onPress = function():Void  {
    mcATM._visible = !mcATM._visible;
};
btnPostOffice.onPress = function():Void  {
    mcPostOffice._visible = !mcPostOffice._visible;
};

stop();

Kenneth Kawamoto
 
Hi Kenneth,

Your suggestion works brilliantly! Thank you very much for your excellent advice and help, you're amazing! :)


Kiind regards,
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top