0

I'm trying to make a function that make play a symbol animation (hijo) when i click other one (padre). I want a function to use them many times so I'm trying to automatized.

Im getting the instance name of click button "padre" and try to add some sting after that in this case "hijo". I created some vars but when i use string value it doesn't work.

this.padre.addEventListener("click", nose.bind(this));

function nose(evt) {

    var root = this

            //In this case on evt.currentTarget.name i get 'padre' 
    var loprimero = evt.currentTarget.name;
    var loquesigue = "hijo";
    var todito = loprimero + loquesigue;


         //This console fine the name of instance i want gotoAndPlay
    console.log(todito);

        //This is i want to make work
        //This give me cannot read property 'gotoAndPlay' of undefined 
    root.todito.gotoAndPlay(1);

        //And this work fine
    this.padrehijo.gotoAndPlay(1);
}

When I define var loquesigue = this.padrehijo; without quotation marks it works fine. But remember I need to use this on some other parents symbols.

1 Answer 1

0

This is simply logging a string:

console.log(todito);

If you have an instance with that name, you can access it using brackets:

var inst = root[todito];
console.log(inst); // Does this work?

One other note, you don't need to use bind in EaselJS, you can just use on() and its a little cleaner (docs) :)

this.padre.on("click", nose, this);

Cheers,

Sign up to request clarification or add additional context in comments.

2 Comments

Hi there! With this suggetions i get undefined console log. What im doing bad? Thanks for your comments, im new on EaselJS.
You would need to make sure you have a clip on root that has the instance name you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.