flash on 2013-3-25

by tepe
♥0 | Line 48 | Modified 2013-11-05 14:37:10 | MIT License
play

ActionScript3 source code

/**
 * Copyright tepe ( http://wonderfl.net/user/tepe )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dto6
 */

package {
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.net.*;
    import flash.system.*;
    public class FlashTest extends Sprite {
        private var txt:TextField = new TextField();
        private const id1:String = "http://192.168.11.7";
        private const id2:String = "http://ozworks.dip.jp";
        public function FlashTest() {
            addChild(txt);
            txt.text = "aaa";
            test();
            
        }
        
        private function test():void{
            
            // データ作成
            var variables:URLVariables = new URLVariables();
            variables.title = "webstudynote";
            variables.url = id1;
            variables.text = "PHPとAS3の通信テスト";
 
  
            // データ送信先
            //var url_Request:URLRequest = new URLRequest();
            var req:URLRequest = new URLRequest("http://ozworks.dip.jp/testphp15.php");//ローカルテスト用
            req.url = id1+"/testphp15.php";
            req.method = URLRequestMethod.POST;
            //req.data = variables;
            
            
            // PHPに渡すパラメータ
         var param:URLVariables = new URLVariables();
         param.w = Capabilities.screenResolutionX;
         param.h = Capabilities.screenResolutionY;
         param.dpi = Capabilities.screenDPI;
         param.ver = Capabilities.version;
         req.data = param;
            txt.appendText("\nconnected");
         // ローダー
         var loader:URLLoader = new URLLoader();
         loader.dataFormat = URLLoaderDataFormat.TEXT;
         loader.addEventListener(Event.COMPLETE, onComplete);
         loader.load(req);

 /*
            // 送信する
            var url_Loader:URLLoader = new URLLoader();
            url_Loader.dataFormat = URLLoaderDataFormat.VARIABLES;
            url_Loader.addEventListener(Event.COMPLETE,onComplete);
            url_Loader.load(req);
            txt.appendText("\nsending");
            */
        }
            // 受信する
         
        private function onComplete(e:Event):void{
            txt.appendText("\ncomplete");
 
            //var re_variables:URLVariables = new URLVariables( evt.target.data);
            //txt.appendText(re_variables.comp);
                
            var loader:URLLoader = e.target as URLLoader;
            loader.removeEventListener(Event.COMPLETE, onComplete);
          
            // 結果を表示
            var result:String = loader.data as String;
            txt.width = 400;
            txt.height = 400;
            txt.text = "レスポンス↓\n\n"
            txt.appendText(result);
            //addChild(t);
            txt.x = txt.y = 10;
            
        }

   
        
    }
}