自己第一個flex作品

<?xml version="1.0"?>
<Application xmlns="http://www.adobe.com/2006/mxml"
        backgroundColor="white" fontSize="12" creationComplete="initApp()" layout="absolute" xmlns:objecthandles="com.roguedevelopment.objecthandles.*"
       width="700" height="450" cornerRadius="2" backgroundGradientAlphas="[0.78, 0.78]">
    <Style>
        Canvas{
   font-family:EmbeddedBase01;
        }
        Alert{
            background-color:#eeafff;
            alternating-item-colors:red;
            background-image:Embed(source='image/30.jpg');
            stroke-color:#FFFFFF;
           
        }
        .customButton {
            color:#FFFFFF;
            text-roll-over-color:#FFFFBB;
            text-selected-color:#9999FF;
            disabled-color:#333333;
            up-skin:Embed(
               source="image/6.jpg",
               scaleGridTop="1",
               scaleGridBottom="2",
               scaleGridLeft="1",
               scaleGridRight="2");
            over-skin:Embed(
               source="image/5.jpg",
               scaleGridTop="1",
               scaleGridBottom="2",
               scaleGridLeft="1",
               scaleGridRight="2");
            down-skin:Embed(
               source="image/6.jpg",
               scaleGridTop="1",
               scaleGridBottom="2",
               scaleGridLeft="1",
               scaleGridRight="2");
            disabled-skin:Embed(
               source="image/7.jpg",
               scaleGridTop="1",
               scaleGridBottom="2",
               scaleGridLeft="1",
               scaleGridRight="2");
            }
    </Style>
    <Script>
        <![CDATA[
         import com.adobe.serialization.json.JSON;
         import mx.core.UITextField;
         import mx.controls.Label;
         import mx.messaging.AbstractConsumer;
         import mx.automation.delegates.controls.TextInputAutomationImpl;
         import mx.events.ListEvent;
         import flash.events.TextEvent;
         import mx.containers.Panel;
     import mx.events.ColorPickerEvent;
      import mx.controls.Alert;
     import flash.events.MouseEvent;
      import mx.events.NumericStepperEvent;
      import mx.events.MoveEvent;
      import mx.controls.TextArea;
      import mx.controls.Label;
      import flash.external.*;
    internal function initApp():void{
       //設置粗體与I
       btnB.addEventListener(MouseEvent.CLICK,doClickB);
       btnI.addEventListener(MouseEvent.CLICK,doClickI);
       btnU.addEventListener(MouseEvent.CLICK,doClickU);
       btnL.addEventListener(MouseEvent.CLICK,doClickL);
       btnR.addEventListener(MouseEvent.CLICK,doClickR);
       btnC.addEventListener(MouseEvent.CLICK,doClickC);
       colorStype1.addEventListener(MouseEvent.CLICK,doClickSetColor1);
       colorStype2.addEventListener(MouseEvent.CLICK,doClickSetColor2);
       colorStype3.addEventListener(MouseEvent.CLICK,doClickSetColor3);
       colorStype4.addEventListener(MouseEvent.CLICK,doClickSetColor4);
       colorStype5.addEventListener(MouseEvent.CLICK,doClickSetColor5);
       colorStype6.addEventListener(MouseEvent.CLICK,doClickSetColor6);
       colorStype7.addEventListener(MouseEvent.CLICK,doClickSetColor7);
       //供外部調用的事件
       ExternalInterface.addCallback("setSizeImageFlex",setSizeImage);
       //調用javaScript中的方法獲取所需的信息
       //獲取圖片
       //AddImage();
       //獲取Label
       GetAllLabel();
      }
      //獲取以存儲Label
      private function GetAllLabel():void{
       var f:String = "GetAllLabels";//外部javascript方法
    var arry:Array=JSON.decode(ExternalInterface.call(f));//傳遞參數並接受參數
       //調用回綁方法
    GoBackAllLabel(arry);
      }
      //回綁label標籤
      private function GoBackAllLabel(arry:Array):void{
       //遍歷中所有的Label
       if(arry!=null){
        Alert.show("arry!=null");
        for each(var label:objectmodel in arry){
                var ob:ObjectHandles=new ObjectHandles();
                var labelModel:Label=new Label();
                labelModel.x=label.x;
                labelModel.y=label.y;
                labelModel.width=label.width;
                labelModel.height=label.height;
                labelModel.setStyle("fontSize",label.fontSize);
                labelModel.setStyle("fontFamily",label.fontStyle);
                labelModel.text=label.text;
                //顯示原來的label
       ob.addChild(labelModel);
       ob.addEventListener(ResizeEvent.RESIZE,setChildWidth);         
       canvas.addChild(ob);
        }
       }
       
      }
      //設置粗體
      internal function doClickB(evt:MouseEvent):void{
        switch (lab_Name.getStyle("fontFamily")) {
     case "EmbeddedBase04B":
                        lab_Name.setStyle("fontFamily","EmbeddedBase04");
                        break;
     case "EmbeddedBase04":
                        lab_Name.setStyle("fontFamily","EmbeddedBase04B");
                        break;   
                }
      }
      //設置斜體
      internal function doClickI(evt:MouseEvent):void{
         if(lab_Name.getStyle("fontStyle")=="italic")
         {
         lab_Name.setStyle("fontStyle","normal");
         }
        else{
         lab_Name.setStyle("fontStyle","italic");
        }
      }
      //是否有下劃線
      internal function doClickU(evt:MouseEvent):void{
       if(lab_Name.getStyle("textDecoration")=="none")
         {
         lab_Name.setStyle("textDecoration","underline");
         }
        else{
         lab_Name.setStyle("textDecoration","none");
        }
      }
      //是否居左
      internal function doClickL(evt:MouseEvent):void{
         lab_Name.setStyle("textAlign","left");
      }
      //是否居右
      internal function doClickR(evt:MouseEvent):void{
         lab_Name.setStyle("textAlign","right");
      }
      //是否居中
      internal function doClickC(evt:MouseEvent):void{
         lab_Name.setStyle("textAlign","center");
      }
      //設置字體
   [Embed(source="font/trebuc.TTF",
                    fontName="EmbeddedBase01",
                    mimeType="application/x-font")]
            private var EmbeddedBase01:Class;
            [Embed(source="font/Discipuli Britannica Bold.ttf",
                    fontName="EmbeddedBase04B",
                    mimeType="application/x-font")]
            private var EmbeddedBase04B:Class;
            [Embed(source="font/youarewhatyoueat.ttf",
                    fontName="EmbeddedBase02",
                    mimeType="application/x-font")]
            private var EmbeddedBase02:Class;
            [Embed(source="font/verdana.TTF",
                    fontName="EmbeddedBase03",
                    mimeType="application/x-font")]
            private var EmbeddedBase03:Class;
            [Embed(source="font/Discipuli Britannica.ttf",
                    fontName="EmbeddedBase04",
                    mimeType="application/x-font")]
            private var EmbeddedBase04:Class;
      //設置背景圖
      [Embed(source="image/30.jpg")]
      [Bindable]
            private var Image:String;
            //字體改變事件
            private function comboBox_change(evt:ListEvent):void {
                var fontName:String = comboBox.selectedItem.toString();
                lab_Name.setStyle("fontFamily", fontName);
                lab.setStyle("fontFamily", fontName);
            }
            //顏色改變處理
            private function colorPic_Change(evt:ColorPickerEvent):void {
                var fontColor:String =colorPic.selectedItem.toString();
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
            //設置顏色
            internal function doClickSetColor1(evt:MouseEvent):void
            {
             var fontColor:String =colorStype1.getStyle("fillColors");
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
             internal function doClickSetColor2(evt:MouseEvent):void
            {
             var fontColor:String =colorStype2.getStyle("fillColors");
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
             internal function doClickSetColor3(evt:MouseEvent):void
            {
             var fontColor:String =colorStype3.getStyle("fillColors");
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
             internal function doClickSetColor4(evt:MouseEvent):void
            {
             var fontColor:String =colorStype4.getStyle("fillColors");
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
             internal function doClickSetColor5(evt:MouseEvent):void
            {
             var fontColor:String =colorStype5.getStyle("fillColors");
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
             internal function doClickSetColor6(evt:MouseEvent):void
            {
             var fontColor:String =colorStype6.getStyle("fillColors");
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
             internal function doClickSetColor7(evt:MouseEvent):void
            {
             var fontColor:String =colorStype7.getStyle("fillColors");
                lab_Name.setStyle("color",fontColor);
                lab.setStyle("color",fontColor);
            }
            //字體大小處理
            private function Size_Change(evt:NumericStepperEvent):void{
               var fontSize:int=numericStepper.value;
               lab_Name.setStyle("fontSize",fontSize);
               lab.setStyle("fontSize",fontSize);
            }
   public var lab_Name:Label;//聲明一個label變量
   //添加一個標籤 
   private function addSimpleTextArea(event:MouseEvent):void
   {
    var obj:ObjectHandles=new ObjectHandles();
    obj.id="Obj"+Math.ceil(Math.random()*100);
    var lab:Label=new Label();
    //砃敃怢奻氝樓偌聽 
    obj.addChild(lab);
    obj.addEventListener(ResizeEvent.RESIZE,setChildWidth);         
    canvas.addChild(obj);
    //覃淕偌聽腔弇离
    lab.x=0;
    lab.y=0;
    lab.id="lab"+Math.ceil(Math.random()*100);
    lab.text="Label";
    lab_Name=null;
   }
   //執行刪除操作
   private function DelTextArea(event:MouseEvent):void
   {
                if(lab_Name!=null){
                   showAlert();
                }else{
                   Alert.show("請先擇對象!");
                }
                lab.text="";
   }
            //角本提示
            import mx.controls.Alert;
            import mx.events.CloseEvent; 
            private var alert:Alert; 
            private function showAlert():void {
                var text:String = "你確定刪除!";
                var title:String = "標示"; 
 
                alert = Alert.show(text, title, Alert.YES | Alert.NO);
                alert.addEventListener(CloseEvent.CLOSE, alert_close); 
            } 
            private function alert_close(evt:CloseEvent):void {
                switch (evt.detail) {
                    case Alert.YES:
                        canvas.removeChild(lab_Name.parent);
                        lab_Name=null;
                        break;
                }
            }

   //褫眕扢离迍嶺湮苤
   import mx.events.ResizeEvent;
   private function setChildWidth(event:ResizeEvent):void{
                //設置寬度
          lab_Name.width=event.target.width;
   }
   //獲取當前活動的對象
   private function over(event : MouseEvent):void
   {
    lab.enabled="false";
          var x : Number = mouseX;
                var y : Number = mouseY;
                var arr : Array = getObjectsUnderPoint(new Point(x,y));
                for each (var temp : Object in arr) {
                        if(temp.parent as Label) {
                            //提取當前控件
                            lab_Name=new Label();
                            lab_Name=temp.parent as Label;
                            lab.text=lab_Name.text;
                            lab.enabled="true";
                        }
                }
   }
   
   //執行調用外部方法
   public function AddImage():void
   {
    var f:String = "GetImageURL";//外部javascript方法
    var m:String = ExternalInterface.call(f);//傳遞參數並接受參數
    //imageChange.source=m;
    canvas.setStyle("backgroundImage",m);
   }
   //設置圖片大小
   public function setSizeImage(strWidth:Number,strHeigth:Number):void
   {
          //imageChange.width=strWidth;//設置圖片的寬和高
          //imageChange.height=strHeigth;
          canvas.width=strWidth;//設置容器的寬和高
          canvas.height=strHeigth;
        
   }
   //本方法供外部javaScript調用內部信息
   public function SendDate():void
   {
    var f:String = "GetDate";//外部javascript方法此為方法名必醃要一致否則不成功!
    //讀取容器中的所有label對象
    var arry:Array=canvas.getChildren();
    var lab_Num:Label;
    var str:String="";
    if(arry!=null)
    {
     for each (var temp : Object in arry)
     {
      if(temp as ObjectHandles)
      {
        var tem:ObjectHandles=temp as ObjectHandles;
        var arryChild:Array=tem.getChildren();
        for each(var temChild : Object in arryChild){
           if(temChild as Label)
           {
           lab_Num=temChild as Label;
           //自定義一個類型
                             var labs=new objectmodel();
                             //提取當前控件
                             labs.id=lab_Num.id;
                             labs.x=lab_Num.x;
                             labs.y=lab_Num.y;
                             labs.text=lab_Num.text;
                             labs.fontStyle=lab_Num.getStyle("fontFamily");
        labs.fontSize=lab_Num.getStyle("fontSize");
        labs.color=lab_Num.getStyle("color");
        labs.isBold=lab_Num.getStyle("fontWeight")=="Bold" ? "true":"false";
                       labs.isItalic=lab_Num.getStyle("fontStyle")=="italic"? "ture":"false";
        labs.width=lab_Num.width.toString();
        labs.height=lab_Num.height.toString();
                             //進行序列化
                                str+=JSON.encode(labs);
           }
        }
      }
     }
     ExternalInterface.call(f,str);//調用js方法
    }
    else
    {
    ExternalInterface.call(f,str);//沒有控件時調用方法只不過str為空
    }
   }
        ]]>
    </Script>
       <Canvas id="canvas" backgroundImage="{Image}" width="267" height="200" x="290" y="125" horizontalScrollPolicy="auto" verticalScrollPolicy="auto" mouseDown="over(event)" maxHeight="300" maxWidth="300">
         <!-- <Image id="imageChange" source="" x="0" y="0" width="100%" height="100%"/>-->
       <objecthandles:ObjectHandles id="obb" resize="setChildWidth(event);">
    <Label id="myLabel3" text="label"/>
    </objecthandles:ObjectHandles>
       </Canvas>
       <Button x="528" y="374" label="Next Stop" click="SendDate()" width="128" height="33"/>
       <Canvas x="10" y="10" width="200" height="66" backgroundColor="#F4F1E9">
              <Button label="add Label" x="14" y="7" click="addSimpleTextArea(event);" styleName="customButton" height="25" width="171" textAlign="left"/>
              <Button label="delete Label" x="14" y="34" click="DelTextArea(event);" styleName="customButton" height="25" width="171" textAlign="left"/>
       </Canvas>
       <Canvas x="10" y="81" width="200" height="78" backgroundColor="#F4F1E9">
              <TextArea id="lab"  x="10" y="29" width="180" height="44"  change="lab_Name.text=lab.text" maxChars="100"/>
              <Label x="63.5" y="5" text="Label Text" fontWeight="bold" width="68" color="#4E1111"/>
       </Canvas>
       <Canvas x="10" y="164" width="200" height="271" backgroundColor="#F4F1E9" >
              <Label x="3" y="26" text="Choose Font" color="#F5560F"/>
              <ComboBox id="comboBox"
                      dataProvider="[EmbeddedBase01,EmbeddedBase02,EmbeddedBase03,EmbeddedBase04]"
                      change="comboBox_change(event);"  x="21" y="50" width="125"/>
              <Label x="3" y="79" text="Choose Color" color="#F45923"/>
              <Label x="7" y="165" text="Alignment" color="#F45923" height="18"/>
              <Button id="colorStype1" x="20" y="106" width="25"  cornerRadius="1" alpha="1.0" fillAlphas="[1.0, 1.0]" fillColors="#000000"/>
              <Button id="colorStype2" x="86" y="106" width="25" cornerRadius="1" alpha="1.0" fillAlphas="[1.0, 1.0]" fillColors="#990000"/>
              <Button id="colorStype3" x="119" y="106" width="25"  cornerRadius="1" alpha="1.0" fillAlphas="[1.0, 1.0]" fillColors="#CCCCCC"/>
              <Button id="colorStype4" x="53" y="106" width="25"  cornerRadius="1" alpha="1.0" fillAlphas="[1.0, 1.0]" fillColors="#003366"/>
              <Button id="colorStype5" x="20" y="138" width="25" cornerRadius="1" alpha="1.0" fillAlphas="[1.0, 1.0]" fillColors="#90b600"/>
              <Button id="colorStype6" x="53" y="138" width="25"  cornerRadius="1" alpha="1.0" fillAlphas="[1.0, 1.0]" fillColors="#472E30"/>
              <Button id="colorStype7" x="86" y="138" width="25"  cornerRadius="1" alpha="1.0" fillAlphas="[1.0, 1.0]" fillColors="#db2a99"/>
              <ColorPicker id="colorPic" change="colorPic_Change(event);" x="119" y="138" width="25" height="24"/>
              <NumericStepper id="numericStepper" width="45" change="Size_Change(event);" minimum="12" maximum="25" x="75" y="229" />
              <Button id="btnB" x="100" y="194" width="20" icon="@Embed(source='image/bold.gif')" height="22"/>
              <Button id="btnI" x="129" y="194" width="20" icon="@Embed(source='image/italic.gif')" height="22"/>
              <Button id="btnU" x="157" y="194" width="20" icon="@Embed(source='image/underline.gif')" height="22"/>
              <Button id="btnL" x="11" y="194" width="19" icon="@Embed(source='image/textalign_left.gif')" height="22"/>
              <Button id="btnC" x="38" y="194" width="19" icon="@Embed(source='image/textalign_center.gif')" height="22"/>
              <Button id="btnR" x="65" y="194" width="19" icon="@Embed(source='image/textalign_right.gif')" height="22"/>
              <Label x="10" y="233" text="Font Size" width="53" color="#4E1111"/>
              <Button x="1" y="0" label="Message Style" width="199" textAlign="left" enabled="false" color="#4E1111"/>
       </Canvas>
</Application>
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值