Thanks!
The double cast was causing the problems. By removing the 'as Class' you
can actually make a new instance of what ever in in the array at element
n.
It works super smooth now :)
function getAsset( index:uint ):Bitmap {
return Bitmap( new ALL_CARS[index]() as Class );
}
Good weekend all!
Sidney
> Version 1:
>
> public class EmbedTest extends Sprite {
> [Embed(source="clear.png")]
> private static const PRO_CAR : Class;
> public static const ALL_CARS:Array = [PRO_CAR];
>
> public static function getAsset( index:uint ) : Bitmap {
> return new ALL_CARS[index]();
> }
>
> public function EmbedTest() {
> addChild(getAsset(0));
> }
> }
>
> Version 2:
>
> public class EmbedTest2 extends Sprite {
> [Embed(source="clear.png")]
> private static const PRO_CAR : Class;
>
> public static function getAsset(name : String) : Bitmap {
> try {
> return new EmbedTest2[name]();
> } catch (e:Error) {
> trace ("ERROR asset is not accessible " + name);
> }
> return new Bitmap();
> }
>
> public function EmbedTest2() {
> addChild(getAsset("PRO_CAR"));
> addChild(getAsset("PRO_CAR2"));
> }
> }
>
> Am 11.02.2011 15:30, schrieb Sidney de Koning - Funky Monkey Studios:
>> public static function getAsset( index:uint ):Bitmap {
>>
>> return Bitmap( new ALL_CARS[index]() as Class );
>> }
>
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
--
Sidney de Koning - "If you're not prepared to be wrong, you'll never come
up with something original"
Flash / AIR Developer @ www.funky-monkey.nl
Actionscript 3 Teacher @ www.sae.nl
Technical Writer @ www.insideria.com
Blogger @ www.funky-monkey.nl/blog/
3GB free storage you can sync with your mobile device or Mac or PC.
Check out https://www.getdropbox.com/referrals/NTI1MjcxMzk
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders