接触flex有几天了,从一些零零星星的资料上了解了一些flex的东西。一直以来都想利用一个onload啊,或者init啊的事件,来管理初始化的时候需要注册的事件。一直也没有找到类似onload的事件。今天看flash官方网站的文章,居然就有方法,呵呵,做了个demo,源代码如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
creationComplete="applicationCreationCompleateHandle(event)"
fontSize="12" xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="308" height="160"
backgroundGradientColors="[#ffffff, #ffffff]"
backgroundGradientAlphas="[1.0, 1.0]">
<!--Script-->
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
private function applicationCreationCompleateHandle(event:FlexEvent):void
{
btnTest.addEventListener(MouseEvent.CLICK,btnTestClickHandle);
}
private function btnTestClickHandle(event:MouseEvent):void
{
btnTest.label = "我就是按钮啊~~ :)";
}
]]>
</mx:Script>
<!--UI-->
<mx:Panel
title="测试实例--事件注册"
x="30" y="17"
width="248"
height="130"
layout="horizontal"
horizontalAlign="center" verticalAlign="middle">
<mx:Button
id="btnTest"
x="72"
y="33"
label="点击这里"
labelPlacement="right">
</mx:Button>
</mx:Panel>
</mx:Application>
联系客服