관리 메뉴

nkdk의 세상

AS3.0의 버튼 제어 Simple type, Standard Type 비교 본문

My Programing/ActionScript

AS3.0의 버튼 제어 Simple type, Standard Type 비교

nkdk 2008. 3. 9. 22:22


var mButton:SimpleButton = new SimpleButton();

var mUpShape:Shape = new Shape();
var mDownShape:Shape = new Shape();
var mOverShape:Shape = new Shape();
var mhitTestShape:Shape = new Shape();

mButton.overState=mOverShape;
mButton.upState=mUpShape;
mButton.downState=mDownShape;
mButton.hitTestState=mhitTestShape;

function draw(mShape:Shape, mColor:uint, mWidth:uint, mHeight:uint):void{
mShape.graphics.lineStyle(1, 0x000000, 0.6);
mShape.graphics.beginFill(mColor);
mShape.graphics.drawRect(100,100,mWidth,mHeight); // 위치 조정
mShape.graphics.endFill();
}

draw(mOverShape, 0xFFCC00, 100,30);
draw(mUpShape, 0xCCFF00, 100,30);
draw(mDownShape, 0x00CCFF, 100, 30);
draw(mhitTestShape, 0xCC00FF, 100 , 30);

stage.addChild(mButton);

// 하지만 이건 simple코딩이기 때문에 좋지 않은 코딩입니다. 버튼이 많아지면.. 곤란합니다.

그럼 이렇게 해 봅시다.

BtnSta.as

package{
import flash.display.Shape;
import flash.geom.Point;
public class BtnState extends Shape
{
private var bgColor:uint;
private var size:Point;

public function BtnState(bgColor:uint, size:Point):void
{
bgColor = bgColor;
size = size;
draw();
}

private function draw():void
{
graphics.beginFill(bgColor);
graphics.drawRect(0, 0, size.x, size.y);
graphics.endFill();
}
}
}

BtnStateTest.fla

import flash.display.Shape;
import flash.geom.Point;
import BtnState;

var mButton:SimpleButton = new SimpleButton();
var mPoint:Point = new Point(120, 50);

var mUpShape:DisplayObject = new BtnState(0xFFCC00, mPoint);
var mDownShape:DisplayObject = new BtnState(0xFF00CC, mPoint);
var mOverShape:DisplayObject = new BtnState(0xFFCCCC, mPoint);
var mhitTestShape:DisplayObject = new BtnState(0xFFCC00, mPoint);
mButton.overState = mOverShape;
mButton.downState = mDownShape;
mButton.upState = mUpShape;
mButton.hitTestState = mhitTestShape;

addChild(mButton);

여기 까지고요. 추가 적으로..

stage.addChild(child:DisplayObject):DisplayObject

stage.addChildAt(child:DisplayObject,index:int):DisplayObject

removeChild(child:DisplayObject):DisplayObject

removeChildAt(index:int):DisplayObject

getChildAt(index:int):DisplayObject // Z-Index에 해당하는 디스플레이

getChildByName(name:String):DisplayObject // 이름으로 검색후 반환

getChildIndex(child:DisplayObject):int // zIndex반환

setChildIndex(child:DisplayObject, index:int):void // 변경

swapChidren(child1:DisplayObject, Child2:DisplayObject):void // z-index 교환

numChildren // 포함된 DisplayObject객체 개수
contains(child:DisplayObject):Boolean // 컨테이너 이미 삽입된 여부확인

그 외 여러가지가 있습니다.

자 그럼 첨부되어 있는 Class Diagram 을 올리도록 하겠습니다.