티스토리 뷰
[ Flex ][ Source ] ex04_02 : 클래스 정의 및 사용법 / ex06_01 : set get
MiniNeko 2015. 11. 29. 04:34<?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function initApp():void {
var a : Sample = new Sample();
trace(a.strId);
trace(a.strPwd);
trace(a.strName);
a.strId = "abcd";
a.strPwd = "1234";
a.strName = "이순신";
a.strTel1 = "1111"
a.strTel2 = "2222"
a.strTel3 = "3333"
a["strTel4"] = "4444"
txtDisp.text += a.strTel1 + "
";
txtDisp.text += a.strTel2 + "
";
txtDisp.text += a.strTel3 + "
";
txtDisp.text += a.strTel4 + "
";
txtDisp.text += "---------------------" + "
";
for(x = 1; x <= 4; x++) {
txtDisp.text += (a["strTel" + x.toString()]) + "
";
};
Alert.show(a["getCount"]());
trace(a.strId);
trace(a.strPwd);
trace(a.strName);
a.logIn();
a.logIn();
a.logIn();
trace("방문횟수 : " + a.getCount());
trace("카페명 : " + Sample.strCafeName);
Sample.dispCafeName();
}
]]>
</mx:Script>
<mx:TextArea id="txtDisp" x="10" y="10" width="264" height="488"/>
< /mx:Application>
--------------------------------------------------------------------------------------------------------------------------
[ Sample.as ]
package
{
public class Sample
{
import mx.controls.Alert;
public var strId : String;
public var strPwd : String;
public var strName : String;
public static var strCafeName : String = "Flex3 강좌";
private var numLogCount : Number;
public static function dispCafeName():void {
Alert.show(strCafeName);
}
private var _numLogCount : Number = 0;
public var strTel1 : String = "0";
public var strTel2 : String = "0";
public var strTel3 : String = "0";
public var strTel4 : String = "0";
private var _strAddr : String = "";
public function set srtAddr(arg1:String):void {
if(arg1 == "한국")
_strAddr = "대한민국";
else
_strAddr = arg1;
}
public function get strAddr():String {
return _strAddr;
}
public function setAddr(arg1:String):void {
_strAddr = arg1;
}
public function getAddr():String {
return _strAddr;
}
// 생성자는 무조건 public를 사용해야 한다
// Sample() 안에는 매개변수를 혼용해서 사용할수 없다.
public function Sample()
{
//TODO: implement function
strId = "아이디";
strPwd = "암호";
strName = "홍길동";
numLogCount = 0;
}
public function getCount():Number {
return numLogCount;
}
public function logIn():void {
numLogCount++;
}
}
}
--------------------------------------------------------------------------------------------------------------------------
[ ex06_01.mxml ]
< ?xml version="1.0" encoding="utf-8"?>
< mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="initApp()">
<mx:Script>
<![CDATA[
private function initApp():void {
var a:Sample = new Sample();
a.setAddr("대한민국");
trace(a.getAddr());
/* 프로퍼티 방식으로 사용 */
a.srtAddr = "한국";
trace(a.strAddr);
}
]]>
</mx:Script>
<mx:Button x="10" y="10"/>
< /mx:Application>
'Language > Flex' 카테고리의 다른 글
[ Flex ][ Source ] ex08_01 : try / catch / finally (0) | 2015.11.29 |
---|---|
[ Flex ][ Source ] ex06_02 : enterFrame 활용 (0) | 2015.11.29 |
[ Flex ][ Source ] ex03_01 : Button에 이벤트 넣기 (0) | 2015.11.29 |
[ Flex AIR ] AIR Update (0) | 2015.11.29 |
[ Flex AIR ] Air 와 swf 간에 LocalConnection 으로 통신할때 주의할 점 (0) | 2015.11.29 |