Skip navigation
Currently Being Moderated

Strings and .currentLabel in function?

Apr 19, 2012 11:17 PM

I have two instances on stage-"One" and "Two"- both copies of the same symbol. The symbol contains four frames: "facehappy"and "facesad", and "blue1" and "blue2".

There is a third instance on the stage called "winbutton". It has one blank frame and a second frame with text that says "WIN!".

 

 

I want to set it up so that "winbutton" will move to it's second frame if "One" or "Two" is pressed while it shares the same label as it's partner.

 

I do not fully understand strings yet, but have been trying variations of this code:

 

function moveCake(e:MouseEvent)

{if

    

                (

                 (e.target.currentLabel == two.("face"+String )) ||

                 (e.target.currentLabel == two.("blue"+String ))

                )

                 {

                  winbutton.gotoAndStop(frame2)

                 }

 

    )

 

Note: This is a streamlined version of a much more complex code. I would definitely prefer keeping e.target  in their, if that can be done.

 
Replies
  • Currently Being Moderated
    Apr 20, 2012 4:23 AM   in reply to witherton

    You probably do not want to keep e.target in there.  e.target can point to something inside the object that you click, such as one of the face graphics.  You should use e.currentTarget instead.  currentTarget points to the object that has the event listener assigned.

     

    As far as your comparisons go, if you are testing a string value, you only need to use the string values.  Using the "two. " as you have doesn't do anything for you except probably generate an error.

     

    if(e.currentTarget.currentLabel == "facesad" || e.currentTarget.currentLabel == "blue1")

     

    You do not want to use "String" in your code like you did because that is a class name in AS3.  If you want to do something like that then use "face"+string, where string is a variable that is assigned a String value.

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2012 11:24 AM   in reply to witherton

    Labels are strings, so they would look just like I showed "thisisastring"  Based on your description of the intention of the code, I don't think you are going about it per what you say you want (or what I described in your other posting for this).  If you want see if One and Two are displaying the same thing, then give them the same frame labels for the same things and compare the frame labels...

     

    if(One.currentLabel == Two.currentLabel) winbutton.gotoAndStop(frame2);

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 20, 2012 6:53 PM   in reply to witherton

    What you just attempted to explain doesn't agree with what your posting started with... " want to set it up so that "winbutton" will move to it's second frame if "One" or "Two" is pressed while it shares the same label as it's partner."

     

    It sounds like you need to try to tackle this yourself and weather the storm to solve it, because I can't follow what you say you want now.  You know what you want and just need to put the thought logic into code logic. 

     

    If what you are saying now is you want to match labels that share the "blue" or "face" text in them, then you can use the String.indexOf() method to see if they conatin a certain string value or not.

     

    if( String(e.target.currentLabel),indexOf("face") > -1)  // the labels contains "face" if this is true

     

    Look it up in tthe help documents to get a thorough explanation of what it does.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points