A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [CS3] attachMovie ObjName outside of function

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Posts
    4

    [CS3] attachMovie ObjName outside of function

    Hello all

    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) {

    _global.focus_Name = "_focus";
    _global.back_Button = focus_mc + "_back";

    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);

    fadeoutAll(target_mc);
    disableAll(target_mc);

    zoomInTween.onMotionFinished = function() {
    _root.attachMovie(focus_mc ,focus_Name, 100, {_x:185, _y:177.5, _xscale:scale_mc, _yscale:scale_mc});
    _root.attachMovie("back_btn" ,back_Button, 200, {_x:10, _y:10, _xscale:14.3, _yscale:14.3});
    }

    } else {

    removeMovieClip("_focus");
    removeMovieClip(back_Button);

    var zoomOutTween:Tween = new Tween(target_mc, "_xscale", Regular.easeOut, target_mc._xscale, 50, sec, true);
    new Tween(target_mc, "_yscale", Regular.easeOut, target_mc._yscale, 50, sec, true);
    new Tween(target_mc, "_x", Regular.easeOut, target_mc._x, target_x, sec, true);
    new Tween(target_mc, "_y", Regular.easeOut, target_mc._y, target_y, sec, true);

    fadeinAll(target_mc);
    enableAll();
    }
    }


    //beds, bucks, herts & northants
    beds.onRollOver = function() {
    colourswapper(beds,"0xFFADEA");
    };

    beds.onRollOut = function() {
    colourswapper(beds,"0xCE8BBC");
    };

    beds.onRelease = function() {
    focus(beds, 400, 0.5, 267.9, 282.8, "beds_focus");
    trace (back_Button);
    trace (focus_Name);
    };

    beds.beds_focus_back.onRelease = function () {
    trace ("It works!");
    }

    Attached Files Attached Files

  2. #2
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    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?

  3. #3
    Junior Member
    Join Date
    Jul 2008
    Posts
    4
    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.

    Thank you for your reply

  4. #4
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    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_Name100, {_x:185_y:177.5_xscale:scale_mc_yscale:scale_mc});
        var 
    btn:MovieClip _root.attachMovie("back_btn" ,back_Button200, {_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?

  5. #5
    Junior Member
    Join Date
    Jul 2008
    Posts
    4
    Thank you very much, it has indeed started to do what it's told.
    Last edited by mattpodge; 07-10-2008 at 10:35 AM.

  6. #6
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    no worries.

    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:MovieClipscale_mc:Numbersec:Numbertarget_x:Numbertarget_y:Numberfocus_mc:String)
    {
        if (
    ireland._alpha == 100)
        {
            var 
    zoomInTween:Tween = new Tween(target_mc"_xscale"Regular.easeOuttarget_mc._xscalescale_mcsectrue);
            new 
    Tween(target_mc"_yscale"Regular.easeOuttarget_mc._yscalescale_mcsectrue);
            new 
    Tween(target_mc"_x"Regular.easeOuttarget_mc._x185sectrue);
            new 
    Tween(target_mc"_y"Regular.easeOuttarget_mc._y177.5sectrue);

            
    fadeoutAll(target_mc);
            
    disableAll(target_mc);

            
    zoomInTween.onMotionFinished zoomFinished;
        }
        else
        {
            
    removeMovieClip("_focus");
            
    removeMovieClip(back_Button);

            var 
    zoomOutTween:Tween = new Tween(target_mc"_xscale"Regular.easeOuttarget_mc._xscale50sectrue);
            new 
    Tween(target_mc"_yscale"Regular.easeOuttarget_mc._yscale50sectrue);
            new 
    Tween(target_mc"_x"Regular.easeOuttarget_mc._xtarget_xsectrue);
            new 
    Tween(target_mc"_y"Regular.easeOuttarget_mc._ytarget_ysectrue);

            
    fadeinAll(target_mc);
            
    enableAll();
        }
    }


    //beds, bucks, herts & northants
    beds.onRollOver = function()
    {
        
    colourswapper(beds,"0xFFADEA");
    };

    beds.onRollOut = function()
    {
        
    colourswapper(beds,"0xCE8BBC");
    };

    beds.onRelease = function()
    {
        
    focus(beds,400,0.5,267.9,282.8,"beds_focus");
    };

    function 
    beds_focus_back()
    {
        
    trace ("It works!");
    }

    function 
    zoomFinished(o:Object)
    {
        
    _root.attachMovie(o.obj._name+"_focus""_focus"100, {_x:185_y:177.5_xscale:o.obj._xscale_yscale:o.obj._yscale});
        var 
    btn:MovieClip _root.attachMovie("back_btn"back_Button200, {_x:10_y:10_xscale:14.3_yscale:14.3});
        
    btn.onRelease o.obj._parent[o.obj._name+"_focus_back"];

    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?

  7. #7
    Junior Member
    Join Date
    Jul 2008
    Posts
    4
    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 have altered the code to as follows...

    PHP Code:
        zoomInTween.onMotionFinished = function() {
            
    //detailed view
            
    _global.zoomView attachMovie(focus_mc,"_focus",100,{_x:185_y:177.5_xscale:scale_mc_yscale:scale_mc});
            
            
    //back button
            
    _global.back_button attachMovie("back_btn"focus_mc+"_back"200, {_x:10_y:10_xscale:14.3_yscale:14.3});

            
    back_button.onRelease = function() {
                
    trace("Back!");
                new 
    Tween(target_mc"_xscale"Regular.easeOuttarget_mc._xscale50sectrue);
                new 
    Tween(target_mc"_yscale"Regular.easeOuttarget_mc._yscale50sectrue);
                new 
    Tween(target_mc"_x"Regular.easeOuttarget_mc._xtarget_xsectrue);
                new 
    Tween(target_mc"_y"Regular.easeOuttarget_mc._ytarget_ysectrue);

                
    removeMovieClip(zoomView);
                
    removeMovieClip(back_button);
                
    fadeinAll(target_mc);
                
    enableAll();
            };
        }; 
    ...and then latter on when I check the name of zoomView with a trace it returns "undefined", when it should surely be "_focus", am I wrong?

    This is so when I come to defining the tooltips later for each of the various locations it can list like...

    PHP Code:
    _focus.location_dot_1 = function() {
    showTooltip("location_dot_1");
    }

    _focus.location_dot_2 = function() {
    showTooltip("location_dot_2");


  8. #8
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    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.

    PHP Code:
    trace("BEFORE FUNCTION");
    zoomInTween.onMotionFinished = function() {
        
    //detailed view
        
    _global.zoomView attachMovie(focus_mc,"_focus",100,{_x:185_y:177.5_xscale:scale_mc_yscale:scale_mc});
        
        
    //back button
        
    _global.back_button attachMovie("back_btn"focus_mc+"_back"200, {_x:10_y:10_xscale:14.3_yscale:14.3});

        
    trace("DURING FUNCTION: the focus_mc is now attached!");

        
    back_button.onRelease = function() {
            
    trace("Back!");
        };

        
    zoomView.location_dot_1.onRelease = function() {
            
    trace("location dot 1");
        };

        
    };
    trace("AFTER FUNCTION"); 
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center