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 />

Managing focus<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

An interactive object can receive focus, either programmatically or through a user action. Additionally, if the<br />

tabEnabled property is set to true, the user can pass focus from one object to another by pressing the Tab key. Note<br />

that the tabEnabled value is false by default, except in the following cases:<br />

For a SimpleButton object, the value is true.<br />

For a input text field, the value is true.<br />

For a Sprite or MovieClip object with buttonMode set to true, the value is true.<br />

In each of these situations, you can add a list<strong>en</strong>er for FocusEv<strong>en</strong>t.FOCUS_IN or FocusEv<strong>en</strong>t.FOCUS_OUT to provide<br />

additional behavior wh<strong>en</strong> focus changes. This is particularly useful for text fields and forms, but can also be used on<br />

sprites, movie clips, or any object that inherits from the InteractiveObject class. The following example shows how to<br />

<strong>en</strong>able focus cycling with the Tab key and how to respond to the subsequ<strong>en</strong>t focus ev<strong>en</strong>t. In this case, each square<br />

changes color as it receives focus.<br />

Note: Flash Professional uses keyboard shortcuts to manage focus; therefore, to properly simulate focus managem<strong>en</strong>t,<br />

SWF files should be tested in a browser or AIR rather than within Flash.<br />

var rows:uint = 10;<br />

var cols:uint = 10;<br />

var rowSpacing:uint = 25;<br />

var colSpacing:uint = 25;<br />

var i:uint;<br />

var j:uint;<br />

for (i = 0; i < rows; i++)<br />

{<br />

for (j = 0; j < cols; j++)<br />

{<br />

createSquare(j * colSpacing, i * rowSpacing, (i * cols) + j);<br />

}<br />

}<br />

function createSquare(startX:Number, startY:Number, tabNumber:uint):void<br />

{<br />

var square:Sprite = new Sprite();<br />

square.graphics.beginFill(0x000000);<br />

square.graphics.drawRect(0, 0, colSpacing, rowSpacing);<br />

square.graphics.<strong>en</strong>dFill();<br />

square.x = startX;<br />

Last updated 6/6/2012<br />

556

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

Saved successfully!

Ooh no, something went wrong!