开发者

actionscript 3 return

开发者 https://www.devze.com 2023-03-21 15:49 出处:网络
I am new in actionscript 3 and I have this code which doesn\'t work. So can you check it? I only want that Label1.text got input \"hello world\"

I am new in actionscript 3 and I have this code which doesn't work. So can you check it? I only want that Label1.text got input "hello world"

<?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="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            function onButton1click():void {
                Label1.text = Login('irakli', 'password1');
            }

            function Login(username:String, password:String){
                var loader:URLLoader = new URLLoader();
                var request:URLRequest = new URLRequest('http://localhost/hosting/index.php');

                request.method = URLRequestMethod.POST;
                var variables:URLVariables = new URLVariables();
                variables.username = username;
                variables.password = password;
                request.data = variables;

                //handlers
                loader.addEventListener(Event.COMPLETE, _urlSended);
                loader.load(request);

                function _urlSended(e:Event){
                    var loader:URLLoader = URLLoader(e.target);
        开发者_如何学C            return loader.data;                     
                }
            }
        ]]>
    </fx:Script>
    <s:Button id="button1" x="193" y="118" label="Button" click="onButton1click();"/>
    <s:Label id="Label1" x="223" y="166" text="Label"/>
</s:Application>


Try this:

<?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="955" minHeight="600">
    <fx:Script>
        <![CDATA[
            private function onButton1click():void 
            {
                login('irakli', 'password1');
            }

            private function login(username:String, password:String):void
            {
                service.send({username:username, password:password});
            }

            private function onLoginResult(e:ResultEvent):void
            {
                label.text = e.data as String;
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:HTTPService id="service" url="http://localhost/hosting/index.php" method="POST" result="onLoginResult(event)" />
    </fx:Declarations>
    <s:Button x="193" y="118" label="Button" click="onButton1click()"/>
    <s:Label id="label" x="223" y="166" text="Label"/>
</s:Application>

This isn't tested, but it should help you at least.

0

精彩评论

暂无评论...
验证码 换一张
取 消