This page is no longer updated - please visit http://ghostwire.com Thank you!
 

« PHPObject »
An Opensource Alternative to Flash Remoting
Current Release
Readme
Notes
Journal
Archives

Readme
Saturday April 19, 2003

Using PHPObject

It shouldn't be difficult to learn PHPObject if you are familiar with OOP (you are calling a method of a php class anyway, so your php must already be written in OOP). The basic idea behind PHPObject is to link a local flashmx object with a remote php class, so that the methods of the php class can be called by flash.

When a PHPObject is created, it 'inherits' its default properties from the remote php class. Subsequently the object can change these properties, and it can also have other properties declared within flash. When it calls a remote method, its properties are communicated to the server so that the remote class will have the same information as flash. Effectively, your flash object behaves as usual, except now it has an extended set of remote methods that it can call on the server.

Even if you are not familiar with OOP (hey, I am no expert too), the PHPObject's syntax should be easy to pick up...

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

// we set up the gateway first
_global.defaultGatewayUrl = "http://mydomain.com/services/Gateway.php";
// and the key
_global.defaultGatewayKey = "secret";

// creates a new object and link it to a remote PHP class
myFoo = new PHPObject("Foo");

myFoo.onInit = function() {
    // here we define what to do after the object initializes
    // upon initialization, the object is populated with the
    // default properties of the remote class

}

myFoo.onResult = function(result) {
    // here we define the default responder
    // code to execute upon receiving result from server
    // only executes if no specific responder was defined

}

myFoo.doRemoteMethod_onResult = function(result) {
    // here is a specific responder that triggers when the
    // doRemoteMethod is called and result received from server
    // will not trigger default onResult handler

}

// call the remote method like you would for a local method!
myFoo.doRemoteMethod(param1,param2,...)

* You may also like to read this if you are already using flash remoting.

Posted by sunny at April 19, 2003 11:55 PM

 

Comments

Have you thought of queing execution?
I love the PHPObject but my main problem is that I do not want to check whether the object is busy when issuing a new remote command. I was about to add it myself but wanted to check if you have any similar plans.

Cheers,
Tuomas

Posted by: Tuomas Artman at April 24, 2003 05:02 PM

Hi Tuomas, what about sequential invoking?
http://ghostwire.com/archives/phpobject/000006.html

Perhaps if you can explain a little more on what you mean by 'queing execution' I will see what I can do. You also shouldn't need to 'check whether the object is busy', because when the results come back, you catch them with myObj.methodName_onResult

Posted by: sunny at April 24, 2003 05:16 PM

Hi Sunny, sequential execution is a good feature but it does not solve the problem.

This is best explained via an example:
An interface has two buttons (and input fields), which both execute a rather heavy database-query and display the result somehow. Both buttons use the same PHPObject to send and retreive the query.

Now if the user is quick enough he executes the first query and moves on to execute the second query while the PHPObject is busy. What happens is that the second query never gets executed.

To overcome this problem the programmer would have to remember which commands the user has issued, and in the onResult-event check if there are any outstanding requests, using for example an array to store all subsequent requests the user has made while the PHPObject was busy.

This I think would be best done by the PHPObject itself. It could store all issued requests in an array and on the onResult-event check if there are any outstanding request.

Posted by: Tuomas Artman at April 24, 2003 05:38 PM

Hi Tuomas, the 'sequential invoking' feature already cater for this:

----------
myObj = new PHPObject("QueryClass");

query1_btn.onRelease = function() {
    myObj.getResults(query1_txt.text);
    myObj.delayExecute();
}

query2_btn.onRelease = function() {
    myObj.getResults(query2_txt.text);
    myObj.delayExecute();
}

myObj.onResult = function() {
    this.execute();
}
----------

The first time either button is clicked, the remote method is executed, and subsequent clicks only cause the methods to be stored. Then onResult, the stored methods are pushed to the server. And the cycle starts all over...

But if I may comment, isn't it quite strange to allow the users rampant clicking?

Posted by: sunny at April 24, 2003 06:11 PM

Thanks, I didn't think of that.

What comes to rampant clicking, I'm developing an app which updates user input to a database. The thing is that I don't want to lock down the UI at any time...

Posted by: Tuomas Artman at April 24, 2003 08:30 PM

Have you seen this? Might help you create some detailed documentation that would allow other programmers to extend PHPObject, or port it to other languages:
http://www.gskinner.com/gmodeler/app/run.asp

It's a UML editor, built in Flash, pretty cool.

Posted by: Andrew Blair at April 26, 2003 01:16 AM

Hey Sunny,

Can you make it so that we can use one set of .as files and the Gateway.php file from any subfolder? I'm building an intranet that has .fla's that will use PHPObject from various subfolder path levels. This doesn't jive with the current version of the program. Right now, I need to make duplicates of the files, which will get messy, especially if you release an update.

