|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Is this Possible? (Flash/PHP/MySQL )
I would like to know if Flash is the way to go with this possible project. I having a programming background, but don't know Flash yet, but will give it a go if this is possible (and the best language to use for this).
I would like to have a number of objects (10-15) that are controlled by a set of coordinates. The coordinates would be read from a Database (MySQL) or from a text file. I assume I could have a Flash Application read this file every so many seconds (ie. 45 secs) and update the display accordingly. Is my above assumption correct? To populate the database (or create the text files) I would like to have a similar display with the ability to drag these objects (10-15) around and submit the coordinates of their positions. This would be an admin function display. Is that possible? Thanks for any help or guidance, Andrew |
|
#2
|
|||
|
|||
|
loading txt data into flash
it sure is possible... because it's a simple amount of data, i would probably leave out MySQL and just work with text files and PHP. Basically, you need to format your text file to look like this:
&variable=value&variable2=value2& ... you could also do: &variable=value& &variable2=value2& just for readability's sake... So use PHP to fopen your text file, and fwrite or fput the new variables in (i'll explain how to get them from flash to php in a minute, but first, how to get them from php/txt to flash) If you are using Flash MX, you'll need to create a new LoadVars Object, and the process the variables from there: PHP Code:
what this will do is let you track the loading of the text file. it's creating the LoadVars object, setting the callback function to an annymous function that accepts any value and the loads the actual .txt file. In this case, i'm just using trace to tell us if the file loaded successfully (the only way this will fail is if the file doesn't exists). we'll change the response when we know it's working right. So, as a mock text file, lets put some content in it (myText.txt): &variable1=nuttin1& &variable2=nuttin2& &variable3=nuttin3& &variable4=nuttin4& change your function in flash so that if(done) also has the following line: trace(this.variable1); it should trace "nuttin1" in the output window. notice that i had to put "this." before the variable name.. that is because when the variables are loaded in, they are loaded to the myLoad object, so we need to reference the `this' to point Flash in the right direction. Armed with this knowedlge, we can now use our function to load in variables and then process them when we get them. If we are dealing with coordinates, it will be easiest to use an array. Flash has an explode() method of it's own, so we'll just reformat the text file: &xcoords=12|15|17|19|21|24& &ycoords=50|27|34|85|48|22& and also our flash function. i'll write another function to show that our variables are now available out side of our loading function: PHP Code:
Now that we have those variables in an array we can set any property (_x or _y included) of any object by indexing those arrays. mysquare._x = x[0]; mysquare._y = y[0]; //sets the coordinates to (12,50) now, writing the coordinates is a little more tricky, but it emcompasses the same methods... coming next post ![]() bret |
|
#3
|
|||
|
|||
|
for this part, i just made a little .fla to demonstrate saving coordinates. open up the attached and follow along...(i've also included all of my source)
each square has a start and stopdrag command on it, so you can move them. i'm using "duplicateMovieClip" to make copies of the original, and then setting the coordinates to a random value within the stage limits. here's the .fla script: PHP Code:
so, like i said, i just create duplicate the square and place it randomly... put those positions into an array, assign the array as part of my mySend object and send the variables off to PHP here's the writeTXT.php file: PHP Code:
if you've done PHP before, this should all be pretty straight forward. i'm a flash developer so there's probably better ways to do the PHP than the way i did it, but it works write back if you have questions regarding this script.here's a working example: http://dev.noskillx.com/sendCoords.html move the boxes around wherever you want and then send them. it will load the PHP script which will write to the text file and then open the text file to prove it worked ![]() http://dev.noskillx.com/loadText.html that will alert the new coordinates. Try changing the boxes around, every time you reload the loadText.html file, it will reflect your changes that you saved to the text file. That should be everything. cheers, bret |
|
#4
|
|||
|
|||
|
Thanks Bret. I give it a go.
I'll probably be back for some assistance. |
|
#5
|
|||
|
|||
|
How good is that?
He's done pretty much the whole thing for you, complete with step by step instructions almost! I've never seen anything like that before. A pat on the back for Bret for restoring my faith in humanity! |
|
#6
|
|||
|
|||
|
Hello,
I am attempting to recreate the above scenario, but with 2 objects. I have created 2 symbols and used the "duplicateMovieClip" but only one of the two objects duplicates. It is whichever one is listed second (to duplicate). Why is this happening? I'm sure it is simple, but I am fairly new to Flash. Thanks, Andrew |
|
#7
|
|||
|
|||
|
hey,
when you use duplicateMovieClip, you need to be sure to specify a unique depth value, otherwise, only the last clip that you duplicated will show up (since only ony object can exist on a level at a time). levels are the way that flash organises it's stacking order, so you'll just need to specify a new one: square_mc.duplicateMovieClip("newsqaure1",1); square_mc.duplicateMovieClip("newsquare2",2); cheers, bret |
|
#8
|
|||
|
|||
|
That did it!
Thanks Bret. |
|
#9
|
|||
|
|||
|
I'm back with another question (for above scenario)...
Is there an easy way to make it so my objects wont overlap? My thought is that once the object is "released" it can be run through the other object's coordinates to check for an overlap... and moved accordingly. Does this sound okay or is there something better? Note: My objects are circles. - Andrew |
|
#10
|
|||
|
|||
|
hum... i think an easy way to check this would be to just do a hitTest with every movieclip when you let the object go and then snap back to it's original position if there is a hit somewhere. You could put all of the objects into an array and just loop through, using whichever one you grabbed as the hitTest source.
write back if you need code? cheers, bret |
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > Is this Possible? (Flash/PHP/MySQL ) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|