Tuesday, October 27, 2009

AS3: Opening a window in the users browser

Use navigateToURL if you want to open a window in the users browser. For example:

 navigateToURL(new URLRequest("http://www.lazysquirrelgames.com"),  
"_blank");


Adobe documentation:
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLRequest.html

Sunday, October 25, 2009

AS3: Customizing the preloader

By default Flash player displays a simple bar for loading progress. A little code snippet at http://www.flexdeveloper.eu/forums/actionscript-3-0/download-progress-bar-(downloadprogressbar)/ shows how to start modifying this initial screen. The code does not generate anything pretty but is a good start towards understanding what needs to be done.

The relevant adobe documents:
http://livedocs.adobe.com/flex/3/html/help.html?content=app_container_4.html
http://livedocs.adobe.com/flex/3/langref/mx/preloaders/DownloadProgressBar.html

Thursday, October 22, 2009

AS3: Latency aka delay in playing sound

Encountered a problem where I am trying to play short sounds in response to key presses and noticing a considerable delay. Googling for stuff other people seem to have encountered it. Need to test the swf on a windows box to see if what I am seeing is specific to my Linux box.

Some usefull threads on this:


http://stackoverflow.com/questions/227674?sort=oldest#sort-top

This thread indicates it may be specific to Pulseaudio: http://ubuntuforums.org/archive/index.php/t-1146361.html

No solution here but describes the problem well: http://forums.tigsource.com/index.php?topic=7927.0;wap2

EDIT: So tested this on windows XP, the lag still exist but is small enough that I can work around it.

Monday, October 12, 2009

Flex/AS3 :: Flash player debug version for Linux

Remember to use the debug flash player for Linux. There is a tarball on the adobe download page.

The standalone player is great for debugging and lets us leave our browsers flash player alone.

Thursday, October 8, 2009

AS3: Data binding is useful

Data binding is a useful and powerful concept. Its easy to do in Flex, AS3 is more complicated, the adobe docs help:

Adobe livedoc link.

Wednesday, October 7, 2009

AS3: Alpha for Sprite that has children

This one caught me out. I was wondering why I could not change the alpha of a bitmap that I had added as a child of a Sprite. Consider this code block:
var my_sprite:Sprite = new Sprite();

my_sprite.graphics.beginFill(0x000000);
my_sprite.graphics.lineStyle(1, 0x111111, 1, false,
"normal", null, null, 3);
my_sprite.graphics.drawRect(0, 0, 400, 500);
my_sprite.graphics.endFill();
my_sprite.alpha = 0.3; // This is not correct. Will affect all children

stage.addChild(my_sprite);

my_sprite.addChild(my_bitmap); // Some valid bitmap

my_bitmap.alpha = 1; // Does not work.
What I expected was that the sprite would be translucent and my bitmap would be solid. However I found the bitmap taking on the alpha of the sprite. The reason for that was I should not have been trying to change the Sprite's alpha rather I needed to use the alpha parameter of the beginFill call. So the correct code would be:
var my_sprite:Sprite = new Sprite();

my_sprite.graphics.beginFill(0x000000, 0.3); // Alpha of 0.3 for the fill
my_sprite.graphics.lineStyle(1, 0x111111, 1, false,
"normal", null, null, 3);
my_sprite.graphics.drawRect(0, 0, 400, 500);
my_sprite.graphics.endFill();

stage.addChild(my_sprite);

my_sprite.addChild(my_bitmap); // Some valid bitmap

my_bitmap.alpha = 1; // This will work now