dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: duplicate instance names

  1. #1
    Esquire Frank DeRosa's Avatar
    Join Date
    Dec 2002
    Location
    the Matrix
    Posts
    144

    duplicate instance names

    I have a number of layers with a button in each that have instance names set. I'm using a string to keep track of the button clicked so I can disable it once it's clicked and re-enable it later if another button is clicked. This means it's important for multiple instances of the same symobol to have the same name.

    What are the implications of taking the same symbol, in the same layer, but on different (identical) keyframes, and giving them the same instance name?

    Thanks,
    Frank

  2. #2
    Young Senior Member mayhem_sci's Avatar
    Join Date
    Jun 2002
    Location
    Singapore
    Posts
    282
    sometimes i wonder whether people who post here really wants to be understood. different (identical) keyframes?!

    anyway as long as they are on different frames, it doesnt matter.

  3. #3
    Senior Member
    Join Date
    Aug 2002
    Location
    Dublin, Ireland
    Posts
    1,749

    Avoid using the same instance name twice on the same timeline

    anyway as long as they are on different frames, it doesnt matter
    What about if the frames overlap?
    Using the same instancename in multiple places on the same timeline is not good practice. Even if for no other reason than if you need to reorganise your file at any time then you have to manually check and alter every single instancename on the stage. It almost guarantees that you will cause Flash to misbehave at some point.

    This means it's important for multiple instances of the same symobol to have the same name.
    Why do you need that? You just need to have an array of instancenames, for eg:
    PHP Code:
    instanceArray = ["button1""button2""button3"];
    function 
    hideclicked(setup) {
        var 
    i;
        var 
    mcname;
        
    // "this" will contain the reference to the calling MC or button
        
    mcname this._name;
        for (
    i=0i<instancearray.lengthi++) {
            
    // The setup value allows me to turn all buttons on
            // To do the activation, I check for any MC where the instancename
            // is different to the one calling the function OR all of them
            // if setup is set to true.
            
    if (instancearray[i] !== mcname || setup) {
                
    // Activate all the buttons that are not clicked
                
    trace("ACTIVATING _root["+instancearray[i]+"]");
                
    _root[instancearray[i]].onRelease hideclicked;
                
    _root[instancearray[i]]._alpha 100;
            } else {
                
    // Deactivate the button that called the function
                // You would also put any code you want the button
                // to execute in here.
                
    trace("DEACTIVATING "+targetpath(this));
                
    delete this.onRelease;
                
    this._alpha 50;
            }
        }
    }
    // Finally, I call the function to set up all the buttons
    hideclicked(true); 
    When any button in the array is clicked, it deletes its onRelease function (deactivating the button) and cycles through the list of instances to activate them by assigning the onRelease function.

  4. #4
    Esquire Frank DeRosa's Avatar
    Join Date
    Dec 2002
    Location
    the Matrix
    Posts
    144
    Hmmm.... now that I think about it, to get things to behave properly, I've made changes that may render my use of duplicate instance names unnecessary.

    By the way, the instances were always in the same layer but never the same frame.

    Thanks for the code, by the way... good stuff.
    Frank

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