Cheers,
Andrew

Posted by: Andrew Blair at April 26, 2003 04:51 AM

Hi Andrew, thanks. Yea, I saw that cool app some time ago, but haven't had the time to play with it much yet. I am still refining some of the ways PHPObject does things and will put up proper documentation later. For now (and I think for a while), the notes on this website will be the only documentation available.

Regarding the file locations, please note that the Gateway.php is for the server only. The .as file you #include only once in each project (in the topmost movie). If you save the .as files in the include directory of Flash MX, that will allow you to include the file from any directory. In windows, the include directory is usually "C:\Program Files\Macromedia\Flash MX\Configuration\Include"

I will pack the next release as a .mxp and it will install the files in the correct directory.

Posted by: sunny at April 26, 2003 08:35 AM

PHPObject looks superb, but I might just wait till the release of PHP5 before doing any "real-world" stuff with it, as the OOP API will be quite different from the current one, which will probably require some changes in how PHPObject calls remote methods.

Is PHPObject based on amfPHP, or was it developed from scratch?

Posted by: han_hoof at May 6, 2003 04:17 PM

Thanks han, PHPObject was developed from scratch and doesn't use AMF:
http://ghostwire.com/archives/phpobject/000009.html

As for PHP5, I guess there will always be new versions, but life goes on :)

Anyway, I doubt the new OOP API in PHP5, even if drastically different from the one in PHP4 will have any great impact:
(1) Like any good software, PHP5 must have backwards compatibility, it doesn't make sense to say that with PHP5 all existing PHP4 code won't work anymore.

(2) It will be long before PHP5 ships and EVERY server upgrades to PHP5.

(3) The only thing PHPObject has to change, if at all, will be the PHPObject Gateway (and that comes back to the question of whether PHP5 will really render all PHP4 scripts useless).

Posted by: sunny at May 6, 2003 04:56 PM

Hi Sunny,

I have been experimenting with PHPObject. I have it working on my host's linux server but I cannot get it to run on my windows 2K machine at home. I would like to get it running at home so I can avoid having to upload the swf file every time I want to check it.

I am sure this is a dumb question but can you give me any hints as to what I might be doing wrong? The include files are in the right place. The gateway path is "http://computername/gateway/Gateway.php" and the class "Foo" is in the gateway directory.

I also tried with the gateway path "http://localhost/gateway/Gateway.php" and that didn't work either.

Thanks,

Jay Lenner

Posted by: Jay Lenner at May 16, 2003 10:48 AM

Hi Jay, I have replied to the email you sent which has the same contents as your post above. Sorry I can't help you with this. All I can say is I use a WindowsXP running apache on my localhost and it works fine. Actually, I don't really understand why you have to upload the swf to check it - you can test it locally if you use absolute gateway path.

Posted by: sunny at May 16, 2003 01:04 PM

I cant seem to get it to work right on XP and apache ! I think im just being dumb but dont ya gota tell it where u put the Foo.php file ? cos it dont load the $story var or anything

Posted by: Ric at May 16, 2003 05:51 PM

Hi Ric, the Foo.php file (and your other class files) can be put in the same directory as the Gateway.php, or if you want you can put them in another directory (but then you will have to configure the path in Gateway.php). Let me know the version of the PHP and the flash player you are using. Thanks.

Posted by: sunny at May 16, 2003 08:58 PM

Hi!
I had problems getting php object to work on my machine so here is a tip:
If you have set the error reporting leven in your php.ini to include notices (as it is on my dev machine), the gateway won't work, as the gateway.php sometimes uses undefined variables ($this->utf8encode, fe). So php will output a notice and subsequently can't modify the header information. To circumvent this problem add the following at the top of gateway.php:
error_reporting(E_WARNING); (or lower error level).
This way you can keep your default level, but just reduce the level for gateway.php

Cheers
HTH
Martin

Posted by: martin at May 17, 2003 12:44 AM

Thanks Martin! That is a great feedback. I will check on error_reporting/undefined variables and see how to better manage that in the next release.

Posted by: sunny at May 17, 2003 09:48 AM

Thank Martin! It worked for me too. Sunny, thanks for your efforts as well.

Jay

Posted by: Jay Lenner at May 17, 2003 11:38 AM

Glad I could help :-)
Thanks sunny for the great effort you put in this wonderful project! I ran over it by chance and I must say I'm impressed!

Thumps up
Martin

Posted by: martin at May 17, 2003 03:44 PM

