Flash Vista - Ö÷Ò³
本周的热门 Flash 网站
The Two Tales
Site info | 档案文件
主项
Ö÷Ò³
нøÍøÕ¾Á´½Ó
ÓÅÁ¼ÆÀÑ¡ÍøÕ¾
ÈÈÃÅÍøÕ¾
±à¼­ÍƼö
²éÕÒ

Flash Tutorials
Flash Resources
FlashVista 新闻
Flash Templates
Flash Intro Templates
Website Templates
Flash Games
Flash Books
FlashVista 票选
本站图


无故定网站连结
German
Amt1 / Agentur für Kommunikation GmbH
Site info | 找寻另一个
FlashVista
怬
×¢²á×¢²á
¶©Ôĵç×Ó±¨

н¨ÍøÕ¾Á´½Ó
±àÐÞÍøÕ¾Á´½Ó
¸öÈËϲºÃÍøÕ¾
½¨ÒéзÖÀà

打广告
支持
致谢
联落 F

Flash Templates:

More Templates ...

µç×Ó±¨
Óû§

ÃÜÂë



×¢²á×¢²á
Íü¼ÇÃÜÂ룿
Partner websites
Free Hit Counter
Free Seo Tools
Free Tutorials
Free Video Tutorials
Forum signatures
Best Free Scripts
Wii Fit
Wii Fit News
Cool Tech Gadgets
Other Resources
ÍÆ¼ö
ÍÆ¼ö±¾Õ¾¸øÅóÓÑ


µç×Ó±¨
״̬: ÉÐδµÇ¼

Simplified Chinese English German French Spanish Italian Portuguese Russian Polish Finnish Dutch Swedish Thai Romanian Traditional Chinese Simplified Chinese
²éÕÒÉÐδµÇ¼
¹Ø¼ü×Ö: ²éÕÒ£º: ¸ß¼¶²éÕÒ


Variable variables in Flash actionscript


NEW Flash Tutorials in Video Format - Powered by LearnFlash.com: 45 minutes of flash tutorials now available in streaming format or download. Topics Include flash for beginners, text effects, actionscripting, audio/video, flash 8 and more.


Printer version



by Mirza Hatipovic

I often make use of variable variables, because I generally use interpreted languages like PHP. Variable variables are not supported in compiled languages like C++ etc. The same applies for Actionscript. Because I make extensive use of variable variables in PHP, I had some difficulties solving specific problems in Actionscript. Fortunately I found a trick to solve my problem. But before I show you the sample script I will give a short introduction to variable variables in PHP.

Sample PHP script:

//my_var has a string value of “mirza”
$my_var = “mirza”;
//allocate a variable variable of the variable $my_var
$$my_var = 1;
//the upper line of code now has the same meaning like $mirza = 1; !!!


In words, with variable variables you can dynamicaly create variable names and give them values!!!

Now on to Actionscript...

With eval() you can achieve similar results in AS.


//my_var has a string value of “mirza”
my_var = “mirza”;
//allocate a variable variable of the variable my_var
mirza = 1;
//has a value of 1
trace(eval(my_var));

Well, I know that this looks very strange. But I use this method in loops to dynamically create variables like pic1, pic2, pic3.

for(i = 1; i<=5; i++){
//current variable
curr_var = eval(pic + '' + i);
//handle variable…pic1, pic1, etc
}


Hope you’ll find it usefull.


(×¢²áÈÕÆÚ: 11-04-2003, µãÔÄÈË´Î: 0, ÆÀ±È»ý·Ö: 2.78, ƱÊý: 32, ÆÀÂÛÆªÊý: 4)
н¨ÖÁ¸öÈËϲºÃ 建议本站给朋友

ÆÀÂÛÆªÊý: (4)

Good Tutorial
(×¢²áÈÕÆÚ: 12-20-2005 Óû§: ·Ã¿Í)

But it is very usefull if you want to insert arrays into flash with javascript which you can't do directly. But if you set each var like: array[1] => array1 then you can use this function to get your original array back.
(×¢²áÈÕÆÚ: 02-19-2005 Óû§: ·Ã¿Í)


for(i = 1; i<=5; i++){
//current variable
curr_var = eval(pic + '' + i); _root.addProperty("pic" + i, get, set);
//handle variable…pic1, pic1, etc
setProperty("_root.pic" + i, value, "Value: " + i);
}

//===>

for (i = 1; i<= 5; i++) {
trace(eval("_roo.pic" + i));
}

(×¢²áÈÕÆÚ: 02-04-2005 Óû§: ·Ã¿Í)

Much as this tutorial offers useful advice, it is very bad programming practise to do what is done above.

Use arrays instead. Eval was put in actionscript before arrays were put in. Between arrays and ["property"] eval is practially useless. It is only needed in advanced techniques.

(×¢²áÈÕÆÚ: 05-25-2004 Óû§: ·Ã¿Í)


н¨ÆÀÂÛ
Please note:
We review EVERY comment before it appears on the site, so please dont waste your time by posting spam links :)
No URLs allowed, no HTML please.

If you register or login first, your review will contain your nickname


ÆÀ·Ö



ºÜ°ô£¡
·Ç³£ºÃ
ºÃ
¼Ñ
²î