— React-Native Programmierer . Patrick Tresp

1023_1 – PhidgetRFID
Quelle: http://www.phidgets.com

As developing RIA is the focus of my work, sometimes it is nice to play around with some hardware programming or at least do some programming to control hardware.
Last time i did this is like 15 years ago and the result was to get a light bulb shining. Still think it is a little wonder 🙂

While searching a little bit, i did order this 1023_1 – PhidgetRFID, to read RFID Tags. http://www.phidgets.com/products.php?product_id=1023_1
My first weapon of choice is ActionScript 3.0 and i was surprised how easy this is to handle.

I used to be a person that does not read the manual – now i am 🙂
Sometimes its just easier to search for a solution while it is documented very well, e.g. for exact this device : http://www.phidgets.com/docs/1023_User_Guide

If using Phidget the first time, a look at the Phidget Control Panel helps ( Windows and OSX explained seperatly ) http://www.phidgets.com/docs/Phidget_Control_Panel

If connected properly, Coding might start.

Since it is really self-explaining, i won’t go through the code.

For now, the Actionscript Library is packed in some Examples which show already how to use phidgets API, which is located here with also a lot of documents for help: http://www.phidgets.com/docs/Language_-_Flash_AS3

* @author Patrick Tresp
* @see patricktresp.de | blog.patricktresp.de
import flash.text.TextFormat;
import flash.text.TextField;
import flash.display.Shape;
import com.phidgets.PhidgetRFID;
import com.phidgets.events.PhidgetDataEvent;
import com.phidgets.events.PhidgetErrorEvent;
import com.phidgets.events.PhidgetEvent;
import flash.display.Sprite;
* @author ptresp
public class PhidgetRFIDReader extends Sprite
private static const HOST : String = "localhost";
private static const PORT : uint = 5001;
private static const PASSWORD : String;
private var _phidgetRFID : PhidgetRFID;
public function PhidgetRFIDReader()
private function construct() : void
var phidgedRFID : PhidgetRFID = _phidgetRFID = new PhidgetRFID();
phidgedRFID.addEventListener( PhidgetEvent.DETACH, attachDetachHandler );
phidgedRFID.addEventListener( PhidgetEvent.ATTACH, attachDetachHandler );
phidgedRFID.addEventListener( PhidgetErrorEvent.ERROR, errorHandler );
phidgedRFID.addEventListener( PhidgetDataEvent.TAG, tagHandler );
phidgedRFID.addEventListener( PhidgetDataEvent.TAG_LOST, tagHandler );
phidgedRFID.open( HOST, PORT, PASSWORD );
private function attachDetachHandler( event : PhidgetEvent ) : void
switch( event.type )
case PhidgetEvent.ATTACH:
trace( "PhidgetRFIDReader.attachDetachHandler(event) PhidgetEvent.ATTACH" );
_phidgetRFID.Antenna = true;
_phidgetRFID.LED = true;
case PhidgetEvent.DETACH:
_phidgetRFID.Antenna = false;
_phidgetRFID.LED = false;
trace( "PhidgetRFIDReader.attachDetachHandler(event) PhidgetEvent.DETACH" );
private function errorHandler( event : PhidgetErrorEvent ) : void
trace( "PhidgetRFIDReader.errorHandler(event)", event.type, event.Error );
private function tagHandler( event : PhidgetDataEvent ) : void
switch( event.type )
case PhidgetDataEvent.TAG:
trace( "PhidgetRFIDReader.tagHandler(event) PhidgetDataEvent.TAG", event.Data );
displayStatus( true, String( event.Data ) );
case PhidgetDataEvent.TAG_LOST:
trace( "PhidgetRFIDReader.tagHandler(event) PhidgetDataEvent.LOST", event.Data );
displayStatus( false, String( event.Data ) );
private function displayStatus( connected : Boolean, RFIDTag : String ) : void
while ( numChildren > 0 ) removeChildAt( 0 );
if ( RFIDTag !== "0/" )
var color : uint,s : Shape, tf : TextField , format : TextFormat, text : String;
color = connected ? 0x1B3A00 : 0x660000;
s = new Shape();
s.graphics.beginFill( color );
s.graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
addChild( s );
text = RFIDTag + " ";
text += connected ? "found" : "lost";
format = new TextFormat();
format.font = "Arial";
format.size = 24;
format.color = 0xFFFFFF;
tf = new TextField();
tf.width = stage.stageWidth - 40;
tf.x = tf.y = 20;
tf.defaultTextFormat = format;
tf.text = text ;
addChild( tf );
Read More