I've been trying to get this working for about a week now... I have NO idea what I'm doing wrong. I've tried absolutely everying to get this working. When I saw martin's post about the error_reporting, I thought maybe my search was over.... but no :(
This still won't work, and I'm totally positive that I'm doing everything right... so then I have no idea what the problem could be.
The example doesn't even work... And I do have the gateway url set correctly, and the key is right. And I have Foo.php in the same directory as Gateway.php... I've tried moving Foo.php all around and setting $classdir to where I have it, but no luck.

Well, I'm VERY confused, and there's nothing I'd love more than to get this to work. PHPObject is EXACTLY what I've been looking for.

So if you have any ideas, any at all, please reply.

Thanks,
Phil

Posted by: phil at May 19, 2003 11:48 AM

Hi, you should provide details on your system setup - the browser, the version of the PHP and the flash player you are using, etc. Your post doesn't provide any information that could possibly let anyone help you. Thanks.

Posted by: sunny at May 19, 2003 12:35 PM

Sorry.

Running WindowsXP with Apache 2.0.45.
PHP version 4.3.1.
Using FlashMX. Flash player 6.
I keep everything as up-to-date as possible.
All my php scripts work, all my Flash movies work... but they don't seem to work well together :(

Any help would be greatly appreciated.

Thanks again,
Phil

Posted by: phil at May 19, 2003 01:03 PM

Hi Phil!
What I did first to investigate on the problem was the following:
1) run the flashscript. Then look in the access log of apache, if there is a 200 statuscode for gateway.php. If it is, you know that the flashmovie successfully connected to the gateway. If there isn't look for a 400 in the error log. If you find that, your path is somehow false.
2) if possible set
always_populate_raw_post_data = On
in your php.ini. Now the $GLOBALS['HTTP_Raw_Post_Data'] is always set.
Then construct a simple html form with maybe an edit control and a submit button. Set the method of the form to post, and gateway.php as the post target.
Submit the form and look for the output of gateway.php.
Maybe you or someone on this site, may have a clue whats goin on..

Cheers
and luck
Martin

Posted by: martin at May 19, 2003 11:58 PM

Hey martin,
Well I did everything you said.
Flash IS calling Gateway.php... I get 200 statuscode.
I added that line to my php.ini, and when I post to Gateway.php, it spits out this crazy string.

0O%3A8%3A%22stdClass%22%3A1%3A%7Bs%3A7%3A%22_loader%22%3BO%3A8%3A%22stdClass%22%3A1%3A%7Bs%3A11%3A%22serverError%22%3Bs%3A35%3A%22Error+-+Please+provide+a+valid+key%0A%22%3B%7D%7D

