2010-08-16 121 views
2

我試圖讓一個swf發送一個電話號碼到一個特定的asp-fil按下按鈕。 但因爲我是一個菜鳥AS3我不知道在哪裏這個代碼是怎麼了?(請幫助):用as3發送變量到asp的正確方法是什麼?

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(request2,"blank"); 
    } 

} 
+1

好了,這樣你就不會尋找類似FlourineFx或的WebORB。感謝您的反饋。 – Gunslinger47 2010-08-17 08:35:15

回答

1

感謝提示和提示傢伙... 同時,我從朋友得到了完美的解決方案。這是我認爲可能的更短,更簡單。那就是:

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); 
     } 
    } 

} 

希望這將解決東西有人在那裏:)

0

試試這個例子 http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/URLVariables.html#includeExamplesSummary

,或者你可以嘗試增值稅編碼成GET URL像新的URLRequest(「localhost /?number =」+ numberField.text);

但首先嚐試從之前的示例導航調用方法。

p.s.看看這個:http://blog.flexexamples.com/2007/08/16/using-httpservice-tag-to-sendreceive-variables-to-a-server-side-script/

+0

感謝您閱讀的提示:)找到了一個解決方案tho ...張貼在下面。 – VoodooBurger 2010-08-19 07:03:35

+0

如你所願:) 快樂編碼) – Eugene 2010-08-19 08:01:33

相關問題