Flex4学习笔记1---基本语法

Posted on 2013-07-18 15:26  诸葛小北  阅读(195)  评论(0编辑  收藏  举报
<?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="1023" minHeight="800">
    <fx:Declarations>
        <!-- 将非可视元素(例如服务、值对象)放在此处 -->
    </fx:Declarations>
    <s:Button label="我爱北京天安门" width="500" height="50">    </s:Button>
    
    <!-- 弹出框-->
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            public function handeEvent():void{
                mx.controls.Alert.show("你好厦门");                
            }
        ]]>
    </fx:Script>
    <s:Button label="点击我" click="handeEvent()" x="100" y="100"/>
    <!-- 测试代码-->
    <fx:Script>
        <![CDATA[
            //弹出框
            import mx.controls.Alert;
            public function clickHandler(clickEvent:Event):void
            {
             Alert.show("Envent Type:"+clickEvent.type+"----------"+"came from"+clickEvent.currentTarget.id);
            }
        ]]>
    </fx:Script>
    <s:Button id="Me" label="点解我丫丫丫丫" click="clickHandler(event)" x="100" y="200"/>
    
    <!--使用if else 检查密码-->
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            public function checkPassword():void
            {
              if(password.text.length<1)
                  Alert.show("没有输入密码");
              else if (password.text.length <5)
              { Alert.show("没有输入足够长的密码");}
              else Alert.show("输入了密码 ");
            }
        ]]>
    </fx:Script>
    <s:Group>
        <s:layout>
            <s:VerticalLayout/>
        </s:layout>
        <s:TextInput id="password"/>
        <s:Button label = "检查密码" click = "checkPassword()" x="100" y ="400"/>
    </s:Group>

    
    
</s:Application>
View Code

2、

x++,先使用原值,再加1.

++x,先加1,在使用原值。

var x:int=0
trace(x++);/输出0,然后后x的值增加1
trace(x);//输出1
View Code

 3、函数返回值

<!--创建返回-->
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;
            public function textMerge(input1:String,input2:String):String
            {
                var x:String = input1 + input2;
                return x;
            }
        ]]>
    </fx:Script>
    <s:Group x="100" y ="400">
        <s:layout>
            <s:HorizontalLayout/>            
        </s:layout>
        <s:TextInput id="value1"/>
        <s:Label text="and"/>
        <s:TextInput id="value2"/>
        <s:Button label="两字符串相加" click="Alert.show(textMerge(value1.text,value2.text))"/>
    </s:Group>
View Code

 

 

Copyright © 2024 诸葛小北
Powered by .NET 8.0 on Kubernetes