Apr 01
接下来的例子演示了如何利用<mx:Style>标签,将一个PNG的图标嵌入到Flex应用的按钮(Button)中。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">
- <mx:Style>
- /* This style applies to all Buttons, including those in Alert controls. */
- Button {
- icon: Embed(source="assets/bulletCheck.png");
- }
- /* Create a custom style class. */
- .bulletWarning {
- icon: Embed(source="assets/bulletWarning.png");
- }
- </mx:Style>
- <mx:Script>
- <![CDATA[
- import mx.controls.Alert;
- private var a:Alert;
- private function showAlert():void {
- a = Alert.show("message");
- }
- ]]>
- </mx:Script>
- <mx:Button label="bug" />
- <mx:Button label="also a bug"/>
- <mx:Button label="Alert.show()" click="showAlert()" styleName="bulletWarning" />
- </mx:Application>
