#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    2
    Rep Power
    0

    ActionScript 3 Display From PHP Variable.


    What do i do so that flash display all the results from php in the looped movieclips?

    Can someone help me? I'm trying to extract out the data from php using array so that every rows have different data according to the rows in mysql. But right now only one data from a row of mysql seem to be displayed. However when i traced.. it displayed all the data. But how do i assign to the
    looped newContainer such tht, each of the newContainer have different rows of data?


    What should I do so that the each newContainer have different event names, dates, slots left coming from the 8 results respectively? And not just one newContainer displaying only one result the data. I have like 8 rows to be displayed in flash from my sql..

    this is my code..

    import flash.events.MouseEvent;
    import flash.events.Event;
    import fl.motion.MotionEvent;
    import flash.net.URLVariables;
    import flash.display.MovieClip;
    import flashx.textLayout.elements.Configuration;



    var ctr:int = 0;
    var nowate = new Date();


    var myurl:String = "http://localhost:8888/eventspictures/getdata.php";

    var containers:Array = [];

    var scriptLoader:URLLoader = new URLLoader();
    var scriptRequest:URLRequest = new URLRequest();



    scriptRequest.url = myurl + "?ck=" + now.getTime();

    scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccess);
    scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleError);



    scriptRequest.method = URLRequestMethod.POST;
    scriptLoader.load(scriptRequest);


    function handleLoadSuccess(evt:Event):void
    {

    for (var j:Number = 0; j <4; j++)
    {
    var newContainer:MovieClip = new con();
    newContainer.name = String(ctr);

    newContainer.y = j*80 +65;
    newContainer.x= 16;

    stage.addChild(newContainer);
    containers.push(newContainer);






    var variables:URLVariables = new URLVariables(evt.target.data);
    trace(variables.output);


    var parse:String = variables.output;
    var parsed:Array = parse.split("<|>");

    var tab:String = ' ';
    var eventname:String = '';
    var date:String='';
    var slotsleft:String='';



    // different variable names to assign to different column names(etc; eventname, date, slotsleft)
    // loop through.. start from O

    for (var i:Number = 0; i<parsed.length-1; i++)
    {
    trace(parsed[i]);

    var item:String = parsed[i];
    var itemarray:Array = item.split(",");

    eventname += itemarray[2] + tab + "<br>";
    date += itemarray[3] + tab;
    slotsleft += itemarray[4] + tab;






    trace(eventname);





    }


    }



    newContainer.eventname_txt.htmlText = eventname;
    newContainer.date_txt.htmlText= date;
    newContainer.slotsleft_txt.htmlText=slotsleft;




    //slotsleft_txt.x = 270;
    }
    function handleError(evt:IOErrorEvent):void
    {
    }

    backbutton_mc.addEventListener(MouseEvent.CLICK, goHomePage);


    function goHomePage (evt:Event):void{


    gotoAndPlay("dashboard");
    for (var j:int = 0; j < containers.length; j++)
    {
    stage.removeChild( containers[j] );

    }


    }



    stop();



    or issit a php error?

    Here's the php code..

    <?php

    $_POST['orderby']= "date";
    $_POST['sortby']= "asc";

    $host = 'localhost'; // or '127.0.0.1'
    $user ='root'; //FTP login name if own server
    $password= 'root'; // FTP PASSWORD

    $connection = mysql_connect($host,$username,$password);

    $connection = mysql_connect($host, $user, $password);
    if (!$connection) {
    echo 'error=' . mysql_error() . '&';
    die('Could not connect ' . mysql_error());
    }
    //echo 'Connected successfully' ."\n<br />";

    // * means everything

    $database = 'eventspictures';

    $db = mysql_select_db($database, $connection);
    if (!$db) {
    echo 'error=' . mysql_error() . '&';
    die ('Not connected : ' . mysql_error());
    }
    //echo 'Database Selected successfully'."\n<br />";

    //3. Build a query


    if ($_POST['orderby']){

    $query= 'select * from eventsdata order by '.$_POST['orderby'].' '.$_POST['sortby'];

    }else{

    $query= 'select * from eventsdata';
    // select everything from eventsdata

    }





    $results = mysql_query($query, $connection) or die('Query not run' . mysql_error());

    //echo 'Query run<br>';

    //4. Fetch data and 5. Loop to display data

    /*while($row = mysql_fetch_array($results)){



    extract ($row);
    echo "$id, $admin, $name \n<br>";
    }
    */



    //6. format for flash



    while($row = mysql_fetch_array($results)){

    extract ($row);
    $output .= "$id,$image,$eventname,$date,$slotsleft".'<|>';


    }

    echo 'output='.urlencode($output);






    //7. database close
    mysql_close($connection); // only if you use mysql_connect()
    ?>
  2. #2
  3. No Profile Picture
    Gotta get to the next screen..
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2003
    Location
    Legion of Dynamic Discord
    Posts
    6,675
    Rep Power
    3164
    Hi, did you get this sorted out? It's hard to tell what's going on, could you repost your code but wrap it in [code][/code] tags so all the indenting is in place. One thing I did notice was that you can move this bit outside the loop as it doesn't need to be done multiple times:

    Code:
    var variables:URLVariables = new URLVariables(evt.target.data);
    trace(variables.output);
    
    var parse:String = variables.output;
    var parsed:Array = parse.split("<|>");
    
    var tab:String = ' ';
    var eventname:String = '';
    var date:String='';
    var slotsleft:String='';
    You say it traces correctly but you don't say which trace, you have more than one. I'm curious what this one traces: trace(parsed[i]); as that would tell us if it is correctly parsing your data.
    Quis custodiet ipsos custodes?

IMN logo majestic logo threadwatch logo seochat tools logo