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

Keyboard input<br />

private function onKey( ev<strong>en</strong>t:KeyboardEv<strong>en</strong>t ):void<br />

{<br />

textElem<strong>en</strong>t.replaceText( textElem<strong>en</strong>t.text.l<strong>en</strong>gth, textElem<strong>en</strong>t.text.l<strong>en</strong>gth,<br />

String.fromCharCode( ev<strong>en</strong>t.charCode ) );<br />

updateText();<br />

}<br />

public function set bounds( newBounds:Rectangle ):void<br />

{<br />

_bounds = newBounds.clone();<br />

drawBackground();<br />

updateText();<br />

this.scrollRect = _bounds;<br />

}<br />

//force update to focus rect, if needed<br />

if( this.stage!= null && this.focusRect && this.stage.focus == this )<br />

this.stage.focus = this;<br />

private function updateText():void<br />

{<br />

//clear text lines<br />

while( this.numChildr<strong>en</strong> > 0 ) this.removeChildAt( 0 );<br />

}<br />

//and recreate them<br />

var textLine:TextLine = textBlock.createTextLine( null, _bounds.width - 8);<br />

while ( textLine)<br />

{<br />

textLine.x = 4;<br />

if( textLine.previousLine != null )<br />

{<br />

textLine.y = textLine.previousLine.y +<br />

textLine.previousLine.totalHeight + 2;<br />

}<br />

else<br />

{<br />

textLine.y = 4 + textLine.totalHeight;<br />

}<br />

this.addChild(textLine);<br />

textLine = textBlock.createTextLine(textLine, _bounds.width - 8 );<br />

}<br />

private function drawBackground():void<br />

{<br />

//draw background and border for the field<br />

this.graphics.clear();<br />

this.graphics.beginFill( 0xededed );<br />

this.graphics.lineStyle( 1, 0x000000 );<br />

this.graphics.drawRect( _bounds.x + 2, _bounds.y + 2, _bounds.width - 4,<br />

_bounds.height - 4);<br />

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

}<br />

}<br />

}<br />

Last updated 6/6/2012<br />

570

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

Saved successfully!

Ooh no, something went wrong!