Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 26th, 2003, 09:34 AM
bagger bagger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 43 bagger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 35 m 15 sec
Reputation Power: 8
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

Reply With Quote
  #2  
Old February 26th, 2003, 11:21 AM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
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:
//actionscript
    
myLoad = new LoadVars();
    
myLoad.onLoad = function(done){
        if (
done){
            
trace ("success loading the file");
        } else {
            
trace("something went wrong");
        }
    }
    
myLoad.load("myText.txt"); 

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:
//actionscript
myLoad = new LoadVars ();
myLoad.onLoad = function (done)
{
    if (
done) {
        
this.xcoords.split("|");
        
this.ycoords.split("|");
        
trace ("success loading the file");
        
processCoords();
    } else {
        
trace ("something went wrong");
    }
};
myLoad.load ("myText.txt");
processCoords = function(){
    
trace(x);
    
trace(y);



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

Reply With Quote
  #3  
Old February 26th, 2003, 02:33 PM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
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:
//actionscript
for(i=1;i<15;i++){
    
square0_mc.duplicateMovieClip("square"+i+"_mc",i);
    
this["square"+i+"_mc"]._x Math.round(Math.random()*550);
    
this["square"+i+"_mc"]._y Math.round(Math.random()*350);
    
this["square"+i+"_mc"].number_txt.text i;
}
submit_mc.onRelease = function(){
    
mySend = new LoadVars();
    
mySend.xsend = [];
    
mySend.ysend = [];
    for(
i=0;i<15;i++){
        
mySend.xsend[i] = _root["square"+i+"_mc"]._x;
        
mySend.ysend[i] = _root["square"+i+"_mc"]._y;
    }
    
mySend.onLoad = function(success){
        if(
success){
            
trace("sent variables okay");
        
        } else {
            
trace("something went wrong");
            
getURL("javascript:alert('something went wrong');");
        }
    }
    
mySend.send("writeTXT.php",mySend,POST);



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:
<?
    $x 
$_POST[xsend];
    
$y $_POST[ysend];
    
$xcoords explode(",",$x);
    
$ycoords explode(",",$y);
    
$xputs "&xcoords=";
    
$yputs "&ycoords=";
    for(
$ii=0;$ii<count($xcoords);$ii++){
        if(
$ii == count($xcoords)-1){
            
$xputs .= $xcoords[$ii] . "&\n";
            
$yputs .= $ycoords[$ii] . '&';
        } else {
            
$xputs .= $xcoords[$ii] . '|';
            
$yputs .= $ycoords[$ii] . '|';
        }
    }
    
$puts $xputs .  $yputs;
    
$text fopen("myText.txt","w");
    if(
$text){
        
fwrite($text$puts);
        
fclose($text);
        print 
'<script language="javascript">window.location = "/myText.txt";</script>';
    }
    exit;

?>


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
Attached Files
File Type: zip savecoords.zip (8.5 KB, 486 views)

Reply With Quote
  #4  
Old February 26th, 2003, 05:06 PM
bagger bagger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 43 bagger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 35 m 15 sec
Reputation Power: 8
Thanks Bret. I give it a go.

I'll probably be back for some assistance.

Reply With Quote
  #5  
Old March 7th, 2003, 07:11 PM
wa90 wa90 is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 12 wa90 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thumbs up

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!

Reply With Quote
  #6  
Old March 14th, 2003, 05:11 PM
bagger bagger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 43 bagger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 35 m 15 sec
Reputation Power: 8
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

Reply With Quote
  #7  
Old March 14th, 2003, 05:32 PM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
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

Reply With Quote
  #8  
Old March 14th, 2003, 06:45 PM
bagger bagger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 43 bagger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 35 m 15 sec
Reputation Power: 8
That did it!

Thanks Bret.

Reply With Quote
  #9  
Old March 21st, 2003, 01:34 PM
bagger bagger is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Posts: 43 bagger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 35 m 15 sec
Reputation Power: 8
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

Reply With Quote
  #10  
Old March 25th, 2003, 05:12 PM
bret bret is offline
flash junkie
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: CO, USA
Posts: 172 bret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 38 sec
Reputation Power: 6
Send a message via Yahoo to bret
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > Is this Possible? (Flash/PHP/MySQL )


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.