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

Copy and paste<br />

Default behavior<br />

Adobe AIR 1.0 and later<br />

By default, AIR copies selected items in response to the copy command, which can be g<strong>en</strong>erated either by a keyboard<br />

shortcut or a context m<strong>en</strong>u. Within editable regions, AIR cuts text in response to the cut command or pastes text to<br />

the cursor or selection in response to the paste command.<br />

To prev<strong>en</strong>t the default behavior, your ev<strong>en</strong>t handler can call the prev<strong>en</strong>tDefault() method of the dispatched ev<strong>en</strong>t<br />

object.<br />

Using the clipboardData property of the ev<strong>en</strong>t object<br />

Adobe AIR 1.0 and later<br />

The clipboardData property of the ev<strong>en</strong>t object dispatched as a result of one of the copy or paste ev<strong>en</strong>ts allows you<br />

to read and write clipboard data.<br />

To write to the clipboard wh<strong>en</strong> handling a copy or cut ev<strong>en</strong>t, use the setData() method of the clipboardData object,<br />

passing in the data to copy and the MIME type:<br />

function customCopy(ev<strong>en</strong>t){<br />

ev<strong>en</strong>t.clipboardData.setData("text/plain", "A copied string.");<br />

}<br />

To access the data that is being pasted, you can use the getData() method of the clipboardData object, passing in<br />

the MIME type of the data format. The available formats are reported by the types property.<br />

function customPaste(ev<strong>en</strong>t){<br />

var pastedData = ev<strong>en</strong>t.clipboardData("text/plain");<br />

}<br />

The getData() method and the types property can only be accessed in the ev<strong>en</strong>t object dispatched by the paste<br />

ev<strong>en</strong>t.<br />

The following example illustrates how to override the default copy and paste behavior in an HTML page. The copy<br />

ev<strong>en</strong>t handler italicizes the copied text and copies it to the clipboard as HTML text. The cut ev<strong>en</strong>t handler copies the<br />

selected data to the clipboard and removes it from the docum<strong>en</strong>t. The paste handler inserts the clipboard cont<strong>en</strong>ts as<br />

HTML and styles the insertion as bold text.<br />

Last updated 6/6/2012<br />

597

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

Saved successfully!

Ooh no, something went wrong!