การอ้างอิง Class แบบ dynamic ด้วย getDefinitionByName() by

31
Aug
0

getDefinitionByName() เป็นการอ้างอิง  Class แบบ dynamic  เช่น ถ้าเรามี Class หรือมีการสร้างมูฟวี่คลิปไว้ในไลบราลี่

เราก็สามารถอ้างอิงนำมาใช้แบบ  dynamic ในรูปแบบที่หลากหลาย เช่น
ในไลบราลี่ มี Mc1,Mc2,Mc3,Mc4,Mc5

เราจะทำการสร้างมูฟวี่คลิปขึ้นมาใหม่ โดยการ Random Class จากไลบราลี่
var _flower:MovieClip;
for (var i:uint=0; i<10; i++)
{
var num:uint = (Math.random()*5)+1;
var classRef:Class = Class(getDefinitionByName("Mc"+num));
_flower = new classRef();
_flower.name = "mc" + (i + 1);
addChild(_flower);
}

ทีนี้เราก็จะได้มูฟวี่คลิปที่แตกต่างกัน

ตัวอย่าง

https://dl-web.dropbox.com/get/Public/blog_levelup.swf?w=3ec274cc

Enjoy this article?

Consider subscribing to our RSS feed!

ไม่มีความเห็น

ยังไม่มีความเห็น

ใส่ความเห็น

RSS feed for comments on this post

 เราชนะรอบ 4 | ยืมเงิน 3000 ด่วน | แอพกู้เงิน | แอพเงินด่วน | สินเชื่อออนไลน์อนุมัติทันที | Site Map | กู้เงินก้อน | กระเป๋าตัง | thisshop และ ยืมเงินฉุกเฉิน 5000 ด่วน