Still no luck with PHPObject working :(
I have no clue what's going on with this...

Thanks,
Phil

Posted by: phil at May 20, 2003 09:43 AM

I'm using Flash version 6.0.21.0
Is that a problem?

thanks,
phil

Posted by: phil at May 20, 2003 02:32 PM

:(
Of course that is the problem - I have already posted about upgrading flash player several times on this website! With that version you will have problems even if not using PHPObject! I believe at least v6.0.65.0 is required.

Please use this link, it will help you update all your flash players, including your authoring player:
http://www.macromedia.com/support/flash/downloads.html

Posted by: sunny at May 20, 2003 02:43 PM

Ughgh...
Well I updated to 6.0.79.0
Had my hopes up... but still no luck :(
Good god what in the world is wrong here???????
How annoying.
I'm SO frustrated I can't even describe...

Sorry... I'll just wait til a next version I guess and see if maybe that works. I've wasted enough of your guys' time.

thanks for your help though, i appreciate the effort,
phil

Posted by: phil at May 20, 2003 03:14 PM

Hello
I am having a problem with my PHPObject, I know very little about PHP and Flash, so I am not an expert. Wondering if you guys can help me get it working. Here is the problem:
I config my gateway.php & test.fla and tried testing with the example that was included (test.fla, foo.php). But I came to a point about PHPObject.mxp, did not really understand how to run it so I tried editing test.fla (#include "PHPObject.as") -> (#include "PHPObject.mxp"). I don't think it actually connected to Gateway.php or work...

Window XP
Apache 1.3.20
PHP 4.2.1
Flash MX 6

Ty in advance,
John

Posted by: John at May 20, 2003 03:28 PM

Oh dear... I think I should put up a discussion forum instead, this page is getting too long...

Phil, if you are out of luck with this version, I doubt the next one will help... I suggest you do a clean reinstall. Do not make any changes to the files and try again; I am pretty sure in your case it was because of the player version.

John, you need to run the PHPObject.mxp (double-click it). It is a Macromedia Extension file.

Posted by: sunny at May 20, 2003 03:36 PM

Ahhh after deeply looked into Macromedia Extension... I just found out that "Manage Extensions" is disabled therefore I cannot double click PHPObject.mxp or manually... Can you guys or Sunny help me on this one?

John

Posted by: John at May 21, 2003 02:35 AM

Hehe sorry for my silly post, I guess I did not look deep enough. Since I did now, things have been working. Again I am sorry for my posting.

John

Posted by: John at May 21, 2003 03:05 AM

Well sunny, I'm just screwed.
No way around it.
I even went as far as to completely uninstall flash, apache, php, everything... and do a complete reinstall of it all, and of course the flash player update......
Still screwed.....................
Thanks for all your help, but there's no fixing this man... I'm 100% sure I'm doing everything correctly, and it still doesn't work...
So... I'm pretty pissed you know? PHPObject is EXACTLY what I've been looking for, and it seems I'm the only person that can't get it to work... and I consider myself pretty computer-literate, which makes it all the more annoyyyyyying.

Uggghhg....
Later,
Phil

Posted by: phil at May 21, 2003 05:06 PM

Well, Phil that's unfortunate...
Say... just in case... did you perhaps forget to install the .mxp (like John)?

Posted by: sunny at May 22, 2003 12:57 PM

I said I was computer-literate didn't I?
Yeah of course I installed the .mpx
Even tried putting the .as's in the same directory as the .swf...
I've tried just about everything imaginible at this point... I'm at the end of the road, and with nothing to show for it :(
I know other people have gotten it to work, lucky bastards, but I'm just s*** out of luck.
Sucks too since this is absolutely -->PERFECT<-- for what I want to do...

VERY much thanks for all of your help trying to get this working for me, but you might as well move on.

Thanks again,
Phil

Posted by: phil at May 22, 2003 02:49 PM

Hmnn... ok, I suppose there isn't anything we can do about it now... Got an idea: say, everyone of you out there who happen to read this page, please post a little "It worked for me" (so Phil will cry more) or "It doesn't" (so Phil will feel consolated)... Yea, since we are already at it, might as well make this page really long!!!

Posted by: sunny at May 22, 2003 03:12 PM

Haha, make me cry people.
Sorry to bitch so much...
I'm sure PHPObject does everything it's meant to, and that I just have something configured wrong somewhere, but WHAT!?!?

later,
phil

Posted by: phil at May 22, 2003 03:40 PM

I've got a huge PHP application that uses PEAR as the DB abstraction layer. Could you provide any hints as to how to use PEAR inside the PHP class that holds all my PHPObject methods? In my existing PHP scripts, I just define a new DB object (let's say $dbh). Normally I can just do something like the following in my PHP pages:

$query="SELECT * FROM tests WHERE test_id='$test_id';
$test=$dbh->getAll($query);
print_r($test);

Now inside my PHPObject class I've tried the following:

function getTest($test_id){
$query="SELECT * FROM tests WHERE test_id='$test_id';
$test=$dbh->getAll($query);
print_r($test);
}

Then in my flash movie I say:
myFoo.getTest(1);

Obviously this won't work, but could you point me in the rigt direction? I'm not very good with objects, expecially objects being called from within other obects as in this case.

Posted by: Brett Brewer at May 23, 2003 04:43 AM

Sorry Phil - I was able to install the files and successfully run the test in about 10 minutes.

I'm using a Win2000 Server, IIS 5.0, PHP 4.2.3, & Flash MX.

It did take an hour or so to get a test flash app to open and read a MSAccess DB using ODBC, but that was because of my lack of experience with php.

It does work so don't give up!

Take care,
Floyd

Posted by: Floyd at May 23, 2003 04:53 AM

I'm not really giving up... it's just that there's not much else to do to try to fix this.
I'm still open to any ideas you might have that I could try... but I've done just about everything there is to do.
Unless somebody wants to make a .swf for me with my host and password in it and send me it, that would be cool... then I could see if it's my FlashMX that is screwed up, or if it's apache/php.
Anyone up for that? E-mail me.

Thanks,
Phil

Posted by: phil at May 23, 2003 08:25 AM

Hi Brett,

Why won't myFoo.getTest(1) work?

In your PHP method, you used "print_r($test)", then in Flash, you will have to use PHPObject's getOutput() method to retrieve the data, example:
----------------------------
myFoo.getTest_onResult = function() {
trace(this.getOutput());
}
----------------------------

Alternatively, in the PHP method, you could use "return $test" instead, then in Flash you could do:
----------------------------
myFoo.getTest_onResult = function(result) {
trace(result);
}
----------------------------

Or, in the PHP method, you could set a property, like "$this->currentTest = $test". Then, in Flash you would do:
----------------------------
myFoo.getTest_onResult = function() {
trace(this.currentTest);
}
----------------------------

The above, basically, are the three ways to get data back from PHP. Thanks.

Posted by: sunny at May 23, 2003 09:23 AM

I guess my problem is, where do I create the $dbh object to make the database query? I usually just keep all my DB connection code in an include file, along with session_start() calls and the like. You can't put an include that instantiates a class inside another class. I were doing it entirely in a PHP script, I wouldn't be declaring my $dbh object inside a class, I'd be passing a reference to the $dbh object. If I were doing it inside a function (not in a class), I'd just declare $dbh as global inside the function and call methods on it. Not sure how or where to put my DB connection code and $dbh object instantiation. Is there a forum where we could discuss such topics at length?

Posted by: Brett at May 23, 2003 10:50 AM

Brett, your question is not really about PHPObject. To make things clear, PHPObject requires you to have prior knowledge on how OOP in PHP works. You may like to ask your questions in the forums in http://www.phpbuilder.com or other PHP related sites.

Meanwhile, I would like to point out, you CAN "put an include that instantiates a class inside another class". Alternatively, you can also "put an include that instantiates a class inside the file that contains another class".

Posted by: sunny at May 23, 2003 11:15 AM

Guess who got PHPObject working!
I was trying to play outside of the sandbox like a bad little boy.
My http port was higher than what the flash player allows I guess... So I set it lower and whadya know, it works!!!
Works really damn good too. GREAT peice of software.

Oh and on a sidenote, does anyone happen to know the exact range of ports that the flash player will allow?

Thanks,
phil

Posted by: phil at May 23, 2003 12:06 PM

You naughty boy! Deserve a real hard spanking! How the **Insert_Vulgarity_Here** are we supposed to know that you were doing that?!!!

Hmnnn... you are hereby sentenced to 48 hours/week of community service... you are now obliged to help the next fellow who comes along and say he can't get the thing to work!

:)

Posted by: sunny at May 23, 2003 12:36 PM

Hi, Sunny

Great work!
I start playing around with some PHP class... Just wondring how you pass the ARRAY OBJECT to php class and from php to flash? does it support nesting object?


Jono

Posted by: Jonathan at May 23, 2003 01:46 PM

I'm so happy this is working.
I found an error though, a pretty annoying one too.
When I write my actionscript, I don't leave any blank lines.
That is a problem with '#include "PHPObject.as"' because the line directly after that will not get executed.
The problem is that PHPObject.as ends with a comment, and flash doesn't automatically insert a newline character after '#include's.
So the line following '#include "PHPObject.as"' is treated as a comment... not good.
A simple fix is to add a blank line at the bottom of PHPObject.as

Hope that helps, and hope that counts towards my community service.

Later,
phil

Posted by: phil at May 23, 2003 01:54 PM

Ah, that's good Phil! Yes, I guess everyone will agree that ought to count towards your community service :)

Jonathan, nested stuff are supported except for the recursive ones.

Posted by: sunny at May 23, 2003 02:18 PM

This isn't a flame, but I guess that last message means you don't have a real forum for this project. This page is going to get very long if you don't set one up...I won't take up any more of your time or space after this. I use phpbuilder.com all the time, but this is a FlashMX question as much as it is PHP. The example files provided are just too simple. I got them working in about 10 minutes, but they don't show me enough. I need to see something that connects to a database and displays data from within a PHP class called by FlashMX. Then I'll be able to use PHPObject for my app...it looks like you've done really good work so far though and I applaud you for it. Any chance of adding more examples to your site? Anyone want to volunteer some more advanced examples that could be posted somewhere?

Posted by: Brett Brewer at May 24, 2003 02:14 AM

Well, Brett, to put it bluntly, nobody is begging you to use PHPObject. If you expect to be spoonfed, sorry, you have come to the wrong place.

Posted by: sunny at May 24, 2003 03:35 AM

Good on you Sunny!!

I still don't know what this project's really abt but then I'm not making lots of demands anyway. Eitherway your site looks great - keep it up!!

Posted by: Ben at May 24, 2003 05:03 PM

Does it matter what extension you give to your classes? Is it ok to name them like: myclass.class.php ?

Posted by: Han at May 27, 2003 08:04 PM

Hi Han, I think you already know the answer - yes, it matters unless you hack the Gateway.php to behave otherwise.

Posted by: sunny at May 27, 2003 10:41 PM

Hi Sunny! Could you please give a brief outline on how to pass an array object, say a result-set from mySQL database to Flash using PHPObject. Do you pass a 2-dimensional array an object and loop through it on the Flash side or you pass on individual values?

Posted by: Iggie at June 3, 2003 09:33 PM

Hi Iggie, actually the best way to find out is to experiment on your own. The answer I can give is that you pass an array back just like you would pass an array from one function to another in actionscript. How would you do it? Yes, you pass it as an array and loop through the array. Of course, you can also pass individual values... it really depends on what you want to achieve!

Posted by: sunny at June 4, 2003 02:56 AM

Iggie, I found this at FlashKit. Should be what you're looking for: http://www.flashkit.com/tutorials/Dynamic_Content/Integrat-Vin-916/index.php

Posted by: David Eleuterius at June 5, 2003 12:20 AM

There really needs to be a forum where folks can ask questions and have them answered by people who know. I'm trying to figure out how to use this - and eventually I will - but it would be really helpful to have a forum where people can quickly look up simple questions so that time to application of PHPObject can be reduced dramatically. That way a FAQ of sort can be built by those who figure things out and can pass their knowledge along, in addition to building a community of folks who help each other out. I see this kind of community for other folks. I'm not asking to be spoonfed, but it would be helpful to see what others have learned.

Posted by: David Eleuterius at June 5, 2003 02:04 AM

Has anybody been able to display multiple records yet? I am trying to populate a combobox with project titles (and IDs for the DB) for a portfolio, and I can't figure out if I am supposed to put this as my init() function, or call it another function. And if I call it another function, how do I trigger it when it is supposed to just load when the portfolio movie loads?? The idea is a selection of the combobox passes the ID and then a single recordset is called. That by far will be a stroll in the park compared to what I've been going through trying to figure out how to get multiple records to populate a combobox.

Posted by: David Eleuterius at June 5, 2003 08:09 AM

There will be a forum when I get time to putting it up and when I am convinced that enough people are using PHPObject and willing to help each other out. David, I know you are not asking to be spoonfed, but there are people out there who are. If I put up a forum before there are enough people using PHPObject and willing to help each other out, I will be swarmed with more questions. The presence of a forum will implicitly suggest I am providing "support" which I am not. I would professionally provide support if this is a commercial product but it is not.

Regarding database queries, there are actually many ways to do things. You can pass one record back at a time, or if you wish you can pass whole resultsets back and let Flash manipulate the records. If you wish to have the whole resultset passed back to Flash, first make sure you are passing back as an associative array (I mean, it is easier for Flash that way). I would suggest everyone use ADODB, download at http://php.weblogs.com/ADODB

The benefits are listed on that library's website. And in any case, I am going to support that library in future releases of PHPObject (not compulsory that you use that library, but I do find it useful).

Lastly, if you do not wish to use ADODB, here is a PHP code example on packing the mysql result in an array object format familiar to flash:

function getThemes() {
    $result = $this->query("SELECT * FROM themes");
    $arr = array();
    while( $row = mysql_fetch_assoc($result) ) {
        $item = array();
        while ( list($key,$val) = each($row) ) {
            $item[$key] = $val;
        }
        array_push($arr, $item);
    }
    return $arr;
}

If your fields in the database table are "data" and "label" (most likely not, but this is just an example), then you can use the setDataProvider method of the comboBox to populate the component easily:

myFoo.getThemes_onResult = function(result) {
    myComboBox.setDataProvider(result)
}

Posted by: sunny at June 5, 2003 12:45 PM

Thanks a lot David. It just happened that I found this example myself a bit earlier on actionscript.org. Yeah, some documentation for PHPObject is a great idea, but I suppose it will be more or less up to the community of PHPObj developers that I am sure is gonna form in the next few months. Keep up great work, Sunny!

Cheers,
Iggie

Posted by: Iggie at June 5, 2003 07:19 PM

Thanks for reply Sunny. I have always written my php in a procedural manner so object oriented is new to me. Also working with data in Flash (I have mostly made Flash CDs) is new to me also, so I am getting bombarded with all kinds of new things to learn (not to mention how PHPObject functions within Flash). I have always been one to learn by example, so the going has been really rough without anything to refer to. When I get my code working I can release it back as an example so people can learn from my cussing.

Posted by: David Eleuterius at June 5, 2003 08:57 PM

Despite serious efforts, I can't seem to get PHPObject to work with an object of my own. It does, however, work with the example movie and Foo class. I am using Mac OS X, PHP 4.2.3 (I think)

My class:
- I use ".class.php" for my classes, so changed a line in Gateway.php so it finds it.
- is in a subdir, so I use new PHPObject("dir/MyClass.class.php")
- I created a blank init() function (like Foo class)

1) Creating the object appears to work ok
2) Methods aren't seeming to be executing on the server and
2) my methods for MyClass.onInit or MyClass.onResult or MyClass.medthodName_onResult don't appear to be firing.

