[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12291
  • Last Modified:

pass variable: from url into swf out to php and back to swf?

Hi,
This question is a continuation of the issue that negatyve helped me with earlier, titled: php into flash mx

I am trying to make an SWF that displays data from a Db based on the url of the page that it is embedded in.

Presently, it works if I hard code the variable directly into the SWF like this:

myLoad.load("http://www.myURL/flash_tour.php?musical_group_id=593");

But how do I get Flash to read this variable directly from the html page instead, so that I can use the same SWF for multiple variables?

I am able to get the variable from the html page to display in a dynamic text field, but I can't figure out how to get that variable into the myLoad statement so that it gets passed to the PHP script and loads the correct data into the SWF.

(In my PHP script I have  "SELECT * where musical_group_id =" . $_GET[musical_group_id];")


Once I get Flash to append the variable onto the myLoad statement I assume I can use either the query string method or FlashVars to pass it into the SWF. Or?

Do I somehow have to pass the variable from the html url into flash and then back out to the php to be read again by the SWF?...

Or do I need to put the php and html together? I was hoping to keep them separate so that the SWF could be more portable.

PHP script tha returns the data: flash_tour.php
Flash page that the SWF is embedded in:flash_tour.html
SWF:flash_tour.swf
variable: musical_group_id

background on this question: php into flash mx
http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_20815370.html 

Thanks alot, billywig
0
billywig
Asked:
billywig
  • 9
  • 8
1 Solution
 
negatyveCommented:
ok: actually you are passing that variable to the swf, as I read "I am able to get the variable from the html page to display in a dynamic text field". That means that you are doing something like this:

<object ...>
              <PARAM NAME=movie VALUE="your_movie.swf">
              <PARAM NAME=FlashVars VALUE="your_variable=http://www.myURL/flash_tour.php?musical_group_id=593">
<embed
              src="your_movie.swf"
              FlashVars="your_variable=http://www.myURL/flash_tour.php?musical_group_id=593"
              ..............>
</embed>


Then just do:

myLoad = new LoadVars();
myLoad.path = this;
myLoad.onLoad = function(success)
{
      if(success){
            .........
      } else {
            trace("PHP PAGE NOT FOUND");
      }
};
myLoad.load(_root.your_variable);

and you're done..
0
 
billywigAuthor Commented:
But how would I get the variable passed to the script?
Here is the code I have so far for the three elements of this. Thanks!

1. Tour_results.php::::::::::::::::::::::::::::::::::::::::

<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html;  charset=ISO-8859-1">
<TITLE>tour results</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="550" HEIGHT="400" id="flash_tour" ALIGN="">

<PARAM NAME=movie VALUE="flash_tour.swf?musical_group_id="=<?php echo $_GET['musical_group_id']; ?>">

<PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF>
</OBJECT>
<EMBED src="flash_tour.swf?musical_group_id=<?php echo $_GET['musical_group_id']; ?>"  quality=high bgcolor=#FFFFFF  WIDTH="550" HEIGHT="400" NAME="flash_tour" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
</BODY>
</HTML>

2. flash_tour.php::::::::::::::::::::::::::::::::::::::::::::::::::::

<?
$hostname = "hostname ";
$username = "username";
$password = "password";
$dbName = "dbName";

MSSQL_CONNECT($hostname,$username,$password) or DIE("DATABASE FAILED TO RESPOND.");
mssql_select_db($dbName) or DIE("Table unavailable");
      
$tour_query="SELECT convert(char(11), date,101) as date, city, state, venue_name, musical_group_id FROM webtours_view where musical_group_id =" . $_GET[musical_group_id];

$result = mssql_query($tour_query);

$num_rows = mssql_num_rows($result);

for($i=0;$i<$num_rows;$i++){
     $row = mssql_fetch_array($result);

     $date = "date$i";
     $date = $row['date'];

     $venue_name = "venue_name$i";
     $venue_name = $row['venue_name'];

     $city = "city$i";
     $city = $row['city'];

     $state = "state$i";
     $state = $row['state'];

     print("&date$i=$date");
     print("&venue_name$i=$venue_name");
     print("&city$i=$city");
     print("&state$i=$state");
}
print("&totals=$num_rows");

?>

3. flash_tour.swf::::::::::::::::::::::::::::::::::::::::::::

myLoad = new LoadVars();
myLoad.musical_group_id = _root.musical_group_id;
myLoad.path = this;
myLoad.onLoad = function(success)
{
      if (success) {
            this.path.pane_sp.boundingBox_mc._visible = false;
            this.path.pane_sp.setScrollContent("emptyClip");
            var mc = this.path.pane_sp.getScrollContent();
            for (var i = 0; i < Number(this.totals); i++) {
                  var item = new Object();
                  item.date = this["date" + i];
                  item.venue_name = this["venue_name" + i];
                  item.city = this["city" + i];
                  item.state = this["state" + i];
                  item.title = "Record n." + (i + 1);
                  item._y = i * 110;
                  mc.attachMovie("singleRecord", "record" + i, i, item);
            }
            this.path.pane_sp.refreshPane();
      } else {
            trace("PHP PAGE NOT FOUND");
      }
};
myLoad.SendAndLoad("flash_tour.php");

//myLoad.load("flash_tour.php?musical_group_id=593");
//myLoad.SendAndLoad("flash_tour.php?musical_group_id="+(musical_group_id.text)), myLoad , "POST";


0
 
negatyveCommented:
ehm, I think I do not understand what's the real application actions flow..
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
billywigAuthor Commented:
Does this make any sense?::::::::::::

1.
The variable originates in the URL of the tour_results page (this is the page that holds the SWF).
The url of this page containing the SWF would be: http://www.myURL/tour_results.php?musical_group_id=whatever 

2.
This variable gets passed to the root of the SWF through the object/embed tags.

3.
The SWF would then load the php script (using myLoad.SendAndLoad ?) and pass the variable of "musical_group_id" to flash_tour.php (the main php script).

4.
The php script would then have enough info to return the results into the SWF for display.
0
 
negatyveCommented:
1. you call the page this way:

http://www.myURL/tour_results.php?musical_group_id=whatever

2. the page pass the id to the movie this way:

<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html;  charset=ISO-8859-1">
<TITLE>tour results</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">

<OBJECT
      classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"       codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
      WIDTH="550" HEIGHT="400" id="flash_tour" ALIGN="">
      <PARAM NAME=movie VALUE="flash_tour.swf?musical_group_id="=<?php echo $_GET['musical_group_id']; ?>">
      <PARAM NAME=quality VALUE=high>
      <PARAM NAME=bgcolor VALUE=#FFFFFF>
      <EMBED
            src="flash_tour.swf?musical_group_id=<?php echo $_GET['musical_group_id']; ?>"
            quality=high
            bgcolor=#FFFFFF
            WIDTH="550"
            HEIGHT="400"
            NAME="flash_tour"
            ALIGN=""
            TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
      </EMBED>
</OBJECT>
</BODY>
</HTML>

3. now in the main timeline of flash_tour.swf there's a variable called "musical_group_id". you use it in the loadvars:

myLoad = new LoadVars();
myLoad.path = this;
myLoad.musical_group_id = _root.musical_group_id; // HERE YOU ADD THE VARIABLE TO THE LOADVARS OBJECT
myLoad.onLoad = function(success)
{
    if(success){
         // HERE YOU HAVE RECEIVED RESPONSE FROM THE SERVER
         // THIS IS POINT 4.
    } else {
         trace("PHP PAGE NOT FOUND");
    }
};
myLoad.SendAndLoad("flash_tour.php", myLoad , "POST");
0
 
billywigAuthor Commented:
I'm so close I can almost taste it....

But I am still getting no display.

The var is definitely being read by the tour_results.php page (when I view source I see the number).

The flash_tour.php (db script) is returning results (when i view it directly in browser).

I no longer have a dynamic text field in the swf. I don't need one, right?

Does this have to be inside the curly brackets?
myLoad.SendAndLoad("flash_tour.php",myLoad,"POST");

Also, the SWF is displaying twice in my page. ???

//Thanks Much


0
 
negatyveCommented:
>Also, the SWF is displaying twice in my page. ???

no, why it should?

>I no longer have a dynamic text field in the swf. I don't need one, right?

no, you do not

>The var is definitely being read by the tour_results.php page (when I view source I see the number).

perfect

>The flash_tour.php (db script) is returning results (when i view it directly in browser).

perfect. now let's make some tests:

myLoad = new LoadVars();
myLoad.path = this;
myLoad.musical_group_id = _root.musical_group_id;
getURL("javascript:alert('" + myLoad.musical_group_id + "');void(0)"); // HERE WHAT DOES HAPPEN?
myLoad.onLoad = function(success)
{
   if(success){
   } else {
        trace("PHP PAGE NOT FOUND");
   }
};
myLoad.SendAndLoad("flash_tour.php", myLoad , "POST");
0
 
billywigAuthor Commented:

>// HERE WHAT DOES HAPPEN?

I get a blank javascript alert.


>no, why it should?

I had 2 </OBJECT> tags.........
0
 
negatyveCommented:
>I had 2 </OBJECT> tags.........

I have removed on from the code I have posted before.

>I get a blank javascript alert.

let's test again:

myLoad = new LoadVars();
myLoad.path = this;
myLoad.musical_group_id = _root.musical_group_id;
getURL("javascript:alert('" + _root.musical_group_id + "');void(0)"); // HERE WHAT DOES HAPPEN?
myLoad.onLoad = function(success)
{
  if(success){
  } else {
       trace("PHP PAGE NOT FOUND");
  }
};
myLoad.SendAndLoad("flash_tour.php", myLoad , "POST");

if you get a blank alert again, it means that it cannot reach the variable. is your movie loaded inside or over a main one?
0
 
billywigAuthor Commented:
Blank alert again.
I am using the exact movie that you sent me the last week.  It's not in another movie or anything.

BUT::::::
If I don't use the web page and I load the swf directly with an ID I get the alert containing the ID.
Like this: http://URL/flash_tour.swf?musical_group_id=whatever

--------------------------------------------------
The 2 php pages use "$_GET" but the swf uses "POST". Do I need to add "$_" to this or use GET instead?
---------------------------------------------------
OR maybe I should try Flash Vars to pass the ID instead of what I am doing now which is:

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" WIDTH="550" HEIGHT="400" id="flash_tour" ALIGN="">
<PARAM NAME=movie VALUE="http://path/flash_tour.swf?musical_group_id="=<?php echo $_GET['musical_group_id']; ?>">
<PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED src="http://path/flash_tour.swf?musical_group_id=<?php echo $_GET['musical_group_id']; ?>"  quality=high bgcolor=#FFFFFF  WIDTH="550" HEIGHT="400" NAME="flash_tour" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
</EMBED>
</OBJECT>
0
 
billywigAuthor Commented:
However, if I comment-out the alert and load the swf directly with an ID added I still get a blank SWF.
0
 
negatyveCommented:
ok, try this for Tour_results.php:

=======================================================
<? $vars_to_flash = "musical_group_id=" . $_GET['musical_group_id']; ?>
<HTML>
<HEAD>
<meta http-equiv=Content-Type content="text/html;  charset=ISO-8859-1">
<TITLE>flash_tour</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
<OBJECT
      classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
      codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
      WIDTH="550" HEIGHT="400"
      id="flash_tour" ALIGN="">
      <PARAM NAME=FlashVars VALUE="<? echo $vars_to_flash; ?>" >
      <PARAM NAME=movie VALUE="flash_tour.swf">
      <PARAM NAME=quality VALUE=high>
      <PARAM NAME=bgcolor VALUE=#FFFFFF>
      <EMBED
            src="flash_tour.swf"
            FlashVars="<? echo $vars_to_flash; ?>"
            quality=high
            bgcolor=#FFFFFF
            WIDTH="550"
            HEIGHT="400"
            NAME="flash_tour"
            ALIGN=""
            TYPE="application/x-shockwave-flash"
            PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
      </EMBED>
</OBJECT>
</BODY>
</HTML>
=======================================================

and this code for the flash part:

=======================================================
myLoad = new LoadVars();
myLoad.path = this;
myLoad.musical_group_id = _root.musical_group_id;
myLoad.onLoad = function(success)
{
            if(success){
                        // actions
            } else {
                        trace("PHP PAGE NOT FOUND");
            }
};
myLoad.SendAndLoad("flash_tour.php", myLoad , "GET");
=======================================================
0
 
negatyveCommented:
0
 
billywigAuthor Commented:
YES!  negatyve! negatyve!

Thank you very much! I'm learning alot of stuff here.
I have been trying to answer easy HTML questions to get some points but I don't seem to be much of an expert- yet.
So I may have to pay-the-man in order to keep this resource.
So cool though, Thanks.

cha-ching!
0
 
negatyveCommented:
>I'm learning alot of stuff here.

yeah, that's finally the best thing! :)

cheers!
0
 
billywigAuthor Commented:
Yes learning, but there is so much...

I'd like to display the group's name, which I am able to print to the PHP script using:
 print "&$primary_group_name" ;

I'd like to keep this variable separate from the other data/MC and display it only once. Can you tell me how I can display this variable in the SWF?

I'd rather not pass the group name in the url as a GET, in the way that we pass the musical_group_id. I'd like to have the string contain the musical_group_id variable only.

What I want to end up with (some day) is a group of SWFs that perform different tasks based upon a given musical_group_id, so that I can nest them within each other as needed.
I guess the parent SWF would be the one that reads the musical_group_id, then the child movies would refer to the parent movie for the group_id?

Thank you, I guess I will post this as a separate question with whatever points I can find...
0
 
negatyveCommented:
can't you send it as a result of a different page loading?
0
 
meezyartCommented:
neg is the man!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now