13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Basics of user interaction<br />

square.y = startY;<br />

square.tabEnabled = true;<br />

square.tabIndex = tabNumber;<br />

square.addEv<strong>en</strong>tList<strong>en</strong>er(FocusEv<strong>en</strong>t.FOCUS_IN, changeColor);<br />

addChild(square);<br />

}<br />

function changeColor(ev<strong>en</strong>t:FocusEv<strong>en</strong>t):void<br />

{<br />

ev<strong>en</strong>t.target.transform.colorTransform = getRandomColor();<br />

}<br />

function getRandomColor():ColorTransform<br />

{<br />

// G<strong>en</strong>erate random values for the red, gre<strong>en</strong>, and blue color channels.<br />

var red:Number = (Math.random() * 512) - 255;<br />

var gre<strong>en</strong>:Number = (Math.random() * 512) - 255;<br />

var blue:Number = (Math.random() * 512) - 255;<br />

}<br />

// Create and return a ColorTransform object with the random colors.<br />

return new ColorTransform(1, 1, 1, 1, red, gre<strong>en</strong>, blue, 0);<br />

Discovering input types<br />

Flash Player 10.1 and later, Adobe AIR 2 and later<br />

The Flash Player 10.1 and Adobe AIR 2 releases introduced the ability to test the runtime <strong>en</strong>vironm<strong>en</strong>t for support of<br />

specific input types. You can use ActionScript to test if the device on which the runtime is curr<strong>en</strong>tly deployed:<br />

Supports stylus or finger input (or no touch input at all).<br />

Has a virtual or physical keyboard for the user (or no keyboard at all).<br />

Displays a cursor (if not, th<strong>en</strong> features that are dep<strong>en</strong>d<strong>en</strong>t upon having a cursor hover over an object do not work).<br />

The input discovery ActionScript APIs include:<br />

flash.system.Capabilities.touchscre<strong>en</strong>Type property: A value provided at runtime indicating what input type is<br />

supported in the curr<strong>en</strong>t <strong>en</strong>vironm<strong>en</strong>t.<br />

flash.system.Touchscre<strong>en</strong>Type class: A class of <strong>en</strong>umeration value constants for the Capabilities.touchscre<strong>en</strong>Type<br />

property.<br />

flash.ui.Mouse.supportsCursor property: A value provided at runtime indicating if a persist<strong>en</strong>t cursor is available<br />

or not.<br />

flash.ui.Keyboard.physicalKeyboardType property: A value provided at runtime indicating if a full physical<br />

keyboard is available or a numeric keypad, only, or no keyboard at all.<br />

flash.ui.KeyboardType class: A class of <strong>en</strong>umeration value constants for the<br />

flash.ui.Keyboard.physicalKeyboardType property.<br />

flash.ui.Keyboard.hasVirtualKeyboard property: A value provided at runtime indicating if a virtual keyboard is<br />

provided to the user (either in place of a physical keyboard, or in addition to a physical keyboard).<br />

Last updated 6/6/2012<br />

557

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!