• Home
  • About
  • Contact Us
  • Gallery
  • Video
  • Archives
  • Site Map
Grab the RSS feed

FlashBannerOnline

FlashBannerOnline
  • Home
  • FlashBannerOnline
  • Free Downloads
  • General
  • Tutorials
    • Adobe AIR
    • CSS
    • Fireworks
    • Flash
      • ActionScript
    • FLEX
    • Javascript
      • JQuery
      • MooTools
    • PHP

Using URLLoader to send and load Data to Server Used FLEX

  • ActionScript, FLEX, Tutorials

    Posted on February 2nd, 2010

    Written by Behrouz Pooladrag

    Related Posts

    • Using ActionScript 3.0 with PHP Loading External Variables
    • Sample Loading Text and XML with URLLoader
    • Loading Text and XML with URLLoader in AS3

    Tags

    "urlloader.php?url=", actionscript, actionscript 3 sendandload php, adobe flex urlloader, as2 url load, AS3, as3 "adobe air" "login" php, as3 flash.net, as3 loadandsend php, as3 mysql data, as3 nysql banner and text, as3 reload url, Class, database, flash as2 login php mysql, flash as2 php database sample, flash as3 urlrequest variable, flash cs4 mysql php, flash load and send, flash load url, flash loader using coding, flash php mysql as3 login, flash send and load data, flash servlet xml example, flash to php data using urlloader, flash urlrequest login sample, flash.net.URLLoader, FLEX, flex 3 urlloader reload, flex and php communication through xml, flex con servlet, flex php urlloader, flex record and send to server, flex retreive string from servlet senddata, flex return mysql data, flex servlet url swf/dynamic/3, flex url loader servlet, flex urlloader, flex urlloader variables, flex urlrequest string variable, flex urlrequestmethod.post urlloader, flex urlvariables php, flex with mysql using as3, how to send data throught urlrequest in flex, how to send data to server in flash as3, input data flash mysql, ip:207.182.137.187 id, load a flash object file from mysql, load data from post urlloader, Mysql, on release flash.net.urlloader, passing data mysql flash, PHP, php flash servlet, php load url, reload data from mysql in flash cs4, sample flash as3 classes, send and load as3, send and load flash as3 php mysql, send data urlrequest, send load php as3, send param with url loader flex, send variables to flex from php, SendAndLoad, sendandload as2 error loading url, sendandload con actionscript 3.0 y mysql, sendandload in as3 with php, sending data from flex to servlet, sending data to server as3, sending request from flex to servlet, servlet load data mysql, to pass data from flash to mysql database using as3, trace("par: " loader.data.par);, url loader flex, url loader send as3, URLLoader, urlloader as2, urlloader class php, urlloader com php my sql, urlloader data, urlloader flex, urlloader flex php lightspeed problem, urlloader par, urlloader responce, urlloader to pass data, urlloader urlvariables, urlloader.sendandload(), URLLoaderDataFormat, URLRequest, urlrequest method post flex, URLRequestMethod, URLVariables, urlvariables custom flex, write text file using urlloader actionscript 3, xmlloader:flash.net.urlloader
    Using URLLoader to send and load Data to Server Used FLEX

    Here is a very simple example of two way communication with database using Flex and PHP. In this example, we are sending username and password to the PHP file from Flex. PHP file then validates the input and returns the appropriate response.

    This example also demonstrates the simple PHP script to establish a database (MySQL) connection and validate username and password against the table in database.

    In AS3, we can use flash.net.URLLoader, URLRequest and URLVariables class to send and load data. First create a class named SendAndLoadExample.

    Class SendAndLoadExample:

    package {
    
    import flash.events.*
    import flash.net.*;
    
    public class SendAndLoadExample {
    
    public function SendAndLoadExample() {}
    public function sendData(url:String, _vars:URLVariables):void {
    var request:URLRequest = new URLRequest(url);
    var loader:URLLoader = new URLLoader();
    loader.dataFormat = URLLoaderDataFormat.VARIABLES;
    request.data = _vars;
    request.method = URLRequestMethod.POST;
    loader.addEventListener(Event.COMPLETE, handleComplete);
    loader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
    loader.load(request);
    }
    private function handleComplete(event:Event):void {
    var loader:URLLoader = URLLoader(event.target);
    trace("Par: " + loader.data.par);
    trace("Message: " + loader.data.msg);
    }
    private function onIOError(event:IOErrorEvent):void {
    trace("Error loading URL.");
    }
    }
    }
    

    Now, create an object of SendAndLoadExample class in Flex.

    SendAndLoadExample.mxml

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                    layout="vertical">
    <mx:Script>
    <![CDATA[
    import flash.net.URLVariables;
    private var mySendAndLoadExample:SendAndLoadExample;
    mySendAndLoadExample = new SendAndLoadExample();
    private function sendAndLoad():void {
    var url:String = "http://[your server]/login.php";
    var variables:URLVariables = new URLVariables();
    variables.UserName = "tushar";
    variables.Password = "my_password";
    mySendAndLoadExample.sendData(url, variables);
    }
    ]]>
    </mx:Script>
    <mx:Button label="Fetch data" click="sendAndLoad()"/>
    </mx:Application>
    

    PHP file for login check: login.php

    
    <?
    $clientUserName=$_POST['UserName'];
    $clientPassword=$_POST['Password'];
    //////////////////////////////////////
    // Host name
    $host="[your server]";
    // Mysql username
    $username="[MySql database username]";
    // Mysql password
    $password="[MySql database password]";
    // Database name
    $db_name="[MySql database name]";
    // Table name
    $tbl_name="[MySql table name having usernames and passwords]";
    function makeConnection() {
    // Connect to server and select databse.
    mysql_connect("$GLOBALS[host]", "$GLOBALS[username]",
                    "$GLOBALS[password]")or die("cannot connect");
    mysql_select_db("$GLOBALS[db_name]")or die("cannot select DB");
    }
    function fireQuery($query) {
    $result=mysql_query($query);
    return $result;
    }
    function printOutput($code, $msg){
    print "par=$code&msg=$msg";
    }
    //////////////////////////////////////
    function checkUserID($id, $password) {
    $sql="SELECT * FROM $GLOBALS[tbl_name] WHERE
                    userName='$id' and password='$password'";
    $result=fireQuery($sql);
    $count=mysql_num_rows($result);
    if($count==1){
    return true;
    }
    return false;
    }
    function init(){
    if(isSet($GLOBALS["clientUserName"])
            && isSet($GLOBALS["clientPassword"])){
    makeConnection();
    if(checkUserID($GLOBALS["clientUserName"]
            , $GLOBALS["clientPassword"])){
    printOutput("1", "Login successful.");
    } else {
    printOutput("0", "Failed to login $GLOBALS[clientUserName].");
    }
    } else {
    printOutput("0", "Required parameters missing.");
    }
    }
    init();
    ?>
    

    fin.

    This entry was posted on Tuesday, February 2nd, 2010 at 2:55 am and is filed under ActionScript, FLEX, Tutorials. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

    You might also like

    Using ActionScript 3.0 with PHP Loading External Variables Creating dynamic websites which combine the power of Flash or Flex with PHP is easier than ever with ActionScript...
    Sample Loading Text and XML with URLLoader In previous versions of ActionScript, there were a couple of classes who had the capability of loading external...
    Loading Text and XML with URLLoader in AS3 In previous versions of ActionScript, there were a couple of classes who had the capability of loading external...
    Sending Data from AVM2 (AS3) to AVM1 (AS2/AS1) In Chapter 13, we showed how to use a LocalConnection to communicate between an AS3-based movie in Flash Player's...
  • 0 Comments

    Take a look at some of the responses we've had to this article.

  • Post a Comment

    Let us know what you thought.

  • Name:

    Email (required):

    Website:

    Message:

  • Ad Ad

  • FlashBannerOnline.Com

  • Subscribe

    Enter your email address:

    | More

  • Blogroll
    • Random Flash Banner!
  • Tag Cloud

    • actionscript addChild addEventListener Adobe AIR Air Animation AS2 AS3 as3 preloader Banner beginFill BitmapData blog.flashbanneronline.com Class CSS Date Class draw Flash flash.net.URLLoader flash banner free flash banner generator flash banner happy new year flashbanneronline FlashBannerOnline.com flash banner online free flash player function game getChildIndex Javascript lightbox Loading Mysql new year flash banner Object Optimization package PHP Sprite tot Tweener URLLoader URLRequest web XML
  • Recent Comment
    • Behrouz Pooladrag on Flash Optimization – Freezing And Unfreezing Objects
    • Valerie on Flash Optimization – Freezing And Unfreezing Objects
    • FlashLord on RSS Reader for FlashBannerOnline Blog!
    • Behrouz Pooladrag on Using ActionScript 3.0 with PHP Loading External Variables
    • LUN on Using ActionScript 3.0 with PHP Loading External Variables
  • RSS FlashBannerOnline
    • Happy New Year 2012 & Gift!
    • New Templates Oval Light Added to Flash Banner Online
    • FlashBannerOnline started in Arabic language
    • Happy New Year 2011
    • New Templates Christmas 2011 Added at Christmas!
    • New Templates angel animate Added to Flash Banner Online
    • Added Tow New Preloader (Pro Preloader , Rotate Preloader)
    • Happy New Year , by new Theme (Christmas 2010)
  • Add to Technorati Favorites

    Subscribe
  • Google
    Custom Search

Copyright © 2010 FlashBannerOnline - Powered by Wordpress.

FBO by