2 Replies Latest reply on Sep 6, 2009 6:03 AM by FlashAdicted

    unable to load php file into native window..

    niroshan_fernandez

      Hi Guys,

       

      Im using flash cs3 as my development environment. what i was trying to do is creating a small login application using Air. I must say im still a newbie to flash air. as far as my login system concern i have managed following tasks,

       

      1. send username ans password using post and validate through php

      2. get the result back to flash application and open up a new native air window if the login is success.

      3. close the login window.

       

      now what i want to do is load my PHP application inside that newly open native window. How can i do it. I tried using Loader() method but it only worked for images not for php or html files.

       

      heres how I tried to use the loader method,

      var url:String = "http://localhost/Flash/login/welcome.php";
      
      var fileLoader:Loader = new Loader();
      fileLoader.load(new URLRequest(url));
      win.stage.addChild(fileLoader);
      

      This failed.

       

      Does anyone know how to load a PHP file into a Native window? Your help highly appreciate it.

       

      Just in case for the people who wants to know who I did the above mentioned tasks heres the code,

       

      Posting data to PHP server

       

      function sendLoginData() {
           
           if(txtUserName.text=='')
                txtBox.text = 'Username is empty';
           else if(txtPassword.text=='')
                txtBox.text = 'Password is empty';
           else
           {
                var variables:URLVariables = new URLVariables(); 
                variables.UserName = txtUserName.text; 
                variables.Password = txtPassword.text; 
              
                var request:URLRequest = new URLRequest("http://localhost/Flash/login/login.php");  
                var loader:URLLoader = new URLLoader();  
                loader.dataFormat = URLLoaderDataFormat.TEXT;  
                request.data = variables;  
                request.method = URLRequestMethod.POST;  
                loader.addEventListener(Event.COMPLETE, handleComplete);  
                loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);  
                loader.load(request);
           }
      }
      

       

      Handdle the returned data

       

      function handleComplete(event:Event):void
      {
           var variables:URLVariables = new URLVariables(event.target.data);  
      
           if(variables.errorcode==0)
           {     
                var url:String = "http://localhost/Flash/login/welcome.php";
                try {                              
                     //Native window
                     var options:NativeWindowInitOptions = new NativeWindowInitOptions();
                     options.systemChrome = NativeWindowSystemChrome.STANDARD;
                     options.transparent = false;
                     options.maximizable=false;
                     
                     var win:NativeWindow = new NativeWindow(options);
                     win.title = 'welcome page';
                     //win.width = 900;
                     //win.height = 900;
                     
                     /*var fileLoader:Loader = new Loader();
                     fileLoader.load(new URLRequest(url));
                     win.stage.addChild(fileLoader);*/
                     
                     win.maximize();
                     win.activate();
           
                     
                     stage.nativeWindow.close();
      
                } catch (e:Error) {
                  trace("Error occurred!");
                }
           }
           else
                txtBox.text = 'Invalid logins';
      }  
      
      function onIOError(event:IOErrorEvent):void
      {  
           trace("Error loading URL.");  
      }
      

       

      PHP code

       

      <?php
      $username = addslashes($_POST['UserName']);
      $password = addslashes($_POST['Password']);
      
      //do your database checking here. this is an example
      if($username=='niroshan' && $password=='123456')
           echo "errorcode=0";  
      else
           echo "errorcode=1";  
      ?>
      

       

      Call the function when pressing the submit

       

      cmdButton.addEventListener(MouseEvent.CLICK,readySendLoginData);
      
      function readySendLoginData(evt:MouseEvent){     
        sendLoginData();
      }
      

      Thanks,

       

      best regards,

      Niroshan