AS3 & PHP

I am trying to retrieve name and value pairs from a php
script with AS3. Flash keeps giving me the error.
Error #2101: The String passed to URLVariables.decode() must
be a URL-encoded query string containing name/value pairs.
Here is an extract of my php.
while ($row = mysql_fetch_assoc ($qr)) {
while (list ($key, $val) = each ($row)) {
$r_string .= '&' . $key . $i . '=' .$val;
$i++;
// add extra & to prevent returning extra chars at the
end
$r_string .='&';
echo $r_string;
If i change the echo to something like echo "name&value"
it works, its as if it does not like the $r_string. I have tried
using urlencode($r_string) and string($r_string) but it fails. The
php used to work in AS2 with sendAndLoad fine.

Thanks for your reply, however php does not seem to have a
URLEncode function, it has a urlencode function which I tried, I
pointed that out at the bottom of my original post.
Like I said previously, if i echo "name&value" (which is
not urlencoded) it works fine.

Similar Messages

  • AS3 / PHP / MySQL - login form

    Hello,
    I'm trying to create the most basic example I can of an AS3/PHP/MySQL interaction.  I want a Flash movie to check a user's login/pass against a DB.  I've tested the PHP code and know it's correct.  The problem must lie in the AS.  I've traced everything to make sure it goes out correctly, but it comes back as the variable names $user, $pass...and some other garbage... not the variable values I am expecting... see below.
    The PHP code correctly returns the following when tested in browser:  user=dan&pass=danpass&err=Success!
    The traced variables $user, $pass, $err return the following in Flash:
    undefined
    $pass
    $err";
        echo $returnString;
    ?>
    Here's the ActionScript:
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLVariables;
    import flash.net.URLRequestMethod;
    logbtn.addEventListener(MouseEvent.CLICK, login)
    function login($e:MouseEvent){
      var myVariables:URLVariables = new URLVariables();
      var myRequest:URLRequest = new URLRequest("login.php");
      myRequest.method = URLRequestMethod.POST;
      myRequest.data = myVariables;
      var myLoader:URLLoader = new URLLoader;
      myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
      myLoader.addEventListener(Event.COMPLETE, completeHandler);
      myVariables.user = loguser.text;
      myVariables.pass = logpass.text;
      myLoader.load(myRequest);
      function completeHandler(event:Event):void{
        trace(event.target.data.user);
        trace(event.target.data.pass);
        trace(event.target.data.err);
    And here's the PHP:
    <?php
      include_once "dbconnect.php";
      $user = $_POST['user'];
      $pass = $_POST['pass'];
      $sql = mysql_query("SELECT * FROM users WHERE user = '$user' AND pass = '$pass'");
      $check = mysql_num_rows($sql);
      if($check > 0){
        $row = mysql_fetch_array($sql);
        $user = $row["user"];
        $pass = $row["pass"];
        $err = "Success!";
        $returnString = "user=$user&pass=$pass&err=$err";
        echo $returnString;
    ?>
    Does anything stand out as being wrong?  I've gone over this for probably 10-15 hours trying different variations, tweaks, and reducing it in complexity.  I will really appreciate any help you can offer!  Thank you.
    -Eric

    Thanks Birnerseff! 
    I've been running the SWF from the same directory as the PHP script.  I just tried viewing it through my localhost and it worked!  I guess I'll have to do all my testing that way, but that's fine.
    Thank you very much.  I probably wouldn't have messed around with that for a long time otherwise.
    -Eric

  • Contact forms in Flash (AS3/PHP)

    Hello,
    I have created a form in flash (CS5) using AS3 and Php.
    The test run worked absolutely fine but now I have added the form to my (original) flash movie it has a number of errors come up...
    Thing is that I've just spent the last 2 hours trying to get this form to work and having no success what so ever.
    So does anyone know what the following complier errors mean and how I can solve this issue?
    Scene 1
    1152: A conflict exists with inherited definition flash.display:DisplayObject.name in namespace public.
    ComponentShim (Compiled Clip), Line 1
    5000: The class 'fl.controls.TextArea' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    ComponentShim (Compiled Clip), Line 1
    5000: The class 'fl.controls.TextInput' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    ComponentShim (Compiled Clip), Line 1
    5000: The class 'fl.controls.UIScrollBar' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    ComponentShim (Compiled Clip), Line 1
    5000: The class 'fl.controls.Button' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
    Yes, I'm obviously a newbie and still getting to grips with flash so any help would be amazing!
    Thank you in advance,
    Jos

    add those components to the library of your main (ie, loading) fla.

  • Creating a file on server, using Flash AS3 + PHP

    I have a very simple PHP script that creates a new file on my server using a random number for the file name (e.g., 412561.txt).  When I load the script directly from a browser, it works.  But when I load the script from a very simple Flash (AS3) script, it does not work (i.e., doesn't create a file).  The Flash script and PHP script are both in the same directory.  Permissions on the directory and its content are 755.  Temporarily setting those permissions to 777 does not solve the problem (i.e., PHP still doesn't create file when called via Flash).
    Here is my phpinfo.
    Here is the PHP file.
    The contents of the PHP file are:
    <?php
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    $RandomNumber = rand(1,1000000);
    $filename = "$RandomNumber" . ".txt";
    $filecontent = "This is the content of the file.";
    if(file_exists($filename))
              {$myTextFileHandler = fopen($filename,"r+"); }
    else
              {$myTextFileHandler = fopen($filename,"w"); }
    if($myTextFileHandler)
              {$writeInTxtFile = @fwrite($myTextFileHandler,"$filecontent");}     
    fclose($myTextFileHandler);   
    ?>
    Here is the html container for the Flash script.  The Flash script features a single button which calls the PHP script when pressed.  In case it helps, here is the raw Flash file itself.  The code of the Flash script is as follows:
    stop();
    var varLoader:URLLoader = new URLLoader;
    var varURL:URLRequest = new URLRequest("http://www.jasonfinley.com/research/testing/TestingSaveData.php");
    btnSave.addEventListener(MouseEvent.CLICK,fxnSave);
    function fxnSave(event:MouseEvent):void{
              btnSave.enabled=false;
              varLoader.load(varURL);
    Directory listing is enabled at the parent directory here, so you can see there when a new text file is created or not.  (Um, if this is a security disaster, please let me know!)
    Can anyone please help me understand why this isn't working and how I can fix it?  Thank you
    ~jason

    #1, Yes that is a security risk, please disable directory index viewing.
    #2, Always validate. I see no issue with the code you're using but clearly it's not working. The way you find out is your trusty errors.
    Make a new document (or paste this into your existing) where a button with the instance name btnSave is on screen:
    // import required libs
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.MouseEvent;
    import flash.events.SecurityErrorEvent;
    import flash.text.TextField;
    // assign handler
    btnSave.addEventListener(MouseEvent.CLICK, fxnSave);
    // make a textfield to display status
    var tf:TextField = new TextField();
    addChild(tf);
    tf.width = stage.stageWidth;
    tf.height = 300;
    tf.multiline = true;
    tf.wordWrap = true;
    tf.selectable = false;
    tf.text = "Loading...\n";
    // just making sure the textfield is below the button
    this.swapChildren(tf,btnSave);
    function fxnSave(event:MouseEvent):void
        // disable button
        event.currentTarget.enabled = false;
        // new loader
        var varLoader:URLLoader = new URLLoader();
        // listen for load success
        varLoader.addEventListener(Event.COMPLETE, _onCompleteHandler);
        // listen for general errors
        varLoader.addEventListener(IOErrorEvent.IO_ERROR, _onErrorHandler);
        // listen for security / cross-domain errors
        varLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, _onErrorHandler);
        // perform load
        varLoader.load(new URLRequest("http://www.jasonfinley.com/research/testing/TestingSaveData.php"));
    // complete handler
    function _onCompleteHandler(e:Event):void
        tf.appendText("Load complete: " + e);
    // error handler
    function _onErrorHandler(e:Event)
        if (e.type == SecurityErrorEvent.SECURITY_ERROR)
            tf.appendText("Load failed, Security error: " + e + " type[" + e.type + "]");
        else if (e.type == IOErrorEvent.IO_ERROR)
            tf.appendText("Load failed, IO error: " + e + " type[" + e.type + "]");
    I get a Event.COMPLETE for mine, so the PHP script is definitely firing. Change the URL to something invalid and you'll see the IOErrorEvent fire off right away.
    That leaves you to diagnose the PHP script. Check your error_log and see what is going wrong. You're suppressing errors on your file write which doesn't help you locate the issue saving the file. If you want to handle errors yourself you should do the usual try/catch and handle the error yourself (write a debug log file, anything).

  • AS3/PHP Contact Form Problem

    I am working on a contact form in my .fla that utilizes php to send user info to my email address.  I believe I have all of the files in the correct directories, but it is still unsuccessful.  I am not getting any errors in the AS3.  Rather, I think the issue is related to the send_email.php file.  The swf is hosted at http://stephenpappasphoto.com/ and the page in question is under the "Contact" button.
    Here is the AS3:
    import flash.utils.Timer;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.MouseEvent;
    import flash.net.URLVariables;
    import flash.events.TimerEvent;
    f_Name.text = f_Date.text = f_Location.text = f_Email.text = f_Phone.text = f_Budget.text = message_status.text = "";
    submitBtn.addEventListener(MouseEvent.CLICK, submit);
    resetBtn.addEventListener(MouseEvent.CLICK, reset);
    var timer:Timer;
    var var_load:URLLoader=new URLLoader;
    var URL_request:URLRequest=new URLRequest("send_email.php");
    URL_request.method=URLRequestMethod.POST;
    function submit(e:MouseEvent):void
        if( f_Name.text == "" || f_Date.text == "" || f_Location.text == "" || f_Email.text== "" || f_Phone.text == "" || f_Budget.text == "" )
            message_status.text = "Please fill up all test fields.";
        else if( !validate_email(f_Email.text) )
            message_status.text = "Please enter a valid email address.";
        else
            message_status.text = "Sending..."    ;
            var email_data:String = "name=" + f_Name.text 
                                + "&email=" + f_Email.text
                                + "&message=" + f_Phone.text
                                + "&message=" + f_Location.text
                                + "&message=" + f_Date.text
                                + "&message=" + f_Budget.text;
            var URL_vars:URLVariables = new URLVariables(email_data);
            URL_vars.dataFormat = URLLoaderDataFormat.TEXT;
            URL_request.data = URL_vars;
            var_load.load( URL_request );
            var_load.addEventListener(Event.COMPLETE, receive_response );
    function reset(e:MouseEvent):void
        f_Name.text = f_Date.text = f_Location.text = f_Email.text = f_Phone.text = f_Budget.text = message_status.text = "";
    function validate_email(s:String):Boolean
        var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
        var r:Object = p.exec(s);
        if( r == null )
            return false;
        return true;
    function receive_response(e:Event):void
        var loader:URLLoader = URLLoader(e.target);
        var email_status = new URLVariables(loader.data).success;
        if( email_status == "yes" )
            message_status.text= "Thank you for your contact information.  I will get back to you shortly.";
            timer = new Timer(500);
            timer.addEventListener(TimerEvent.TIMER, on_timer);
            timer.start();
        else
            message_status.text = "Your message cannot be sent.  Please email your information to [email protected]. ";
    function on_timer(te:TimerEvent):void
        if( timer.currentCount >= 10)
            f_Name.text = f_Date.text = f_Location.text = f_Email.text = f_Phone.text = f_Budget.text = message_status.text = "";
            timer.removeEventListener(TimerEvent.TIMER, on_timer);
    Here is the send_email.php:
    <?php
    $f_Name = $_POST['name'];
    $f_Date = $_POST['date'];
    $f_Location = $_POST['location'];
    $f_Email = $_POST['email'];
    $f_Phone = $_POST['phone'];
    $f_Budget = $_POST['budget'];
    if( $f_Name == true )
        $sender = $f_Email;
        $receiver = "[email protected]";
        $client_ip = $_SERVER['REMOTE_ADDR'];
        $email_body = "Name: $f_Name \nEmail: $f_Email \n\nSubject: New Client-$f_Name \n\nDate: $f_Date \n\n$f_Location \n\n   Phone: $f_Phone \n\n    Budget: $f_Budget\n\n    IP: $client_ip \n\n";       
        $extra = "From: $sender\r\n" . "Reply-To: $sender \r\n" . "X-Mailer: PHP/" . phpversion();
        if( mail( $receiver, "New Client - $f_Name", $email_body, $extra ) )
            echo "success=yes";
        else
            echo "success=no";
    ?>
    Thank you in advance for any advice.

    Try this:
    For the actionscript side, my changes are in italics:
    import flash.utils.Timer;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.MouseEvent;
    import flash.net.URLVariables;
    import flash.events.TimerEvent;
    f_Name.text = f_Date.text = f_Location.text = f_Email.text = f_Phone.text = f_Budget.text = message_status.text = "";
    submitBtn.addEventListener(MouseEvent.CLICK, submit);
    resetBtn.addEventListener(MouseEvent.CLICK, reset);
    var timer:Timer;
    var var_load:URLLoader=new URLLoader;
    var URL_request:URLRequest=new URLRequest("send_email.php");
    URL_request.method=URLRequestMethod.POST;
    URL_request.data = formVariables;
    var_load.addEventListener(Event.COMPLETE, receive_response ); 
    function submit(e:MouseEvent):void
        if( f_Name.text == "" || f_Date.text == "" || f_Location.text == "" || f_Email.text== "" || f_Phone.text == "" || f_Budget.text == "" )
            message_status.text = "Please fill up all test fields.";
        else if( !validate_email(f_Email.text) )
            message_status.text = "Please enter a valid email address.";
        else
            message_status.text = "Sending..."    ;
            formVariables.name = f_Name.text;
            formVariables.email = f_Email.text;
            formVariables.phone = f_Phone.text;
            formVariables.location = f_Location.text;
            formVariables.date = f_Date.text;
            formVariables.budget = f_Budget.text;
            formVariables.subject = "Mail from form...";
            formVariables.recipient = "[email protected]";
            varLoad.load(formVariables);
    function reset(e:MouseEvent):void
        f_Name.text = f_Date.text = f_Location.text = f_Email.text = f_Phone.text = f_Budget.text = message_status.text = "";
    function validate_email(s:String):Boolean
        var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
        var r:Object = p.exec(s);
        if( r == null )
            return false;
        return true;
    function receive_response(e:Event):void
        var loader:URLLoader = URLLoader(e.target);
        var email_status = new URLVariables(loader.data).success;
        if( email_status == "yes" )
            message_status.text= "Thank you for your contact information.  I will get back to you shortly.";
            timer = new Timer(500);
            timer.addEventListener(TimerEvent.TIMER, on_timer);
            timer.start();
        else
            message_status.text = "Your message cannot be sent.  Please email your information to [email protected]. ";
    function on_timer(te:TimerEvent):void
        if( timer.currentCount >= 10)
            f_Name.text = f_Date.text = f_Location.text = f_Email.text = f_Phone.text = f_Budget.text = message_status.text = "";
            timer.removeEventListener(TimerEvent.TIMER, on_timer);
    The php file that you have should work with this actionscript. The variables that you define in the AS, "name", "email", etc, must match the variables that are used in the php. Try it. It may need some additional tweeks.

  • Flash, AS3, PHP, & Query Strings

    I think what I am after is pretty simple but unfortunately, I
    don't know much php. Basically what I am looking for is this.
    I want to pass a query from the browser address to a flash
    document.
    For Example, if someone visits.
    http://www.whatever.com/tour?mls=123456789
    (or tour.php?mls=123456789, whatever is easiest)
    A document opens, resizes the browser (optional but would be
    nice), and loads a flash SWF. It also passes the mls=123456789
    string into flash to a variable mls.
    Any ideas?
    Thanks!
    Drew

    Try: URLLoaderDataFormat.VARIABLES

  • AS3+PHP Game Development Speed

    Dear All,
    I'm an As2 game developer but my new prj need to done with as3.So one thing that I want to make sure is 
    " Will the game speed slow if I place the contents and imgaes into the stage as in AS2 ?"
    As I planned to use OOP class.And confused that all those mcs should be place directly into timeline or should attach from as files?
    Thanks in advance!

    It depends.
    If there are moments in your game were 50+ objects are getting animated, faded etc. on stage and your game runs fullscreen and uses bitmaps it certainly will slow down if you put all things on the timeline.
    Then you could use something like the copyPixels method (google it) to speed things up or even go further and use a framework like flixel

  • Password authentification for as3 php upload

    Hi
    I'm making an Air file that uploads and overwrites an XML file.
    So far, the php is very simple:
    $everything = $_POST['saveThisXML'];
      $everything = stripslashes($everything);
       $toSave = $everything; 
       $fp = fopen("settings.xml", "w");
       if(fwrite($fp, $toSave)) echo "writing=Ok";
       else echo "writing=Error";
       fclose($fp);
    I'd like to set up a user name and passowrd that the user enters in the Air app.  Is it then just a matter of sending POST data to the php file, and have it check the user and pass variables?  Is that a reasonably safe way to do it?  If not, can someone please point me in th edirection of a good tutorial that they're used on this topic?
    Thanks again guys.
    Shaun

    OK
    So somewhere along the line, the user is going to have to set up a database.  I can use PHP to do that though, right?  And they'd just have to run the php page once to set it up.
    Thanks kglad.
    Also, I can successfully upload data from a string (myString) in Flash using PHP:
    var myData:URLRequest = new URLRequest("http://www.blah.com/saver.php");
            myData.method = URLRequestMethod.POST;
            var variables:URLVariables = new URLVariables();
            var origEverything:String = myString;
            variables.saveThisXML = origEverything;       
            myData.data = variables;
            var loadData:URLLoader = new URLLoader();
            loadData.dataFormat = URLLoaderDataFormat.VARIABLES;
            loadData.addEventListener(Event.COMPLETE, doneBaby);
            loadData.addEventListener(IOErrorEvent.IO_ERROR, dataLoadError);
            loadData.load(myData);  
    However, when I try to add two variables to send to php, I get a named pairs error.  Here's what I tried adding (in bold):
    var myData:URLRequest = new URLRequest("http://www.blah.com/saver.php");
             myData.method = URLRequestMethod.POST;
             var variables:URLVariables = new URLVariables();
             var origEverything:String = myString;
              var passTest:String = 'testPW';
             variables.saveThisXML = origEverything;     
         variables.saveThisPass = passTest;     
            myData.data = variables;
             var loadData:URLLoader = new URLLoader();
             loadData.dataFormat = URLLoaderDataFormat.VARIABLES;
             loadData.addEventListener(Event.COMPLETE, doneBaby);
             loadData.addEventListener(IOErrorEvent.IO_ERROR, dataLoadError);
             loadData.load(myData);  
    Why would that generate an error?
    Cheers kglad
    Shaun

  • As3 TypeError:#2007 Parameter text must be non-null can't fix.

    I have comment box project. As3+php based project.And have #2007 Error.Try to fix but can't do anything.If can help it would be very helpful.Error part like this:
    TypeError: Error #2007: Parameter text must be non-null. at flash.text::TextField/set text() at comment2_fla::mc_1/completeHandler() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()
    First Part of Code:
    var variables_re:URLVariables = new URLVariables();
    var varSend_re:URLRequest = new URLRequest("guestbookParse.php");
    varSend_re.method = URLRequestMethod.POST;
    varSend_re.data = variables_re;
    var varLoader_re:URLLoader = new URLLoader;
    varLoader_re.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader_re.addEventListener(Event.COMPLETE,completeHandler_re);
    function completeHandler_re(event:Event):void{
              if(event.target.data.returnBody==""){
                 gbOutput_txt.text = "no data";
                 } else {
                           gbOutput_txt.condenseWhite = true;
                           gbOutput_txt.htmlText = "" + event.target.data.returnBody;
    variables_re.comType = "requestEntries";
    varLoader_re.load(varSend_re);
    Second Part of Code:
    msg_txt.restrict = "ığüşöç A-Za-z 0-9";
    name_txt.restrict = "ığüşöç A-Za-z 0-9";
    var errorsFormat:TextFormat = new TextFormat();
    errorsFormat.color = 0XFF0000;
    processing_mc.visible = false;
    var variables:URLVariables = new URLVariables();
    var varSend:URLRequest = new URLRequest("guestbookParse.php");
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;
    var varLoader:URLLoader = new URLLoader;
    varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader.addEventListener(Event.COMPLETE,completeHandler);
    function completeHandler(event:Event):void{
              processing_mc.visible = false;
              name_txt.text = "";
              msg_txt.text = "";
              status_txt.text = event.target.data.return_msg;
              gbOutput_txt.condenseWhite = true;
              gbOutput_txt.htmlText=""+event.target.data.returnBody;
    submit_btn.addEventListener(MouseEvent.CLICK,ValidateAndSend);
    function ValidateAndSend(event:MouseEvent):void{
              if(!name_txt.length){
                        status_txt.text = "İsminizi Girin";
                        status_txt.setTextFormat(errorsFormat);
              } else if (!msg_txt.length){
                        status_txt.text = "Yorum Girin";
                        status_txt.setTextFormat(errorsFormat);
              }else{
                        processing_mc.visible = true;
                        variables.comType = "parseComment";
                        variables.userName = name_txt.text;
                        variables.userMsg = msg_txt.text;
                        varLoader.load(varSend);
                        status_txt.text = "Yorumunuz Eklendi...";
    Php Part:
    <?php
    mysql_connect("localhost","root","") or die (mysql_error());
    mysql_select_db("yorum") or die (mysql_error());
    if ($_POST['comType'] == "parseComment") {
        $name = $_POST['userName'];
              $location = $_POST['userLocation'];
        $comment = $_POST['userMsg'];
        $sql = mysql_query("INSERT INTO guestbook (name, post_date, comment, location)
            VALUES('$name', now(),'$comment','$location')") 
            or die (mysql_error());
              $body = "";
        $sql = mysql_query("SELECT * FROM guestbook ORDER BY post_date DESC");
        while($row = mysql_fetch_array($sql)) {
                        $id = $row["id"];
                        $name = $row["name"];
                        $post_date = $row["post_date"];
                        $comment = $row["comment"];
                        $location = $row["location"];
                        $comment = stripslashes($comment);
                        $name = eregi_replace("&#39;", "'",  $name);
                        $location = eregi_replace("&#39;", "'",  $location);
                        $comment = eregi_replace("&#39;", "'", $comment);
                        $post_date = strftime("%b %d, %y", strtotime($post_date));
                        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <font color="#9B9B9B">' . $location . '</font>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
                        <br />
                        '.$comment.'
                        <br />
                        <br />
        mysql_free_result($sql);
        mysql_close();
         echo "return_msg=Entry has been added successfully $name, thanks!&returnBody=$body";
         exit();
    if ($_POST['comType'] == "requestEntries") {
        $body = "";
        $sql = mysql_query("SELECT * FROM guestbook ORDER BY post_date DESC");
        while($row = mysql_fetch_array($sql)) {
                        $id = $row["id"];
                        $name = $row["name"];
                        $post_date = $row["post_date"];
                        $comment = $row["comment"];
                        $location = $row["location"];
                        $comment = stripslashes($comment);
                        $post_date = strftime("%b %d, %y", strtotime($post_date));
                        $body .= '<u><b><font color="#790000">' . $name . '</font>    |    <font color="#9B9B9B">' . $location . '</font>      |      <font color="#9B9B9B">' . $post_date . '</font></b></u>
                        <br />
                        '.$comment.'
                        <br />
                        <br />
        mysql_free_result($sql);
        mysql_close();
        echo "returnBody=$body";
        exit();
    ?>

    use the trace function to debug:
    function completeHandler(event:Event):void{
              processing_mc.visible = false;
              name_txt.text = "";
              msg_txt.text = "";
              status_txt.text = event.target.data.return_msg;
              gbOutput_txt.condenseWhite = true;
    trace("::"+event.target.data.returnBody+"::");
              gbOutput_txt.htmlText=""+event.target.data.returnBody;
    // and then initialize $body outside those if-statements or ensure you're sending an appropriate comType variable and value. 
    // right now it doesn't look like you're even sending comType with varSend.
    // ie, you must assign the urlrequest data property AFTER urlvariable variables/values are assigned.

  • Photo gallery with buttons and php.

    I am relatively new to actions script, very new to as3, and brand new to php. I have tried very hard to figure all of this out via tutorials, studying the code, etc but now I'm running out of time to get this done so I need some help.
    I am trying to make a photo gallery that functions as follows:
    -the php gathers all of the filenames from a folder and returns it to flash
    -an array of buttons is loaded onto the stage (one for each photo)
    -flash then loads the first image into a movie clip.
    -when the user clicks on button[i], image[i] loads in the movie clip.
    -i also plan to incorporate what might happen if the number of photos exceeds the number of buttons that can fit nicely on the stage, like an arrow to go to another set of buttons. I haven't tried coding this yet since I was just trying to get the thing to work in general first. If anyone has ideas about this, let me know.
    Please don't make fun of me too much. I know it's probably a mess.
    Thank you so much in advance for your help.
    Here's the php:
    <!--
    Author:      Adam Ehrheart
    Site:      http://adamehrheart.com
    Blog:      http://flashcamp.net
    Date:      4.21.08
    -->
    <?php
    #   Use "." if the get_files.php file resides in the same directory as files being read
    #   Otherwise you can change the path to whatever you like
    #   eg:
    #   Same Directory:
    #   $path = ".";
    #   Other Directory
    #   $path = "products/images/"
    $path = "Photography/";
    #   Choosing what directory to read
    if ($handle = opendir($path)) {
       #   Temporary array to hold image files
       $imageFiles = array();
       #   Creating loop and assigning current file to $file temp variable
       while (false !== ($file = readdir($handle)))
          #   Checking wheter or not the file is invisible and starts with a "."
          $fileCheck = substr($file, 0, 1);
          #   Checking to make sure the files is either a (jpg, JPG, png, PNG)
          $fileType = substr($file, -3);
          #   Making sure file is not invisible
          if($fileCheck != ".")
             #   Making sure file is readable and dynamically loadable by Flash
             if($fileType == "jpg" || $fileType == "JPG" || $fileType == "png" || $fileType == "PNG")
                #   Adding File to the image array
                if($path != "."){
                array_push($imageFiles, $path . $file);
                }else{
                   array_push($imageFiles, $file);
          #   Sorting the files alphabetically
          sort($imageFiles);
       #    Creating XML File output to be read by Flash
       echo "<?xml version=\"1.0\"?>\n";
       #   Root Node
       echo "<image_list>";
       #   Creating child nodes for each image
       foreach($imageFiles as $value)
          #   Pulling the Width and Height values for each file and adding them as attributes for the image node
          list($width, $height) = getimagesize($value);
          #   Creating the image node
          echo "<image width=\"$width\"" . " height=\"$height\">" . $value . "</image>";  
       echo "</image_list>";
       #   Closing the readdir function
       closedir($handle);
    And here's the as3:
    //php photo section
    import flash.events.Event;
    import flash.net.*;
    //load the php file
    var myRequest:URLRequest = new URLRequest("Photography.php");
    var myLoader:URLLoader = new URLLoader();
    //define images variable as an xml file
    var images:XML = new XML();
    images.ignoreWhite = true;
    images.addEventListener ('load', myLoader);
    //define the images variable as an xml as the php file result
    myRequest.data = images;
    //outputting the filenames
    function onLoaded(evt:Event):void {
      trace("here we get the data back: "+myLoader.data);
    //when the data is loaded, begin myRequest
    myLoader.addEventListener(Event.COMPLETE, onLoaded);
    myLoader.load(myRequest);
    //array to call the images
    var imageArray:Array //= NewArray();
    var listLength:Number;
    var il:XMLList = images.data  //xml.images;
    listLength=il.length();
    var i:Number
    var photo_btn:Array = new Array();
    for (i = 0; i < listLength; i++); {
    imageArray[i] = il[i].pic //xml.images[i].pic;
    if (photo_btn[i].mouseDown == true) {
    img_loader.load(imageArray[i])
    if (i == 0)  {
    photo_btn[i].y = 422.7;
    photo_btn[i].x = 411.5
    else if (i > 0 && i < 24); {
    photo_btn[i].y = 422.7;
    photo_btn[i].x = (photo_btn[i-1].x + 18.6);
    if (i > 24 && i < listLength); {
    photo_btn[i].y = 442.7;
    photo_btn[i].x = (photo_btn[i-1].x + 18.6);
    img_loader.load(imageArray[0]);

    As for AS3 part of it, I am not sure your code really works. There are syntax and logical errors there.
    I think you need to take it step by step and accomplish several task in the following sequences:
    1. Write code that loads XML correctly;
    2. Write code that enables buttons;
    3. Write code that will load images on button clicks.
    The code below shows in principal what needs to be done in order to load XML and make the data in this XML available for further consumption. Also, by accomplishing this step you will iron out all the PHP vs Flash wrinkles including your XML.
    Please note, I don't know your XML structure so all the parsing issues you need to resolve yourself.
    Once you get handle on it - we, hopefully, will talk about steps 2 and 3.
    import flash.display.Loader;
    import flash.events.*;
    import flash.net.*;
    var images:XML;
    var myRequest:URLRequest;
    var myLoader:URLLoader;
    // list of image urls that will come from loaded XML
    var imageList:XMLList;
    myRequest = new URLRequest("Photography.php");
    myLoader = new URLLoader();
    myLoader.addEventListener(Event.COMPLETE, onFileLoaded);
    // suggested handler for unexpected errors - avoids some headaches
    myLoader.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
    myLoader.load(myRequest);
    // Note: all the listeners are removed
    // it is always wise to remove listeners that are needed any longer
    // to make objects eligible for arbage collection
    function onLoadError(e:IOErrorEvent):void
         trace(e.toString());
         myLoader.removeEventListener(Event.COMPLETE, onFileLoaded);
         myLoader.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError);
    function onFileLoaded(e:Event):void
         myLoader.removeEventListener(Event.COMPLETE, onFileLoaded);
         myLoader.removeEventListener(IOErrorEvent.IO_ERROR, onLoadError);
         images = new XML(myLoader.data);
         // only now xml is ready and you can start loading images
         imageList= images.pic;

  • Bootstrap + mysql + php: robust solution for an educational dashboard?

    Hi. We are just beginning work on a dashboard for educational purposes. We need to show data tables of sts progress, notes etc...
    Kind of like the following tables:
    http://www.dreambox.com/district-reports
    We have downloaded a template based on bootstrap. It is all pretty easy except for the data integration. Before we were using flash datagrids and were also looking at flex components which were very easy to use. The questions are:
    1. Can we get the same "power" for our data tables/data grids with bootstrap "ready made" plugin ins.
    2. To replicate the datadrid in flash what do we use in bootstrap - ajax datatable or a j query plug in.
    3. How do we connect up the mysql + php + datagrid. Would it be very similar to an AS3 + php + mysql solution?
    Basically, is bootstrap html5 + CSS a viable robust solution to producing an educational dashboard.
    I use the term plugin because I don't think you call them components or widgets.
    You must also know that this will be on an enterprise level and there should be around 10,000 active users - not at the same time obviously. We will be hiring a freelancer or part tim staff to implement and maintain but we do need to know which way to go first.
    Pretty broad questions maybe, just trying to find my way and study up on what I am supposed to be studying up on. I am on Lynda.com which is OK but I need some guys creating these things to give me advice and point us in the right direction.
    Cheers in advance.

    Hi - thank you Nancy - I should get really specific now.
    I spent quite a few hours investigating and here's the run down.
    1. php + mysqli: Pretty easy as it is the same workflow as I use in flash - I was just a bit thrown by the html part and still have a few questions.
    I will post the link to the very clean and easy to follow mysql + php implementation on html tables just in case any newbies are following the post.
    http://www.sourcecodetuts.com/php/18/how-create-secure-registration-page-phpmysql-part-ii
        mysqli - they seem to use the "improved" mysqli now and this code seems to be very professional with encryption etc...
    My question is which is the best method for handling the recordset back from the database.
    1. In flash we used to use XML serialized which is easy for flash objects to pick up and then display in the datagrid tables.
    2. The example in the next link echos it out in the html table format which sounds very obvious but not sure if it is correct as I have never dome that before.
    http://www.sourcecodetuts.com/php/40/creating-and-populating-table-mysql-data-using-twitte r-bootstrap-framework
    while ($row = mysql_fetch_array($result)) {
        // Print out the contents of the entry
        echo '<tr>';
        echo '<td>' . $row['firstname'] . '</td>';
        echo '<td>' . $row['lastname'] . '</td>';
        echo '<td>' . $row['email'] . '</td>';
        echo '<td>' . $row['phone'] . '</td>';
    3. However I am more used to dealing with an object returned and then dealt with in flash BUT a simple html table couldn't deal with that so - I have just started reading re: ajax or javascript. Are they the best way to handle data returned from a database. As I say this dashboard wil have to be used my many thousands and we will be creating various tables with multiple parameters inputted via dropdown box lists.
    My workflow in flash - would it be javascript that would replicate that functionality or do I just echo out in tr and td tags as in above - seems to basic.
    Sorry about repeating mysel above and going on and on but I hace finally got there - just missing the last part in the puzzle.
    Cheers

  • Error #2007 and PHP

    Hello!
    Could you please help me with the following code because I can't find the solution - I receive Error #2007: Parameter text must be non-null. (I know what the error means but  I'm not experienced enough to handle it)
    This is hit counter that uses AS3, PHP ("Counter.php") and  text file ("hit_count.txt").
    AS3:
    var variables:URLVariables = new URLVariables();
    var varSend:URLRequest = new URLRequest("Counter.php");
    varSend.method = URLRequestMethod.POST;
    varSend.data = variables;
    var varLoader:URLLoader = new URLLoader;
    varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
    varLoader.addEventListener(Event.COMPLETE, completeHandler);
    // this is the part that causes problem:
    variables.requestCode = "homepage";
    varLoader.load(varSend);
    function completeHandler(event:Event):void {
        var countVar = event.target.data.phpCountVar;       
    PHP ("Counter.php"):
    <?php
    if ($_POST['requestCode'] == "homepage") {
        $txtDatabase = "hit_count.txt";
        $currentNumber = file_get_contents($txtDatabase, true);
        $fh = fopen($txtDatabase, 'w') or die ("cannot open file");
        $newNumber = $currentNumber + 1;
        $data = "$newNumber";
        fwrite($fh, $data);
        fclose($fh);
        print "phpCountVar=$newNumber";
    ?>
    text file ("hit_count.txt"):
    0
    Any ideas?

    click file/publish settings/flash and tick "permit debugging".  retest.  the problematic line number will be in your error message.
    if that info doesn't allow to solve your problem, copy and paste the problematic line of code here.

  • Load XML file from addon domain without cross-domain Policy file

    Hello.
    Assuming that there are two addon domains on the same server: /public_html/domain1.com       and      /public_html/domain2.com
    I try to load XML file from domain2.com into domain1.com without using cross-domain policy file (since it doesn’t work on xml files in my case).
    So the idea is to use php file in order to load XML and read it back to flash.
    I’ve found an interesting scripts that seems to do the job but unfortunately I can't get it to work. In my opinion there is somewhere problem with AS3 part. Please take a look.
    Here are the AS3/PHP scripts:
    AS3 (.swf in www.domain1.com):
    // location of the xml that you would like to load, full http address
    var xmlLoc:String = "http://www.domain2.com/MyFile.xml";
    // location of the php xml grabber file, in relation to the .swf
    var phpLoc:String = "loadXML.php";
    var xml:XML;
    var loader:URLLoader = new URLLoader();
    var request:URLRequest = new URLRequest(phpLoc+"?location="+escape(xmlLoc) );
    loader.addEventListener(Event.COMPLETE, onXMLLoaded);
    loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
    loader.load(request);
    function onIOErrorHandler(e:IOErrorEvent):void {
        trace("There was an error with the xml file "+e);
    function onXMLLoaded(e:Event):void {
        trace("the rss feed has been loaded");
        xml = new XML(loader.data);
        // set to string, since it is passed back from php as an object
        xml = XML(xml.toString());
        xml_txt.text = xml;
    PHP (loadXML.php in www.domain1.com):
    <?php
    header("Content-type: text/xml");
    $location = "";
    if(isset($_GET["location"])) {
        $location = $_GET["location"];
        $location = urldecode($location);
    $xml_string = getData($location);
    // pass the url encoded vars back to Flash
    echo $xml_string;
    //cURLs a URL and returns it
    function getData($query) {
        // create curl resource
        $ch = curl_init();
        // cURL url
        curl_setopt($ch, CURLOPT_URL, $query);
        //Set some necessary params for using CURL
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       //Execute the curl function, and decode the returned JSON data
        $result = curl_exec($ch);
        return $result;
        // close curl resource to free up system resources
        curl_close($ch);
    ?>

    I think you might be right about permissions/settings on the server for php. Unfortunately I'm not allowed to adjust them.
    So I wrote my own script - this time I used file path instead of http address of the XML file.  It works fine in my case.
    Here it is:
    XML file on domain2.com:
    <?xml version="1.0" encoding="UTF-8"?>
    <gallery>
        <image imagePath="galleries/gallery_1/images/1.jpg" thumbPath="galleries/gallery_1/thumbs/1.jpg" file_name= "1"> </image>
        <image imagePath="galleries/gallery_1/images/2.jpg" thumbPath="galleries/gallery_1/thumbs/2.jpg" file_name= "2"> </image>
        <image imagePath="galleries/gallery_1/images/3.jpg" thumbPath="galleries/gallery_1/thumbs/3.jpg" file_name= "3"> </image>
    </gallery>
    swf  on domain1.com:
    var imagesXML:XML;
    var variables:URLVariables = new URLVariables();
    var varURL:URLRequest = new URLRequest("MyPHPfile.php");
    varURL.method = URLRequestMethod.POST;
    varURL.data = variables;
    var MyLoader:URLLoader = new URLLoader;
    MyLoader.dataFormat =URLLoaderDataFormat.VARIABLES;
    MyLoader.addEventListener(Event.COMPLETE, XMLDone);
    MyLoader.load(varURL);
    function XMLDone(event:Event):void {
        var imported_XML:Object = event.target.data.imported_XML;
        imagesXML = new XML(imported_XML);
       MyTextfield_1.text = imagesXML;
       MyTextfield_2.text = imagesXML.image[0].attribute("thumbPath");  // sample reference to attribute "thumbPath" of the first element
    php file on domain1.com:
    <?php
    $xml_file = simplexml_load_file('../../domain2.com/galleries/gallery_1/MyXMLfile.xml');  // directory to XML file on the same server
    $imported_XML = $xml_file->asXML();
    print "imported_XML=" . $imported_XML;
    ?>
    Regards
    PS: for those who read the above discussion: the first and the second script work but you must test which one is better in your situation. The first script will also work between two domains on different servers. No cross domain policy file needed.

  • Why is code to get center of image not working?

    Hey there. I have am trying to establish the center of the imags that load so that I can put them in the center of the stage. I am doing this as each image is a different size.
    Here is the code i have gotten to work before but its not working now and I have been searching to find what I have done wrong with no luck. : (
    Would you look it over and maybe you will see what I am doing wrong?
    public function placePicture(e:Event = null):void {
         rawImage = imageData.image[imgNum].imageURL;
         lastImageIndex = imageData.*.length() - 1;
         imageLoader = new Loader;
         imageHolder = new Sprite;
         imageLoader.load(new URLRequest(rawImage));
         imageLoader.x -= imageLoader.width/2; //this should set the image to the center no?
         imageLoader.y -= imageLoader.height/2;
         imageHolder.x = 640; //this is the center of the stage
         imageHolder.y = 100;
         imageHolder.addChild(imageLoader);
         masterHolder.addChild(imageHolder);    
    The result when I publish is the picture comes on stage but the top left corner goes to 640 instead of the center of the image going to 640.
    I tried several variations of this all with the same result:
    imageLoader.x = -1*imageLoader.width/2;
    I tried using setRegistrationPoint with the following tutorial: http://flashscript.ca/set-registration-as3.php
    and I tried doing all of the above by inserting the loader into a sprite and then applying the code to the sprite and then adding that sprite to another sprite and putting that at 640 and not inserting it in another sprite and trying to straight up put the existing sprite at 640 (hopefully that all makes sense). And I have tried to put it to width/3 and nothing different happens.
    If you have any other ideas or can see what I am doing wrong I would really be gratefull for some tips! : )
    Thanks for any help!
    oh, and I am getting no errors on this.

    the image's width and height are not available until loading is complete.  ie, use a complete listener/listener function.

  • Is it possible to create a forum in flash??

    I'm creating a flash website and is this possible without using any kind of server side language, if so how do you do it,
    if not how do i integrate my code in my flash?
    tnx in advance...

    You will need server-side support, most efficiently in the form of MySQL (or similar DB) and PHP (or similar server-side scripting).  You can probably find some tutorial info if you search Google using terms like "AS3 PHP MySQL tutorial".

Maybe you are looking for