A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Simple FLASH + MYSQL ?

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    1

    Simple FLASH + MYSQL ?

    I'm curious to know how I can properly refresh the contents of a mysql database (datagrid component) after I have inserted or deleted my desired
    query upon the release of a button action. Everything works properly as far as inserting and deleting data, its just that I'm having
    difficulty in displaying the updated results in the datagrid upon a button action (refreshing the grid).

    Heres what I have to display the contents of the mysql database in the flash datagrid component...

    var myGridArray:Array = [];
    myGridArray.push({status:"loading data..."});
    myGrid.dataProvider = myGridArray;
    var sender:LoadVars = new LoadVars();
    var receiver:LoadVars = new LoadVars();

    receiver.onLoad = function(ok){
    if(ok){
    myGrid.removeAllColumns();
    myGrid.removeAll();
    for(var i =1;i<=receiver.total;i++){
    receiver["dataPacket"+i] = receiver["user_data"+(i)].split("|");
    var _id:String = receiver["dataPacket"+i][0];
    var _username:String = receiver["dataPacket"+i][1];
    var _age:String = receiver["dataPacket"+i][2];
    myGridArray.push({ Name:_username, Age:_age });
    delete(receiver["user_data"+i]);
    }
    myGrid.dataProvider = myGridArray;
    //
    total = receiver.total;

    }else{
    myGrid.removeAllColumns();
    myGrid.removeAll();
    myGridArray.push({status:"No data was found!"});
    myGrid.dataProvider = gridArray;
    }
    }
    sender.sendAndLoad("http://localhost/get_users.php",receiver,"POST");

    As you can see, this is a rather simple query, Name and Age.

    Now this is what I'm using to add data to it...

    addButton.onRelease = function() {
    //
    sender.addName = myName.text;
    sender.addAge = myAge.text;

    sender.sendAndLoad("http://localhost/add.php",receiver,"POST");
    }

    And this is what I'm using to Delete data from it...

    deleteButton.onRelease = function() {
    //
    sender.delName = _root.columnName;
    sender.delAge = _root.columnAge;

    sender.sendAndLoad("http://localhost/delete.php",receiver,"POST");
    }

    Now this works! However, how can I refresh the datagrid upon releasing the addButton/deleteButton? Rather than restarting my flash application or having
    to delete my browser temporary files and refreshing the screen or needing an extra button for this matter.


    Possibly write a timer and call the reciever.onload function after a desired count? Seems rather unprofessional though.

    Any comments on this matter would be greatly appreciated!

  2. #2
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    Not sure what you mean by releasing the button; however, a timer would work as well as anything else. It really depends upon the application. Consider how timely this data needs to be, and how many people are accessing it. Does this have to scale up? If you're just getting the most recent pizzas people ordered off a list, and updating it every minute or two, then setting a timer shouldn't be a problem. If, on the other hand, you need the last 100 or so transactions off of a table of thousands that are being updated constantly, and you need to ping the server for that every couple of seconds, then I'd (a). suggest using AMFPHP which is a lot faster, and (b). suggest indexing your time and [id] columns and writing a piece of code that passes mySQL the last known id on each poll, and only selecting things later than that, sending them back to Flash, and having an intermediate step in Flash where the new lines are added to (and possibly old lines popped off of) the data array before repopulating the datagrid with it. If you were talking about a huge amount of incoming, ongoing data, you might want to actually open a socket connection to the server and let it be pushed.

    Not enough info to really know what you're after with this. But no; using a timer is not in itself a bad way of doing it, it's what's called polling the server, and if your packets are small enough (which often requires some reduction to exclude the information you already have in the client) then it can be executed well.
    The Strike Agency
    http://www.theStrikeAgency.com

    StrikeSapphire -- The Original Bitcoin Casino
    https://strikesapphire.com
    (not available in the US)

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