Flash automatically names objects on stage "instance#"
        Posted  
        
            by 
                meowMIX3R
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by meowMIX3R
        
        
        
        Published on 2010-12-28T17:10:35Z
        Indexed on 
            2010/12/29
            13:54 UTC
        
        
        Read the original article
        Hit count: 205
        
Hi, I have 2 TLF text boxes already placed on my main stage. In the property inspector window I give these the instance names: "txt1" and "txt2".
I am trying to have a single mouseup event, and figure out which text box it occurred on.
My document class has the following code:
package  {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class SingleEvent extends Sprite{
    public function SingleEvent() {
        // constructor code
        root.addEventListener(KeyboardEvent.KEY_UP, textChanged,false,0,true);
    }
    private function textChanged(e:KeyboardEvent){
        trace(e.target.name);
        trace("   " + e.target);
        switch(e.target){
            case txt1:
                trace("txt1 is active");
                break;
            case txt2:
                trace("txt2 is active");
                break;
            default:
                break;
        }
    }
    }
}
Example output is:
instance15
   [object Sprite]
instance21
   [object Sprite]
Since the objects are already on the stage, I am not sure how to get flash to recognize them as "txt1" and "txt2" instead of "instance#". I tried setting the .name property, but it had no effect.
In the publish settings, I have "Automatically declare stage instances" checked.
Also, is it possible to have a single change event for multiple slider components? The following never fires:
root.addEventListener(SliderEvent.CHANGE, sliderChanged,false,0,true);
Thanks for any tips
© Stack Overflow or respective owner