Solved

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

Posted on 2003-12-05
18
12,273 Views
Last Modified: 2007-12-19
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
Comment
Question by:billywig
  • 9
  • 8
18 Comments
 
LVL 27

Expert Comment

by:negatyve
ID: 9912822
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
 

Author Comment

by:billywig
ID: 9912972
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
 
LVL 27

Expert Comment

by:negatyve
ID: 9913038
ehm, I think I do not understand what's the real application actions flow..
0
 

Author Comment

by:billywig
ID: 9913109
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
 
LVL 27

Expert Comment

by:negatyve
ID: 9913220
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
 

Author Comment

by:billywig
ID: 9913425
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
 
LVL 27

Expert Comment

by:negatyve
ID: 9913494
>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
 

Author Comment

by:billywig
ID: 9913591

>// HERE WHAT DOES HAPPEN?

I get a blank javascript alert.


>no, why it should?

I had 2 </OBJECT> tags.........
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9913653
>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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:billywig
ID: 9913902
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
 

Author Comment

by:billywig
ID: 9913943
However, if I comment-out the alert and load the swf directly with an ID added I still get a blank SWF.
0
 
LVL 27

Expert Comment

by:negatyve
ID: 9914625
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
 
LVL 27

Accepted Solution

by:
negatyve earned 300 total points
ID: 9914635
0
 

Author Comment

by:billywig
ID: 9914695
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
 
LVL 27

Expert Comment

by:negatyve
ID: 9934164
>I'm learning alot of stuff here.

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

cheers!
0
 

Author Comment

by:billywig
ID: 9943873
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
 
LVL 27

Expert Comment

by:negatyve
ID: 10002987
can't you send it as a result of a different page loading?
0
 

Expert Comment

by:meezyart
ID: 14304597
neg is the man!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Inserting a pop up image to a scanned PDF 5 424
SWF won't scale? 4 518
How to display a webpage in a flash 10 344
Rotating Adobe pdf document 4 300
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now