Pay for Hesitation: MXML中使用ActionScript的方式

Pages

2008年3月13日 星期四

MXML中使用ActionScript的方式

補昨天下午的...orz..

在MXML中使用ActionScript有下列四種方式:
• Inline within MXML tags
• Nested within MXML tags
• In MXML scripts
• Within ActionScript classes


Inline ActionScript
=======================================================
<mx:Button id="alertButton" label="Show Alert"
click="mx.controls.Alert.show('Example')" />
=======================================================
<mx:VBox>
<mx:TextInput id="input" />
<mx:Text id="output" text="{input.text}" />
</mx:VBox>
=======================================================
<mx:VBox>
<mx:TextInput id="input" />
<mx:Text id="output" text="{'User input: ' + input.text}" />
</mx:VBox>
=======================================================
<mx:Button id="alertButton" label="Show Alert" click="mx.controls.Alert.
show('Example');alertButton.x += 40;" />
=======================================================


Nested ActionScript
=======================================================
<mx:Button>
<mx:click>
<![CDATA[
mx.controls.Alert.show("Example");
]]>
</mx:click>
</mx:Button>
=======================================================


MXML Scripts
=======================================================
我們熟悉的用法
<mx:Script>

<![CDATA[

import mx.controls.Alert;

private function example( ):void {

Alert.show("Example");

}

]]>

</mx:Script>
=======================================================


引用外部as檔
=======================================================
<mx:Script source="code.as" />


以上來自Oreilly的Programming Felx 2.0 p83~0.86


沒有留言: