flex4 -- 如何自动生成get和set方法,以及使用
参考文章:?http://www.voidcn.com/article/p-tmjdntwl-zt.html 1、如何自动生成 选择你的变量-->单击右键-->源代码-->生成Getter/Setter-->如图 2、如何使用: package { ? ? ? import flash.display.Sprite; ? ? ? import flash.events.MouseEvent; ? ? ? ?? ?? ? ? public class Player extends Sprite ? ? ? { ? ? ? ? ? ?? ? ? ? ? private var _test:String ; // Flex4.5 可以自动帮你 get ?set方法 ? ? ? ? ??? ? ? ? ? //之后调用都为该方法~~~ ?类似普通字段调用 ? ? ? ? ? public function get test():String ? ? ? ? ? { ? ? ? ? ? ? ? return _test; ? ? ? ? ? } ? ?? ? ? ? ? public function set test(value:String):void ? ? ? ? ? { ? ? ? ? ? ? ? _test = value; ? ? ? ? ? } ? ?? ? ? } ? ? ? ? ? ?? } ? <?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="155" minHeight="200" ? ? ? ? ? ? ? ? ?initialize="application1_initializeHandler(event)" ? ? ? ? ? ? ? ? ?> ? ? ? <fx:Script> ? ? ? ? ? <![CDATA[? ? ? ? ? ? ? import com._test.player.Player;? ? ? ? ? ? ? ? ? ? ? ? ? ? import mx.controls.Alert;? ? ? ? ? ? ? import mx.events.FlexEvent;? ? ? ? ? ? ? ? ? ? ? ? ? ? private var p:Player ;? ? ? ? ? ? ? protected function application1_initializeHandler(event:FlexEvent):void? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? // TODO Auto-generated method stub? ? ? ? ? ? ? ? ? p = new Player();? ? ? ? ? ? ? ? ? p.test = "hello";//调用? ? ? ? ? ? ? ? ? Alert.show(p.test);? ? ? ? ? ? ? } ? ?? ? ? ? ? ]]> ? ? ? </fx:Script> ? ? ? <fx:Declarations> ? ? ? ? ? <!-- Place non-visual elements (e.g.,services,value objects) here --> ? ? ? </fx:Declarations> ? </s:Application> ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |