0

Struggling to find the answer. Right so I have a variable which is storing a number, and I have a movieclip called "note". I want to add the number onto the end of the note while adding it to the stage. Any suggestions please ?

   var num = 1;        

   addChild(note);     // Should be note1

Edit: Thanks for all your help, i've solved the solution. What I have done is created an array for of the movieclips and used a for statement to go through all of the movieclips.

2 Answers 2

1

If note here is the name of your class (AS linkage), and you want that your instance be called note1, for example, your code can be like this :

var num:int = 1;

this['note' + num] = new note();
addChild(this['note' + num]);

Hope that can help.

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

Comments

1

Try this

import flash.utils.getDefinitionByName;
import flash.display.MovieClip;

var num = 1;
var cl:Class = getDefinitionByName("Note"+num) as Class;
addChild(new cl() );

2 Comments

Thanks for your response i appreciate it. I'm getting an error saying note1 is not defined. But earlier in my file I have var note1:Note1; so surely I have already defined ?
is it Note1 or note1? see the difference of capital "N"?

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.