Build Complex Interactions In Flash Lite



function initKeyHandler()
{
keyListener = new Object();
keyListener.onKeyDown = Delegate.create(this,onSoftKeyEvent);
Key.addListener(keyListener);
}

The initKeyHandler() Function:

Explanation: The initKeyHandler function creates a new object instance and registers it for device key events.

function onSoftKeyEvent()
{
switch(Key.getCode())
{
case ExtendedKey.SOFT1:
toolbar.show();
break;

case ExtendedKey.SOFT2:
toolbar.hide();
break;
}
}

The onSoftKeyEvent() Function:

Explanation: The onSoftKeyEvent function is a event handler for Key Events. Here we control the toolbar’s visibility on appropriate keypress.

function toolbarOpen(sender:Object)
{
txtAction.text = "Select";
}
function toolbarClose(sender:Object)
{
txtAction.text = "";
}

The toolbarOpen and toolbarClose Function:

Explanation: The above functions are handlers to the toolbar’s open and close events. We can use these to indicate to the user that tool bar requests action. For this example, we will set the label to the middle softkey (Enter) to indicate that the toolbar is open and demands user interaction.

function itemSelected(sender:Object, titleText:String, position:Number)
{
switch(position)
{
case 0:
rotateClockWise();
break;

case 1:
rotateAntiClockWise();
break;

case 2:
zoomIn();
break;

case 3:
zoomOut();
break;
}
}

The itemSelected() Function:

Explanation: The itemSelected function handles item selected interaction. So here we will check for the selected index and call upon the appropriate transformation function.

function rotateClockWise()
{
subject._rotation += 90;
}

function rotateAntiClockWise()
{
subject._rotation -= 90;
}

function zoomIn()
{
subject._xscale = subject._yscale += 10;
}

function zoomOut()
{
subject._xscale = subject._yscale -= 10;
}

Explanation: The above functions are the ones which cause transformations of our smiley movieclip, addressed by variable, subject.

Download FLA: Flash Lite – Toolbar Demo

Popularity: 28% [?]



Pages: 1 2 3


May 29, 2010  Tags: , ,   Posted in: Actionscript 2.0, Flash Lite, Mobile, Nokia, Sony Ericsson

Leave a Reply