[英]using a variable name to load movie clip to stage using As3
I have created a Spelling Puzzle in AS3
that loads a list of words from an XML
file into an Array
. 我在AS3
中创建了一个拼写拼图,它将XML
文件中的单词列表加载到Array
。
As the code loops through the array, it assigns each word to a variable called "current_word", then scrambles the letters of "current_word" and displays them on stage. 当代码循环遍历数组时,它会将每个单词分配给一个名为“current_word”的变量,然后对“current_word”的字母进行扰乱并在舞台上显示它们。
I would like to add an animated MovieClip
as a visual aid with the class name that matches the value of current word. 我想添加一个动画MovieClip
作为视觉辅助,其类名与当前单词的值相匹配。
For example if the current word is 'bear', then a MovieClip
with the class name 'bear' is loaded from library to stage. 例如,如果当前单词是“bear”,则将类名为“bear”的MovieClip
从库加载到舞台。
I was trying to create an empty movie clip called "tempItemClip" and overwrite its value with the value of the var current_word
. 我试图创建一个名为“tempItemClip”的空影片剪辑,并使用var current_word
的值覆盖其值。
No errors, but it's not working. 没有错误,但它不起作用。 I am new to ActionScript. 我是ActionScript的新手。 Can someone advise me on the best solution? 有人可以告诉我最好的解决方案吗?
public function getWord()
{
current_word=pWord[ques_num];
setTiles(current_word.length);
ques_num++;
trace(current_word);
var tempItemClip:MovieClip = new MyItem();
Puzzle_screen.addChildAt(tempItemClip,4);
tempItemClip.x=380;
tempItemClip.y=130;
//var myClip:Object = getDefinitionByName(current_word);
var myClip:MovieClip = new MovieClip();
tempItemClip[current_word] = myClip;
tempItemClip.addChild(myClip);
}
It's not clear what you are asking, but I believe this is what you want : 目前尚不清楚你在问什么,但我相信这就是你想要的:
var clipClass:Class = getDefinitionByName(current_word) as Class;
var myClip:MovieClip = new clipClass();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.