Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loading php vars into flash at random

Status
Not open for further replies.

rninja

Technical User
Apr 11, 2001
381
US
Hello everyone.

I am trying to use php variable in a flash movie. More specifically, I want to have a random movie show up in the main loading movie and all of the php variables show up based on the random selector.

EXAMPLE:
Main Movie->Random Movie(1-10){loads: title, description, image, Music Movie}

How do I go about doing this?

Thanks much for assistance in advance!

Rninja

smlogo.gif

 
I forgot to mention, I would like to also have a preloader for that main movie. How do I get it to determine when the main movie is completely loaded?

Rninja

smlogo.gif

 
Set up your PHP page to respond with name/value pairs after logic is run. Then add the loadVars.sendAndLoad() action to each of the random clips. The best way to do this would be to create a _global function and call it from each random movie when it is loaded.

So the _global function would be something like this (in the main timeline of the main movie).

Code:
_global.sendInfo = function(clipNumber){
   sendVars = new LoadVars();
   sendVars.randomClip = clipNumber;
   
   PHPResponse = new LoadVars();
   PHPResponse.onload = _global.receiveReply;

   sendVars.sendAndLoad("urlofphp.php",PHPResponse,"POST");
}

_global.receiveReply = function(result){
   if(result){
      targetClipName.title = PHPResponse.title;
      targetClipName.description = PHPResponse.description;
      targetClipName.image = PHPResponse.image;
      targetClipName.musicMovie = PHPResponse.musicMovie;
   }else{
      trace("Error");
   }
}

Your PHP page should be outputting (printing):

Code:
&title=yourTitle&description=yourDescription&image=yourImage&musicMovie=yourMusicMovie

Now let's say you load Movie 1... the code in the first frame of movie 1 is:

Code:
//call _global function and send parameter via "POST" to PHP page.
_global.sendInfo("1");

This is what you will evaluate in your php to return the correct values in the format shown above.

Hope that makes sense enough for you to be able to use. ASP is my poison so I can't really give you any PHP tips.


Wow JT that almost looked like you knew what you were doing!
 
Pixl8r,

I understand some of the code, but how do I actually get a random movie to show up with the variables from the php file?



Rninja

smlogo.gif

 
In the example "clipNumber" is the value that you will feed to the PHP page.

Code:
 _global.sendInfo = function([highlight]clipNumber[/highlight]){
   sendVars = new LoadVars();
   sendVars.randomClip = clipNumber;
   
   PHPResponse = new LoadVars();
   PHPResponse.onload = _global.receiveReply;

   sendVars.sendAndLoad("urlofphp.php",PHPResponse,"POST");
}

The PHP page will have the logic to evaluate the variable passed to it ("randomClip") then retrieve that record from the database and needs to return the information in the name/value pair format above.

In flash you can generate a random number a couple of ways. One is:

Code:
//Will generate 3 different numbers at random (0,1,2)
_global.sendInfo([highlight]random(3)[/highlight]);


Hope it helps.

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top