Any things I have missed?

Posted by: Robert Gravina at June 12, 2003 11:03 AM

define dir in Gateway.php not in Flash. regardless of how you name your class file and where you keep it, in Flash the declaration is always

myClass = new PHPObject("myClass");

Posted by: sunny at June 12, 2003 02:37 PM

Using IIS & Windows XP, PHP 4.3.1. and FlashMX, with the latest player. What exactly should I see when I access the test example. To be more specific should'nt I see the contents of $num and $story from the Foo class in the text movie when it plays?

Posted by: Kmb40 at June 13, 2003 07:02 PM

I am posting this so that others will not have to write it out in the future. Maybe this will help save development time for Sunny.

I really do not know what the problem is. I tried using this locally on my dev box (Win XP v5.1.2600, IIS v5.1, PHP v4.3, Flash MX v6). I have also tried it on my Interent server with Redhat Linux v7.3, PHP v4.2.2 and Apache v1.3.26.
Heres what I've tried locally and on my Internet server:

1.Placed Foo.php in the same directory(services)as Gateway.php
1a.Did not have to change path in Gateway.php because of 1.
2. Installed PHPObject extension.
3.Set path in Test.fla to the directory(services) of Gateway.php. Example for dev box "http://localhost/services/Gateway.php"
4.Published Test.swf and Test.html to the www/root directory.
5.Accessed Test.html through IE v6.

