A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: PHPObject superheros please save me.

  1. #1
    freelance web badass
    Join Date
    Nov 2000
    Location
    denton
    Posts
    16

    PHPObject superheros please save me.

    I am building dynamic graphs using PHP mySQL and PHPObject.

    I have setup a directory under the webroot called classes and told the Gateway.php to us that.

    I have made my own class that will pull a record from my mySQL db.

    I can't seem to understand what I am doing wrong. I can't tell if the class is getting invoked.

    Is there a way I can trace the data when the swf is executed on the server?

    Should I be naming my dynamic text vars a certain way?

    I installed the PHPObject.mxp in flash. Does this mean that when the swf is generated the PHPObject.as is automatically included in the swf? Or do I have to send that file up to the server?

    if you go to roisports.com/ROIChart.html
    you can see that I have one graph that is supposed to use the data that PHPObject grabs.
    There should be a number next to the dollar sign on the bottom graph. The other 2 graphs are loaded with static data.


    PHP Code:

    <?php class records 
    function 
    getrecord($getrecord
    {
     
    $db_name "roisport_ROICharts";
     
    $connection = @mysql_connect("localhost""roisport""missalic") or die("Could not connect to database");
     
    mysql_select_db($db_name$connection) or die("Count not select database");
     
    $query "SELECT * FROM ROI_Data WHERE id = '$getrecord'"$q_result mysql_query($query); 
    return 
    mysql_fetch_row($q_result); 


    ?>
    the file is called records.php

    In my AS I have the following code

    // import the library
    #include "PHPObject.as"

    // set up gateway url and key
    _global.defaultGatewayUrl = "http://localhost/Gateway.php";
    _global.defaultGatewayKey = "secret";

    // creates the object
    myFoo = new PHPObject("records");

    // sets up responder
    myFoo.getrecord_onResult = function(result)
    {
    id.text = result[0];
    sport.text = result[1];
    money.text = result[2];
    gamedate.text = result[3];
    win.text = result[4];
    loss.text = result[5];
    }


    // invoke remote method passing in the recordid as parameter
    myFoo.getrecord("3");



    // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // Show data output
    // dollar amout that will be dynamic later on
    m=money.text;
    trace(money.text);
    // domain of our graph is the total amount
    total=1000;

    // create color object for the bar and dollar sign and dynamic text
    barColor = new Color (_root.ncaa_chart.bar);
    dollarColor = new Color (_root.ncaa_chart.dollar_sign);

    // set dText
    _root.ncaa_chart.ncaa_amount=m;

    // set color based on dollar amount
    if (m>0) {
    barColor.setRGB(0x468455);
    dollarColor.setRGB(0x468455);
    } else {
    barColor.setRGB(0xCC0000);
    dollarColor.setRGB(0xCC0000);
    m=m*-1
    }
    // calculate percent that will be the width of the bar
    percent=Math.round((m/total) * 100);

    // set width of bar
    _root.ncaa_chart.bar._width = 150*(percent / 100);



    I prefer syrup

  2. #2
    Member
    Join Date
    Aug 2003
    Posts
    30
    Try using the onInit function when you initialize the phpObject:
    code:

    In my AS I have the following code


    // make sure the three files are in the right folder! ('PHPObject.as', 'PHPSerializer.as', and 'PHPLoader.as')
    // mine goes here...
    // C:\Documents and Settings\Administrator\Local Settings\Application Data\Macromedia\Flash MX 2004\en\Configuration\include

    // import the library
    #include "PHPObject.as"

    // set up gateway url and key
    _global.defaultGatewayUrl = "http://localhost/Gateway.php";
    _global.defaultGatewayKey = "secret";

    // creates the object
    myFoo = new PHPObject("records");

    //*******************
    // do this!
    myFoo.onInit = function() {
    // assuming you're echoing something out in your class constructor
    trace(this.getOutput());
    // now, you have to call getrecord, or you'll never see the onResult code below
    //(even if you call it in your php constructor). It's safe to call it here because
    //we know the phpObject has initialized.

    myFoo.getrecord([param1,param2,etc]);


    }
    //
    //*******************



    // sets up responder
    myFoo.getrecord_onResult = function(result)
    {
    id.text = result[0];
    sport.text = result[1];
    money.text = result[2];
    gamedate.text = result[3];
    win.text = result[4];
    loss.text = result[5];

    // put the rest of your code in here so you know you have the data you need


    }




    That should get you started. My general rule of thumb is to make sure my php classes are solid first. At the bottom of your class declaration, create an instance like so:
    PHP Code:
    function debugObject($ob) {
         echo 
    "<pre>\n";
         
    print_r($ob);
         echo 
    "</pre>\n";
    }
    $object = new records();
    debugObject($object); 
    Open your php file in a browser and you'll see a nicely formatted version of your object (or array, or whatever variable you pass to the debugObject function.) Once you know you've got what you need, then move on to the flash side.

    Good luck, let me know how it worked.
    Last edited by if6were9; 02-17-2004 at 01:24 AM.

  3. #3
    Member
    Join Date
    Aug 2003
    Posts
    30
    Also, if you use the debugObject function, make sure you comment it out before testing in flash. It will confuse the movie!

  4. #4
    freelance web badass
    Join Date
    Nov 2000
    Location
    denton
    Posts
    16

    Cool

    Thanks

    I added that function and it seems to work so I put it in the right spot. However there are no results I will have to play with the SQL and make sure its grabbing info. The only thing I am worried about is that the 2 main pieces of data i need are money and gamedate. And since it will return them as strings it could get hairy.

    So about the include files. Should I copy those to my server or will flash add them to the swf when it gets exported?

    I am assuming flash should but If they are on the server will it cause problems?

    Oh also will PHPOBject handle multiple arrays. For example I have changed my SQL code to get more than one row in the db.
    I realize the mysql_fetch_row will only grab one row. Would php freak out if I returned more than one row. What would be the best way of attacking that.
    Last edited by mugafuga; 02-17-2004 at 11:59 AM.
    I prefer syrup

  5. #5
    Member
    Join Date
    Aug 2003
    Posts
    30
    The include files will be included inside the movie when you publish it, so there's no need to put them on the server. You will need the Gateway.php on your server though.

    You can pass as much as you want to phpObject. Objects, multidimensional arrays, etc. Once again, build it into your classes in php and make sure it's solid, then pass it to flash... I've passed over 30k of raw data in the form of objects and object arrays and it handles it all beautifully.

    Pass objects and arrays rather than single strings because if they're essentially already in neat little packages, they're easier to manage/manipulate. Hope this helps.

  6. #6
    freelance web badass
    Join Date
    Nov 2000
    Location
    denton
    Posts
    16

    My object is oh so empty

    thanks for all the help if6were9.

    Ghostwire's site is pretty vague.

    I have modified my code so it will just send an entire query. I even told it to just grab everything in the table. It still will not show any debug info.

    Check out this link
    http://www.roisports.com/classes/records.php
    it basically executes this code below

    I really need it to send me more than one row to make my charts work and I thought the reason it wasn't showing any info was because of my sql but that isn't the case. Well as far as I can tell.

    PHP Code:
    <?php
    class records
    {
    function 
    getrecords()
    {
    $db_name "roisport_ROICharts";
    $connection = @mysql_connect("localhost""roisport""missalic") or die("Could not connect to database");
    mysql_select_db($db_name$connection) or die("Count not select database");
    $query "SELECT * FROM ROI_Data WHERE 1";
    $q_result mysql_query($query);
    return 
    mysql_query($q_result);
    }

    }

    function 
    debugObject($ob) { 
         echo 
    "<pre>\n"
         
    print_r($ob); 
         echo 
    "</pre>\n"

    $object = new records(); 
    debugObject($object);
    ?>
    thanks
    I prefer syrup

  7. #7
    freelance web badass
    Join Date
    Nov 2000
    Location
    denton
    Posts
    16

    Did you read all of my last message?

    I have made some more changes to my PHP

    but it will still not show anything in the debug

    I have used the same connection info and query code on a different php file and it the query is executing.

    I can't figure out why your debug code you gave me will not show anytyhing in the object.

    PHP Code:
    <?php
    class records
    {
        function 
    getrecords()    {
            
    $db_name "roisport_ROICharts";
            
    $connection mysql_connect("localhost""roisport""missalic") or die("Could not connect to database");
            
    mysql_select_db($db_name$connection) or die("Could not select database");
            
    $query "SELECT * FROM ROI_Data WHERE 1";
            
    $results_query mysql_query($query);
            if (
    $results_query) {
                echo(
    "query completed successfully");
            } else {
                echo(
    "An error has occured");
            } 
            return 
    $results_query;
            
    mysql_close($connection);
        }
    }
    // a function to debug the ho
    function debugObject($ob) { 
         echo 
    "<pre>\n"
         
    print_r($ob); 
         echo 
    "</pre>\n"

    $myObject = new records(); 
    debugObject($myObject);
    ?>
    they new link is http://www.roisports.com/records.php

    If there was a problem with the connection or query then i would have seen an echo error but nothing comes up but the empty object.

    Any suggestions?
    I prefer syrup

  8. #8
    Member
    Join Date
    Aug 2003
    Posts
    30
    Sorry it took so long to get back... Your query looks wrong, what about just "select * from ROI_Data" ??

    Just because you don't get an error, doesn't mean it grabbed anything...

    Try running your query in the database and make sure you're getting the result you want first. I'll check back on it later tonight.

  9. #9
    freelance web badass
    Join Date
    Nov 2000
    Location
    denton
    Posts
    16

    I did that already

    Thanks for the help you have given me.

    I did verify the query works.

    I have run the same query in multiple php templates.

    It runs. It pulls data.

    Regarless....

    PHPObject is too much of a hassle. I figured out how to do it by just printing out the results and using loadVariables to get the data. it works great but the only problem is the server overhead. I have it pulling my php file simultaneously for the 5 graphs in my swf right now. But only half of my Movie Clips get the data for my graphs. I am still trying to find a work around for that.

    http://www.roisports.com/flash/ROIChart.html

    check it out. Tell me if all of the graphs work for you. Any ideas?

    I hope ver 1.5 of PHPObject will come with better documentation and actual tutorials that work.

    I have even tried setting up the tutorial exactly the way they have it on Ghostwires site for the card function they use. It doesn't work when I try it.

    Ho hum




    I prefer syrup

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center