I am currently developing an interactive location map of the UK for a client. Every region of the map is a button that, when click, zooms in towards the viewer whilst all the others fade in the background.
This i can do fine with a single function. However the movieClip that is loaded with attachMovie contains buttons that I simply cannot target for any other function. I believe it is something to do with the attachMovie ObjName not being accessible outside of the function they're created in. I have been trying _global variables but still I cannot assign actions to the buttons.
Please, if some one could just take a look at my code and point me in the right direction so that when I click any of the buttons in the attachMovie I at least get a trace function to work.
I have attached my complete actionscript but the section I'm struggling with is displayed below.
code:
//zoom in
function focus (target_mc:MovieClip, scale_mc:Number, sec:Number, target_x:Number, target_y:Number, focus_mc:String) {
It is very confusing to see what you are trying to do and what you are expecting to happen. Maybe you can clarify your problem more.
Here are some observations anyway...
beds.beds_focus_back never actually exists. You do however attach a beds_focus_back clip to the _root, so _root.beds_focus_back does exist at some point.
No matter where you attach this beds_focus_back to, you need to set it's onRelease event function after it has actually been attached (inside the function that gets run when the Tween has finished for example).
Another confusion is that the button inside beds_focus is named beds_01. Which you make no reference to in your code. Is this button the one you are actually asking for help on, or is it a red herring?
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
sorry for the confusion, I'm obv not explaining it too well.
when the region is clicked it zooms up. After the zoom is finished 2 things happen...
1. "attachMovie (focus_mc ..." places a more detailed view of the zoom
2. "attachMovie ("back_btn" ..." places a "back" button in the top corner
the detailed view of the zoom will have location dots on it (one of these is "beds_01") which will simply display a tooltip when hovered over.
the "back" button will reverse the zoom back to the map of the UK.
so what should happens is... click region > zoom in > click "back" > zoom out
but "back" isn't responding to any on function I type.
I'm really at the edges of what actionscript I know so I really don't know where to look for an answer. All I know is if I can get it to trace something onRelease, I can get it to do everything else.
Ok, then my points posted above; that beds.beds_focus_back never exists and that you need to assign the onRelease function after you have attached the clip in question, are the answers you seek.
Replace your zoomInTween.onMotionFinished with the one below and the button starts to do something.
PHP Code:
zoomInTween.onMotionFinished = function()
{
_root.attachMovie(focus_mc ,focus_Name, 100, {_x:185, _y:177.5, _xscale:scale_mc, _yscale:scale_mc});
var btn:MovieClip = _root.attachMovie("back_btn" ,back_Button, 200, {_x:10, _y:10, _xscale:14.3, _yscale:14.3})
btn.onRelease = function()
{
trace(this+" <-- the back button clip you attached");
}
}
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
Here is the solution without nested functions. It uses the name of the clickable county as a seed for the correct function name. (beds gets assigned the onRelease function beds_focus_back). etc.
PHP Code:
//zoom in
function focus(target_mc:MovieClip, scale_mc:Number, sec:Number, target_x:Number, target_y:Number, focus_mc:String)
{
if (ireland._alpha == 100)
{
var zoomInTween:Tween = new Tween(target_mc, "_xscale", Regular.easeOut, target_mc._xscale, scale_mc, sec, true);
new Tween(target_mc, "_yscale", Regular.easeOut, target_mc._yscale, scale_mc, sec, true);
new Tween(target_mc, "_x", Regular.easeOut, target_mc._x, 185, sec, true);
new Tween(target_mc, "_y", Regular.easeOut, target_mc._y, 177.5, sec, true);
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
Wowzers. Thanks for the extra info, though I actually went with your first option and it makes the "back" button work a charm. One more thing you may be able to help me with is that I still cannot get the location dots within the attachMovie to work onRollOver.
I think there are some timing issues you need to get your head around because I think this is the same problem as before. i.e. The location dots do not exist until the focus_mc is attached.
You will need to assign their functions after you have attached the clips in question, in the same way as the back_button code is assigned after the back_button is attached (e.g. from inside the zoomInTween.onMotionFinished function).
The focus_mc is not attached until zoomInTween.onMotionFinished is executed. zoomInTween.onMotionFinished is not executed until the user clicks on a county and it's animation has finished. The code you have written that is physically underneath the zoomInTween.onMotionFinished is actually executed before that function is ever run. That function just sits and waits until the animation has finished.
so the trace output from the above code will show you the execution order and will be something like this ...
BEFORE FUNCTION
AFTER FUNCTION
DURING FUNCTION: the focus_mc is now attached!
Hope that helps.
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?