Showing posts with label air. Show all posts
Showing posts with label air. Show all posts

Friday, December 19, 2014

#AS3 KeyboardHandler

(i've posted this as a comment in Starling bug report from a user)

for performance crucial sections such as keyboard interaction i would not use anything but callbacks.
the flash event system, and the alternatives such as signals are nice for higher level management, but they can't really beat callbacks for performance. what Starling does with the enhanced events is also fast, but here is my point.
the virtual machine and the garbage collector already provide you with the flexibility of one of the core features - everything is an Object including Function.
"functors" or function pointers is something that even languages like C++ don't handle that well, so you really should take advantage of this low level, yet still high level feature.
since the only way in flash to see if a key is pressed is via the KeyboardEvent, use that and build a callback system on top of it. only maintain the stage events and propagate manually not display objects but rather objects of interest.
check this concept i wrote quickly:
  • KeyboardHandler is a state machine that tracks keyboard isDown states for a keyCode and calls your registered callback.
  • it uses the native stage
  • it's super fast
  • it's worker safe
  • you can stop it at any time using "enabled = false"
  • it does call event.preventDefault(), event.stopImmediatePropagation(), but you can mod that yourself or simply call "enabled = false" when needed.
  • once a key is down it no longer registers as down until it up, this forces you to write your key logic smart.
  • if you don't track a key state yourself (which would be faster) at any time you can call supportedKeyIsDown(...) to see if a key is currently down. this allows easy checks for key combinations e.g ALT + SHIFT + LEFT.

Tuesday, September 10, 2013

#flash cs6 compiler bug

i have to work with tools like the one mentioned in the title. here is a bug that only happens if you assign code to a frame in the (main) timeline. target version is 12.0.0.481 and could be fixed in later interations.

you can try the following:
// Array can be used here instead, for 'list'
var list:Vector.<String> = Vector.<String>(["hello", "world"]);
trace(list); // hello,world
var vlen:uint = list.length;
trace(vlen); // 2
const clen:uint = vlen; // this works but 'vlen' is zero at this point
trace(clen); // 0
const len:uint = list.length; // list is a null object reference

results in:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline()

what happens here is that the as3 compiler tries to play smart and traverses for 'const' declarations, and once it finds 'len' it decided to assign a value to the address where it will be stored in the 'constant pool' and then to be referenced by bytecode. but since 'list' is not a 'const' declaration itself the object is simply not constructed yet and 'list' is a null reference.


same does not happen if:

- 'const list:...' is used, but one may not want that
- if the same code is written in an external document class instead on the timeline

if this is by design it may cause compatibility issues with class written code and simply confuse developers. after all, constant declarations after variable declarations should make perfect sense. in general, i wouldn't recommend writing anything more important on timeline frames, but use classes with ENTER_FRAME listeners or attempt to use addFrameScript() on MovieClip instances instead.
--

Monday, January 28, 2013

#starling framework video tutorials

here are a nice set of video tutorials by +Hemanth Sharma to get you started with the starling framework:
http://youtu.be/RTvhZ8wbJaQ

if you don't use proprietary software like "flex builder", mind that you can set everything on the command line using the flex tools "mxmlc", "adl", "adb". i'm sure there are examples on how to do that online. flex is open source as is now maintained by the "apache software foundation".

--

Thursday, August 23, 2012

#threading and concurrency in flash player 11.4

the new flash player (as of 11.4) apparently now supports threads (and concurrency), exposed to the API via the Worker* / MessageChannel family of classes. the approach they took is actually similar to channels in GO, which is nice.

API examples:
Worker class

one slight inconvenience is that each time a worker / thread is created it has to exist in a separate SWF (ByteArray). this can be avoided if the actual SWF is created/loaded in/from memory.

a cool new feature, but it might be a little bit delayed in comparison to lets say Java, which became C/C++ like syntax multithreaded / "API exposed", i believe, since 1996 with JDK 1.0.

--

Sunday, September 18, 2011

#newer adobe air no longer supports linux

adobe air 2.7 was released around june this year and while it improves speed for android and ios, there are no runtimes for linux desktops. the last ones are version 2.6.

here is the main reason:

Adobe attributes this to the fact that a relatively few 0.5% of downloads of Adobe AIR were for Linux. This makes Adobe AIR 2.6 the last version of AIR to be available for Linux.
from a more detailed post on the subject.

the decision itself may be a bit questionable, but i wonder how much of a time investment would it be to update / maintain the linux runtimes (and sdk).
cross platform developers that target some of those 0.5% will now have to consider using the 2.6 sdk.

--