While setting up an AIR Application which asks for User-Interaction by Keyboard, i was surprised, that Keyboard-Interactions are not allowed in regular Fullscreen Mode.

After looking up in the documentation i found :

stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;

This „Specifies that the Stage is in full-screen mode with keyboard interactivity enabled.“

Something i want to keep in mind, since FullScreen did not mean „no interactions by keyboard“ to me!


Read More

During a Project i needed a method which shuffles a Vector. Since i could not find an implemented shuffle() function i remembered how PHP works with sort-functions and came up with this really simple comparison function:

package de.patricktresp.util
	 * @author patricktresp
	public class VectorUtil
		public static function shuffleVector( a : Object, b : Object ) : int
			return Math.floor( Math.random() * 3 - 1 );

So whenever needed i just go:

vector.sort( VectorUtil.shuffleVector );

This works fine for now, but i am very sure there is some more efficient and faster methods.

Suggestions are appreciated.

Read More

Another FFK ( Flash Forum Konferenz ) / beyondtellerrand has passed and left me with new inspirations on how i want to work on and what i want to work on in the future.

Find some interesting Ressources here:




The conference hat obviously more topics than listet before but these are the resources i will need to use in the future.

I am very curious, how molehill will affect the complete Flash importance in the web.

Thanks FFK11!

Read More

When having an external SWF file which needs to be tweened in frames ( e.g. multiple buttons to control the position of swf file ) it always throws performance issues while tweening a frame which is before the current frame ( meaning: reverse tweens ).

After some research i thankfully found following way to force a tween to play forward and loop to reach the desired frame. ( e.g. movie with totalframes 100 is at frame 50, button action: tween to frame 10 )

I was really glad i found this!

TweenLite is downloadable at : http://www.greensock.com/

// header
import com.greensock.TweenLite;
import com.greensock.plugins.*;
// function
TweenPlugin.activate( [ FramePlugin ] );
TweenPlugin.activate( [ FrameForwardPlugin ] );
var frameForward : uint = 10;
var time: Number = 1;
var _animation : Sprite = getChildByname("animation");
TweenLite.to( _animation, time, { frameForward:targetFrame, ease:"easeInOutExpo" } );
Read More

During a Project which had to handle large amounts of BitmapData-Objects i had problems in displaying dynamically created TextFields in the DisplayList. TextFields were not visible on stage, even though the properties were all correct.

Surpisingly i could add other Bitmap-Objects, which are displayed correct, so i used this workaround:

// note: Application.getInstance().getTextFieldTextBounds( textField ) returns the correct amount of space taken from the textField according to http://blog.derraab.com/2010/05/16/aligning-flash-textfield-instances-visually-correct/
// create new BitmapData Object using the TextFields bounds and use alpha values
var bm : BitmapData = new BitmapData( Application.getInstance().getTextFieldTextBounds( tf ).width + 20, Application.getInstance().getTextFieldTextBounds( tf ).height + 20, true, 0x00000000 );
// take a SnapShot of the TextField
bm.draw( tf );
// create new Bitmap Object
var bitmap : Bitmap = new Bitmap( bm );
bitmap.x = tf.x;
bitmap.y = tf.y;
// deleting the reference TextField
tf = null;
// adding new Bitmap to a Sprite
s.addChild( bitmap );
Read More

Just a try to use WP-Syntax available at the Plugins page…

ActionScript Code Snippet Test

public static function getSquareButton( width : uint, height : uint, color : uint ) : Sprite
	var s : Sprite = new Sprite();
	s.graphics.beginFill( color );
	s.graphics.drawRect( 0, 0, width, height );
	return s;
Read More