1、打开eclipse,新建一个FlashBuilder项目如下图:
2、操作如下图
上面的“Main application file”中的值应用helloworld.mxml,此处的名称新建项目时,默认与项目名称一致。
3、项目创建完成后,项目目录结构如下图:
4、打开helloworld.mxml文件
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
</s:Application>
5、输入以下代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
initialize="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
//导入包
import mx.controls.Alert;
//创建方法,当所有子组件生成完成后触发,在这个时间点还没有组件被渲染出来.
protected function init():void
{
Alert.show("Hello World");//相当于javascript中的alert("hello world");
}
]]>
</fx:Script>
</s:Application>
如下图:
运行项目:
8、得到如下效果: