[Flex mobile] Alert창 띄우기 Flex Mobile




<?xml version="1.0" encoding="utf-8"?>
<s:SkinnablePopUpContainer xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark"
  xmlns:itemrenderer="com.adobe.mobilecrud.view.itemrenderer.*"
  backgroundAlpha="0" creationComplete="CenterPopUp()">
<fx:Script>
<![CDATA[

import mx.core.FlexGlobals;
import mx.events.CloseEvent;
import spark.events.PopUpEvent;
private static var YES:String = 'yes';
private static var NO:String = 'no';
public function get Yes():String{
return YES;
}
public function get No():String{
return NO;
}
public function show(text:String = '',title:String = '', closeHandler:Function = null):void{
this.open(FlexGlobals.topLevelApplication as DisplayObjectContainer,true);
if(closeHandler != null){
this.addEventListener(PopUpEvent.CLOSE,closeHandler);
btnOk.addEventListener(MouseEvent.CLICK,btnClose_clickHandler);
btnCancel.visible = true;
btnCancel.includeInLayout = true;
}else{
btnOk.addEventListener(MouseEvent.CLICK,btnClose_clickHandler);
}
this.title.text = title;
text_main.text = text;
}
private function CenterPopUp():void{
this.x = FlexGlobals.topLevelApplication.width / 2 - this.width / 2;
this.y = FlexGlobals.topLevelApplication.height / 2 - this.height / 2;
}
protected function btnClose_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
if(event.currentTarget.id == 'btnOk'){
this.close(true,YES);
}else{
this.close(true,NO);
}
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Rect width="100%" height="100%" radiusX="10" radiusY="10">
<s:stroke>
<s:SolidColorStroke color="haloBlue" weight="2"/>
</s:stroke>
<s:fill>
<s:SolidColor color="white" />
</s:fill>
</s:Rect>
<s:VGroup width="100%" height="100%" bottom="10" right="1" gap="0">
<s:Group width="100%">
<s:Rect width="100%" height="50" left="1" right="1" top="1">
<s:fill>
<s:LinearGradient>
<s:entries>
<s:GradientEntry color="0xf6f6f6" ratio="0.00" alpha="0.5" />
<s:GradientEntry color="0x04b6f1" ratio="0.50" alpha="0.5"/>
</s:entries>
</s:LinearGradient>
</s:fill>
</s:Rect>
<s:Label id="title" text="" verticalCenter="0" horizontalCenter="0"/>
</s:Group>
<s:Line width="100%">
<s:stroke>
<s:LinearGradientStroke caps="round" weight="1">
<s:entries>
<s:GradientEntry color="red" ratio="0.5" alpha="0.5"/>
<s:GradientEntry color="black" ratio="0.5" alpha="0.5"/>
</s:entries>
</s:LinearGradientStroke>
</s:stroke>
</s:Line>
<s:TextArea id="text_main" width="100%" maxHeight="300" textAlign="center" editable="false" 
fontSize="16" contentBackgroundAlpha="0" borderVisible="false" />
<s:HGroup width="100%" horizontalAlign="center">
<s:Button id="btnOk" label="확인" width="80" height="34" fontSize="18" skinClass="spark.skins.spark.ButtonSkin"/>
<s:Button id="btnCancel" label="취소" width="80" height="34" fontSize="18"
 visible="false" includeInLayout="false" click="btnClose_clickHandler(event)" skinClass="spark.skins.spark.ButtonSkin"/>
</s:HGroup>
</s:VGroup>
</s:SkinnablePopUpContainer>


디자인 신경 안쓰고 로직만 구현 하였습니다.(디자인 너무약해서..)



사용 방법은 alert.show('Alert창입니다.','알림',null or Function) 
null일경우 확인 버튼만 나오고 Function 있을경우 확인 버튼과 취소 버튼이 보입니다.

덧글

댓글 입력 영역