A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] can i trace just part of a e.target.name?

  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    88

    resolved [RESOLVED] can i trace just part of a e.target.name?

    hello,

    can i trace just part of an e.target.name? I'm using an array to create multiple instances on stage of a movie clip. so for example, i have "apple1", "apple2", "apple3", etc.

    So if i pick up "apple1" and trace the e.target.name, i'll get "apple1". but what if i just want to trace just the "apple" part? Can I ask AS3 just to read the first 5 characters (in the big picture i want to compare items in a drag and drop type game)?

    I'm not 100% sold that this is the best approach of how I want to do this...but now curiosity has me at least interested.

    Thanks,
    Shields

  2. #2
    Junior Member
    Join Date
    Jun 2009
    Posts
    18
    Here are some links that will help you with manipulating and searching through strings.
    - http://livedocs.adobe.com/flash/9.0/...=00000084.html

    - http://blog.0tutor.com/post.aspx?id=...actionscript-3

    I tried something quick with the search() method to see what it would return if it didn't find anything. It seems to return -1 when nothing matches your query in the string. Note that it is case sensitive.

    PHP Code:
    var textthingy:String "where art thou?";
    trace(textthingy.search("art")); 
    How are you setting the name of the movieclip instances?

  3. #3
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Substringing is one way to go for this but you should really consider comparisons on your actual objects instead of their names.

    PHP Code:
    function eventHandler(e:Event):void{
        switch(
    e.target){
            case 
    apple1:
                
    //  apple1 clicked
                
    break;
            case 
    apple2:
                
    //  apple2 clicked
                
    break;
            
    //...
        
    }


  4. #4
    Member
    Join Date
    Jul 2009
    Posts
    88
    thanks for the help. the links you included led me to substring and that worked perfect!

    Code:
    var editTargetName:String = e.target.name;
    var myTargetName:String = "target" + editTargetName.substring(0,5);

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