开发者

The right way to send variables with as3 to asp?

Im trying to make an swf send a phone-number to a specific asp-fil on the press of a button. But since I'm an as3 rookie I have no idea where this code is going wrong (PLEASE HELP):

import flash.events.IOErrorEvent;
import flash.display.*;
import flash.events.MouseEvent;
import flash.net.*;
import flash.events.Event;

public class action extends MovieClip
{
    private var swf_front_mc:swf_front = new swf_front  ;
    var request:URLRequest = new URLRequest("succes.html");
    var request2:URLRequest = new URLRequest("http://www.example.com");
    public var mobilNr:Number = new Number(swf_front_mc.mobilInput.text);
    public var varsToSend:URLVariables = new URLVariables();

    public function action()
    {
        addChild(swf_front_mc);
        swf_front_mc.name = "swf_front_mc";
        swf_front_mc.x = 0;
        swf_front_mc.y = 0;

        makeInteraction();
    }
    private function makeInteraction():void
    {
        swf_front_mc.submit_mc.addEventListener(MouseEvent.CLICK, submitForm);
    }

    function submitForm(e:MouseEvent):void
    {
        //trace("hello");
        varsToSend.RecipientMobileNumber = mobilNr;

        // Create URL Request, set to POST, and attach data
        var formRequest:URLRequest = new URLRequest("webform_input.asp");
        formRequest.method = URLRequestMethod.GET;
        formRequest.data = varsToSend;

        // Create URL Loader, attach listeners, and load URL Request
        var varLoader:URLLoader = new URLLoader  ;
        varLoader.addEventListener(Event.COMPLETE, onLoaded);
        varLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        varLoader.load(formRequest);
    }
function onLoaded(e:Event):void
    {
        navigateToURL(request,"blank");
    }

    function ioErrorHandler(e:IOErrorEvent):void
    {
        navigateToURL(requ开发者_高级运维est2,"blank");
    }

}


Thanks for the tips and hints guys... Meanwhile i got the perfect solution from a friend. It's much shorter and more simple then I thought possible. Here it is:

package app.form
{
    import flash.net.*;
    import flash.display.*;
    import flash.events.*;

    public class container extends MovieClip
    {
        public function container()
        {
            sendBtn.addEventListener(MouseEvent.CLICK, sendBtnClick);
        }

        public function SendToURLExample(_navn:String, _tlf:String) {
            var url:String = "http://www.yourdomain.com/file.asp";
            var variables:URLVariables = new URLVariables();
            variables.name = _name;
            variables.phone = _phone;

            var request:URLRequest = new URLRequest(url);
            request.data = variables;
            trace("sendToURL: " + request.url + "?" + request.data);
            try {
                sendToURL(request);
            }
            catch (e:Error) {
                // handle error here
            }
        }

        // two text-example-fields on stage called input_text_name/input_text_mobil
        private function sendBtnClick(e:MouseEvent):void {
            SendToURLExample(input_text_name.text, input_text_mobil.text);
        }
    }

}

Hope this will solve the something for someone out there :)


try this one example http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/URLVariables.html#includeExamplesSummary

or you can try to encode your vat into GET URL like new URLRequest("localhost/?number="+numberField.text);

but first one try navigatetourl method from previous sample.

p.s. look at this too: http://blog.flexexamples.com/2007/08/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