Re: [Flashcoders] Calling an element in an Array as an Class

2011-02-11 Thread Sidney de Koning - Funky Monkey Studios
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
> Flashcoders@chattyfig.figleaf.com
> 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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Calling an element in an Array as an Class

2011-02-11 Thread Jens Struwe

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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Calling an element in an Array as an Class

2011-02-11 Thread Sidney de Koning - Funky Monkey Studios
Hi Michael,

Thanks for the tip, normaly i would to, its just that this particular
project has already set its course on using the EMBED method.

Stubborn as i am, i still want to crack this nut :)
So does anybody know how to accomplish this?

Greets,
Sid

>> Or does anybody know a better method?
>
> I recently started using LoaderMax for loading assets.  I will never ever
> look back to manually loading my assets.  :-)
> http://blog.greensock.com/loadermax/
>
> - Michael M.
>
> ___
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> 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
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


RE: [Flashcoders] Calling an element in an Array as an Class

2011-02-11 Thread Mendelsohn, Michael
> Or does anybody know a better method?

I recently started using LoaderMax for loading assets.  I will never ever look 
back to manually loading my assets.  :-)
http://blog.greensock.com/loadermax/

- Michael M.

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders