passing php variable to FLASH

Posted on 2006-04-18
Last Modified: 2008-01-09
this is my php file:

GLObal $test;

$test = "'/Photos/P1010049.jpg'";
echo ("test=" .$test);


this is my flash actionscript:

addressVars = new LoadVars();
addressVars.onLoad = function() {
image0uri = addressVars.test;

the problem is that my flash app does not load the php variable and does not show the image i'm wanting to show. If i replace the last line of the action script with:
image0uri =  '/Photos/P1010049.jpg';

it works perfectly.

Any ideas?

Question by:michaelbrewitt
    LVL 9

    Expert Comment

    I don't know squat about flash, but is there a way to echo out variables to see what's set to?

    Like an echo image0uri or something, so you can see what it is actually set to? It might help to know if it's blank, or set to some weird unexpected path.
    LVL 6

    Expert Comment

    Not too familiar with flash, but if that file with the actionscript in it can be parsed with PHP, then you can simply output the variable directly into the script.  Otherwise, here are some links I found: - EE flash area - article on passing variables into flash via html.  output the php variable right onto the page that the user is viewing

    LVL 4

    Expert Comment

    you can pass a vaariable to flash using get


    $myvariable = "testvariable stuff here";
    <object width="550" height="400">
    <param name="movie" value="somefilename.swf">
    <embed src="somefilename.swf?myvariable=<?php echo $myvariable; ?>" width="550" height="400">
    then the variable is passed to the swf file when it is called.
    then you can use the variable myvariable or whatever text is in between the ? and = in the url to the flash file.

    LVL 9

    Expert Comment

    $test = urlencode("'/Photos/P1010049.jpg'");
    echo ("&test=" .$test);
    LVL 1

    Accepted Solution


    Always you need to print the variables with vlaues as query string. Only pre-caution has to be taken is that we need to start the output with "&" so that it adds these variable to the Loadvars object you create in the flash.

    For example :

    print "&var1=value1&var2=value2";

    Suppose you want to post some values to the php script and get the details back, then its better to use

    LoadVars.sendAndLoad method.


    LVL 1

    Author Comment

    tolgoang - that didn't work.

    Anyone else, any more suggestions?

    LVL 4

    Expert Comment

    Did you try my idea??


    PS: I use it on a lot of Flash applications that I have.
    LVL 4

    Expert Comment

    In this contrived example, suppose that you have a Flash movie that loads an image file and display the image (using  loadMovie on Flash MX - if you're using Flash 5, think of it as loading another .swf file).  

    You want to be able to use the same swf file on many pages to show different images.  Obviously, you need to pass the image filename to Flash.  What can you do?  Since a filename is such a simple text, you can use query string to pass it.  

    Assuming the image filename is image1.jpg, located at a folder named images.  And assuming that the Flash movie will use a variable named imageFilename to refer to the file, then we can do this:

    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
      WIDTH="250" HEIGHT="300" id="flaMovie1">
      <PARAM NAME=movie VALUE="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg">
      <PARAM NAME=quality VALUE=high>
      <PARAM NAME=bgcolor VALUE=#FFFFFF>
      <EMBED src="flaMovie1.swf?imageFilename=images%2Fimage1%2Ejpg"
        quality=high bgcolor=#FFFFFF WIDTH="250" HEIGHT="250" NAME="flaMovie1"

    There you see that I appended a query string after the Flash movie filename (flaMovie1.swf).  The query string contains one variable: imageFilename, with the value of images/image1.jpg.  

    Note: The %2F is the url encoding for the "/" sign, and %2E is the url encoding for the "." sign.  Since these symbols are unsafe or reserved, we should url encode them, although at the present Flash does not seem to care.  So saying: imageFilename=images%2Fimage1%2Ejpg is essentially the same as saying imageFilename=images/image1.jpg.
    LVL 4

    Expert Comment

    I found that after searching google and I tested it and that example works.

    LVL 4

    Assisted Solution

    this page has a sorts of methods:


    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    A colleague recently asked me about how to give his client a small part of the web site that could be completely under the client's control.  Since I have done this sort of thing before to add emergency banners to a web site, I decided I would creat…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    732 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

    23 Experts available now in Live!

    Get 1:1 Help Now