What I got was the Test.html page displaying the Test.swf and;

id busy? = false
id = 1
num = null/empty
delay? = false
time(ms) = null/empty
param = 15
myfoo.story = null/empty
lastUploadSize = 242 bytes
lastDownloadSize = bytes
story methods = null/empty

It appears that the swf is working fine but no information is being retrieved from the Foo.php ie variables $num and $story.

Solutions I tried:
1. Updating Flash player to 6,0,79,0
2. Placed error_reporting(E_WARNING); (or lower error level).at the top of Gateway.php Example "</PHP error_reporting(E_WARNING); (or lower error level)".

Any suggestions anyone. I am working with AMF and PHPObject at the same time so there really is no rush because I got AMF to work. However I would like to use PHPObject because of its freedom.

Posted by: Kyle at June 14, 2003 07:07 PM

Hey sunny,

I have just discovered your phpobject application - it looks just fantastic and a really attractive alternative to remoting too. phpobject looks so much simpler to implement - I haven't tried it out yet, but I'm pretty pleased to have discovered it. It looks like you have done some really great work. Keep it up!!

I'll let you know how we get on here :)

Regards,

Christo

Posted by: Christo at June 18, 2003 11:45 PM

Hi there everyone,

I have been developing a full-blown search application with PHPObject for a few weeks by now and everything works just fine (will post a link when it's online)! Thanks for your great work, Sunny! I am working on OS.X.2 with PHP4.3 and MySQL.

Posted by: Iggie at June 21, 2003 12:03 AM

Hello.. great idea for flash / php developers!
i do have one question tho.. when using the php object.. or using the loadvar method of flash.. to call a php file.. is it possible for php to 'remember' the location of the flash movie(where the php file was called FROM) and pass variables to that flash movie without the flash movie initiating the send / recieve... for example.. if a user is using a browser.. and clicks a certain link or posts a certain form.. instead of posting the results to another php file or iself.. can it pass those variables to a flash movie..? does that make any sence?

thanx for your time.. and again.. good work!

Posted by: Joe at July 1, 2003 01:07 AM

Has anyone used PHPObject with MySQL with datasets larger than just a handful of rows? I find huge performance problems when trying to return a result set with 100 rows. Here are some numbers:
PHP through apache, print to screen: 0.4 seconds
PHPObject, echo output, use getOutput: 0.4 seconds
PHPObject store result in object: 0.7
PHPObject return result array: 53 seconds!!!!

I am using Apache2 under OS X 10.2.6 with PHP 4.3.2 and flash player 6.0 r 79. Anybody else experience such drastic performance problems?

Herre is the function used to test:

function getList($numItems){
$query = "select *,title as label from bbid limit $numItems";
$rs = $this->db->Execute($query);

// This takes 0.4 seconds:
//print "";
//print_r($rs->GetRows());
//print "";

// This takes 53 seconds:
$this->currentResult = $rs->GetArray();
return -1;
}

Posted by: Jim at July 3, 2003 09:40 PM

PHPobject rocks!, but are you limited to using only one class file named Foo.php?

If I rename Foo.php to Foo2.php it doesnt work.
I tried renaming the class to Foo2 and requesting that class, but no luck.

thanks

Posted by: Fredrik at July 4, 2003 12:58 AM

You did not rename the class INSIDE the file you renamed.

Posted by: sunny at July 4, 2003 09:57 AM

Sunny,

PHPObject itself and all the examples and documentation you provided are fabulous -- thanks! I have made a little application that passes a font name and a string from Flash and uses a PHPObject class to pull information from a database about the drawing commands to recreate that string (originally output from Burak's ASV3.1), which Flash then uses to "draw" the string (no embedded font needed). It works great, but I have a question about how to make it sharable. I tried running the Flash movie from another domain (specifying the gateway of my original domain, where the PHPObject class file is too, of course) but it can't be accessed. Can you think of a way I could distribute the Flash movie but not the class PHP file so that people could still use it from my server? I'm having trouble figuring out how to create a web service or some equivalent from all this... any suggestions welcome.

thx, Helen

(Fredrik, are you changing the class name as well as the file name?)

Posted by: Helen Triolo at July 4, 2003 10:23 PM

Follow info to previous question:

The slow speed is also experienced with AMFPHP. I'm not trying to pint fingers at PHPObject. I think it's actually the flash player.

Has anyone tried returning 100 or 1000 (amsll) rows from a database back to flash? Anyone? Using any remoting method?

Posted by: Jim at July 5, 2003 01:41 AM

Helen, because of the Flash player security sandbox, you won't be able to access the gateway from a movie in another domain.

Posted by: sunny at July 5, 2003 10:00 AM

Thanks for the info, Sunny. Guess I'll just stick with showing how to display/manipulate a single asv font string for now then and discuss how phpobject can be used to pass a nested array to Flash in theory.

Just fyi (because I was so pleased to see it work :) the thing which uses phpobject to get a record from a mysql db, create an array of drawing commands from that, and then pass it to Flash so the string can then be manipulated (by a user) with draggable handles is at http://actionscript-toolbox.com/asv/ASVPhrase.php

It's not very speedy (that's why I put an 8 char max on the string entered), but maybe I can optimize my code a bit more... Anyway, thanks again for making phpobject publicly available.

Posted by: Helen at July 7, 2003 10:46 AM

Hi Sunny,

I have begun to experiment with your PHPObject. Everything works okay with the example, and I am now modifying it to suit my needs. Here is what I have found:

When I deliberately invoke a method from my class, arguments are passed and received (by the method responder) flawlessly. It does not respond, however, when I invoke the method through a function in Flash.

My Flash method:
function processAudioFolder(audioFolderPath){
serveBot.chooseRandomSong(audioFilePath);
}

In this example, my PHPObject is named 'serveBot' and contains a method called 'chooseRandomSong($path)'. It receives the argument, then immediately returns it.

(PHP method)
function chooseRandomSong($path) {
return $path;
}

My responder looks like this:
serveBot.chooseRandomSong_onResult = function(result) {
testField.text = result;
}

Again, this appears to work if explicitly called, but does not work when called through the function. I expect it to be a matter of scope, but would appreciate your insight. Thank you Sunny, for your PHPObject!

Sincerely,
Allan Hart

Posted by: Allan at July 8, 2003 11:17 AM

If this is really what you did:

function processAudioFolder(audioFolderPath){
serveBot.chooseRandomSong(audioFilePath);
}

then it is no surprise it failed - the variable names are different!

Posted by: sunny at July 8, 2003 11:41 AM

Hello again Sunny,

Okay, I feel a bit of a fool for putting in the wrong argument. The mistake, however, does not seem related to the issue. I corrected the variable name passed to match the function parameter, but the result is the same. Nothing happens. To clarify my scenario:

My functions are all defined in a frame on the main timeline. It is in this same frame that I instantiate my PHP object (at the top). The function I wish to call my remote method from is also defined in that frame, after the PHPObject is instantiated.

I do not wish to trouble you, Sunny, so I will try an alternate approach. Still, I expect others have experienced a similar problem. If you can offer a solution (an example, perhaps) I, and possibly others, would appreciate it greatly. Thanks, by the way, for your prompt response!

Sincerely,
Allan Hart

Posted by: Allan at July 9, 2003 07:07 AM

Hi sunny,

Whew. As I suspected, it was a matter of scope. I declared my PHP object to be global, then referenced it from within my function as:
_global.serveBot

Works like a charm. Obviously I have some learning to do when it comes to scope in Flash. I'll stick with this for now, until I figure out how I would otherwise reference it. Thanks anyway for your support.

Allan Hart

Posted by: Allan at July 9, 2003 07:14 AM

Hello Sunny.

I am creating an ecard application using phpobject. I am reading in a directory with files from my class and when the thumbnails for 1 or more files do not exist they get created.

Because this loop can take a few minutes (approx. 3 secons per image) i want to display some sort of status to the user.

E.g. it would be cool if i could set a variable in the function, and immediately read it out in flash.. I have now this php code:

------------------------------------------

var $statMsg = "";
var $statPerc = "";
...
$this->statMsg = "$folder: Creating thumbnails";
$this->statPerc = floor(($i / $count) * 100);

------------------------------------------

and i want to use flash to read out the statMsg and statPerc. But i can't seem to work it out..

------------------------------------------

myFoo.onInit = function() {
trace("init");

setInterval(
function() {
trace(myFoo.statMsg add " " add myFoo.statPerc);
}
, 200);

}

------------------------------------------

The function is running, but i don't get anything back.. Damn it :D Any tips?

Posted by: Gilles at July 9, 2003 08:58 PM

 


Zones



Forums