A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: referencing to instance names?

  1. #1
    Senior Member
    Join Date
    Nov 2006
    Posts
    162

    referencing to instance names?

    I am creating a flash menu and I have a function that dynamically sets the links:

    Actionscript Code:
    buttons.addEventListener(MouseEvent.CLICK, gotoPage);


    function gotoPage(event:MouseEvent):void
    {
        var btnName:String = event.target.name;
        btnName = btnName.slice(0,btnName.indexOf("_"));
        var newAddress:String = "/" + btnName + ".html";
        var linkRequest:URLRequest = new URLRequest(newAddress);
        navigateToURL(linkRequest, "_self");
    }

    It was working at the early stage but now it sets the links to weird instance names I have no idea where they come from, like instance4...

    I tried to rename with the .name but it wont let me do it as they are placed on the timeline.

    Any suggestions?

    Thanks

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The event target is not what you think it is. It is probably some Shape or other object inside your button that is actually the target. If you set mouseChildren = false on the buttons, it'll probably fix it.

  3. #3
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    Ok thanks 5tons, it did change the instance name but still does not fix that crazy issue.

    If I dont use buttons.mouseChildren = false;, then my instance names are all different ranging from 2 to 5...

    If I use it, then they are all instance11.

    And if I do trace (buttons.name);, then I get instance114!

    It was working at my early stages. Then I changed the text field in the buttons to be dynamic so I can update it with AS... would that be the issue?

    I am so confuse..

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    From the way you had named things, I thought you had a container Sprite (or MovieClip) called 'buttons' which had individual buttons with the instancenames you wanted. I was suggesting setting mouseChildren to false on those individual button instances. Since you are getting instance# for all of them, I don't think you've actually set any instancenames. Are you creating these button instances from the IDE or by code? A variable is not the same thing as an instancename.

  5. #5
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    I have a custom class for my buttons and I am groupings the buttons into an array:
    Actionscript Code:
    var buttons:ButtonSet = new ButtonSet();
    buttons.addButtons([index_mc, services_mc, profile_mc, terminal_mc, map_mc, certifications_mc, contact_mc]);


    addChild(buttons);

    They are placed first on the timeline with their own instance name that reflects the one in the array.

    Each of the buttons come from the same MC which has a dynamic text field. I set the text with AS:
    Actionscript Code:
    index_mc.text_mc.text_txt.text = "ACCUEIL"
    index_mc.textover_mc.text_txt.text = "ACCUEIL"
    etc...

    Should I set the instance name with AS? I am not sure how to do that yet..

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If addButtons is actually adding the same instances that it is passed, then you shouldn't need to set the names. Can you post addButtons?

  7. #7
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    yes, here is the button class:
    Actionscript Code:
    public class ButtonSet extends MovieClip
        {
            public var buttons:Array;
           
            public function ButtonSet()
            {
               
            }
           
            public function addButtons(buttonSet:Array):void
            {
                buttons = buttonSet;
                for(var i:int = 0; i < buttons.length; i++)
                {
                    addChild(buttons[i]);
                }
            }
        }
    }

    Thanks a lot for trying to help me :-)

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    huh. You're adding the same instance you were given, so that's good. But you're not manipulating the coordinates or anything? Okay, if it works then great.

    Try putting a trace in when adding each to verify they have the names you expect.
    Code:
    public class ButtonSet extends MovieClip
        {
            public var buttons:Array;
           
            public function ButtonSet()
            {
               
            }
           
            public function addButtons(buttonSet:Array):void
            {
                buttons = buttonSet;
                for(var i:int = 0; i < buttons.length; i++)
                {
                    var b:Sprite = Sprite(buttons[i]);
                    trace(b.name);
                    b.mouseChildren = false;
                    addChild(b);
                }
            }
        }
    }

  9. #9
    Senior Member
    Join Date
    Nov 2006
    Posts
    162
    That is awesome! Yes it works perfectly. Thank you so much for taking the time to help me :-)

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