• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Strings and .currentLabel in function?

Community Beginner ,
Apr 19, 2012 Apr 19, 2012

Copy link to clipboard

Copied

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.

TOPICS
ActionScript

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 20, 2012 Apr 20, 2012

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 m

...

Votes

Translate

Translate
LEGEND ,
Apr 20, 2012 Apr 20, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 20, 2012 Apr 20, 2012

Copy link to clipboard

Copied

Thanks, Ned.

The code in my project is working as I want it with the e.target, but I'll take your advice change it to avoid any future problems.

As far as the rest, I probably didn't explain myself clearly enough, but the code in your post doesn't really do what I was looking for. As I noted at the end of the post, the code I posted was streamlined for clarity. In the actual project

there are several numbered instances and there are about a dozen keyframes in those symbols. My goal is to get a specific  button to react if specific instances match specific groups. To get the code to do what I want, it is important to make sure I define a specific instance and its specific state.

But I think you did point me on the right track in saying I need to assign a string value. What would that look? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2012 Apr 20, 2012

Copy link to clipboard

Copied

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);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 20, 2012 Apr 20, 2012

Copy link to clipboard

Copied

Oh, okay You are taking into consideration some of my previous postings. What I'm trying to do now is similar, but

slightly different.

The code in your last post doesn't do quite what I need because it activates "winbutton" when the two symbols are on

matching labels (e.g. "blue1"). What I want is for the winbutton to be activated if they share labels from matching groups (e.g. "blue1,blue2,blue3", "facesad,facehappy,faceangry"). I would like to be able to exclude certain members of the group, too. For instance, if "One" is the target and its current label is "blue1", I would want "winbutton" to only be activated if its label  is "blue2" or "blue3".

I hope this is a better explanation. Thanks in advance.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 20, 2012 Apr 20, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 20, 2012 Apr 20, 2012

Copy link to clipboard

Copied

LATEST

Thanks, Ned. Sorry for the confusion. Sometimes while trying to explain a situation, I'm not quite sure what information to focus on. Several times I've phrased a question in a particular way that led to an answer that, while correct,  I couldn't really use. I have been attempting  to post the simplest example explanations and simplest example code to explain what I am trying to do , but I usually end up stumbling over my own feet. Here, I basically wanted to ask "What is the correct synstax for the string method in this situation?" but ended up asking an entirely different question!  I guess I was hoping whoever answered the question would latch onto my use of the string method and I could take it from there.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines