Forum Moderators: open

Message Too Old, No Replies

Loading image dynamically

without calling an external page

         

too much information

4:11 am on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've spent almost all night looking for a way to dynamically load an image in Flash from a PHP variable where the Flash movie and the PHP are on the same page.

Basically, I have a PHP script that uses the HTTP Referer data to dynamically create a URL for an image file and I want to display that image file through flash. That's all the flash movie has to do.

I just can't find a site that discribes how to load an image from PHP this way. Does anyone have any clues?

too much information

7:47 pm on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since there doesn't seem to be as much support for flash, I'm going to post what I learn as I learn it. So if this thread is old the last post is probably the right answer. ;o)

I have learned that there are two ways to set values of a flash movie externally to the movie itself.

1) In the <object> tag there are two places where the URL of the .swf file are listed. If you edit the URL to include a querystring the flash movie should take the variables and update itself.
Ex.: domain.com/flash/movie.swf
becomes
domain.com/flash/movie.swf?variable1=value&variable2=value2

2) You can use Javascript to edit the variables
Ex.:
<script language = "JavaScript">
<!--
function PassFlash(){
window.document.movie.SetVariable("text", "hello");
}
//-->
</script>

where "text" is the name of a variable within the flash movie.

Then in the <embed> tag you must include NAME=movie and swLiveConnect=true within the tag. Then you can create a link such as <a href="#" onClick="PassFlash()">Pass The Variable</a> to edit the movie.

I think I am going to opt for method 1, replacing the querystring with something like this:
?variable1=<?=$value1?>&variable2=<?=$value2?>
within my PHP file.

I will let you know if it works.

too much information

7:16 pm on Apr 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, that didn't work like I planned but I'm getting closer.

Here's what I have in my PHP script now:

echo "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='550' height='550' id='SMP1' align='middle'>";
echo "<param name='allowScriptAccess' value='sameDomain' />";
echo "<PARAM NAME=FlashVars VALUE='myjpg=".urlencode($img_src)."' />";
echo "<param name='movie' value='sale.swf' />";
echo "<param name='quality' value='high' />";
echo "<param name='bgcolor' value='#ffffff' />";
echo "<embed src='sale.swf' FlashVars='myjpg=".urlencode($img_src)."' quality='high' bgcolor='#ffffff' width='550' height='550' name='SMP1' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
echo "</object>";

I understand that this should send the variable into the flash movie, but I think I have something different in my action script than what is needed to get this to work. Here is my actionscript code so far:

// (holderName is an optional parameter)
MovieClip.prototype.loadjpg = function(picName, holderName) {
// holderName can be passed in case needed for progress indicator
// if not passed, use 'holder' as default
var h = holderName==undefined? "holder" : holderName;
this.createEmptyMovieClip(h, 1);
this._visible = false;
this[h].loadMovie(picName);
var id = setInterval(function (mc) {
if (mc[h]._width > 0) {
mc._alpha = 99;
clearInterval(id);
// may want to move this next line to the onComplete routine
// instead, if visibility is to be set after positioning
mc._visible = true;
mc.onComplete();
} else {
mc.onLoading();
}
}, 80, this);
};
function positionIt() {
this._x = 0;
this._y = 0;
}
this.createEmptyMovieClip("myjpg", 1);
myjpg.onComplete = positionIt;
myjpg.loadjpg("spacer.jpg");

Hopefully I will have this problem solved by tonight.

Again, just for reference, here is my goal. To load a single jpg in a flash movie with the jpg being fed to the movie by a PHP variable.

(Sounds to simple to be as dificult as it is proving to be.)

too much information

11:48 pm on Apr 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



WOO HOO! I got it.

Here's what I did

One frame only in the flash movie. (or the image will 'flicker') the actionscript for that one frame is:

this.createEmptyMovieClip("image_mc", this.getNextHighestDepth());
var mclListener:Object = new Object();
mclListener.onLoadStart = function(target_mc:MovieClip) {
target_mc.startTimer = getTimer();
};
mclListener.onLoadComplete = function(target_mc:MovieClip) {
target_mc.completeTimer = getTimer();
};
mclListener.onLoadInit = function(target_mc:MovieClip) {
var timerMS:Number = target_mc.completeTimer-target_mc.startTimer;
target_mc.createTextField("timer_txt", target_mc.getNextHighestDepth(), 0, target_mc._height, target_mc._width, 22);
target_mc.timer_txt.text = "loaded in "+timerMS+" ms.";
};
var I;
var image_mcl:MovieClipLoader = new MovieClipLoader();
image_mcl.addListener(mclListener);
image_mcl.loadClip(I, image_mc);

Then in the page that loads the movie, you have your PHP that pulls the image location from a database (or whatever) and you feed the image to the movie like this:

echo "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='550' height='550' id='SMP1' align='middle'>";
echo "<param name='allowScriptAccess' value='sameDomain' />";
echo "<param name='movie' value='sale.swf?I=".urlencode($img_src)."' />";
echo "<param name='quality' value='high' />";
echo "<param name='bgcolor' value='#ffffff' />";
echo "<embed src='sale.swf?I=".urlencode($img_src)."' swLiveConnect=true quality='high' bgcolor='#ffffff' width='550' height='550' name='SMP1' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
echo "</object>";

The location of the movie is passed as a querystring value in the call to the flash movie. You have to have this call in the <PARAM> tag and also in the <EMBED> tag for it to work.

*i'm still learning flash, so each time I have a challenge I plan to post my progress. I hope the rest of you that are learning will do the same. Flash doesn't get much help around here because it is often used in ways to annoy people.

SWFWizard

2:12 am on Apr 24, 2005 (gmt 0)

10+ Year Member



You visited ActionScript.org lately? Get answers to all your Flash scripting questions there, including Flash + server side scripts

Jupityjupe

6:33 am on May 23, 2005 (gmt 0)



hi too much,

am trying to use your script but am a beginner in flash.

I am trying to create a gallery of thumbnails that will lighten on rollover and link to a main image, the thumbnail image name coming from a php page with mysql database. Flash i believe is the answer to this.

I have created a flash movie (version MX) called loader and pasted your code into the first and only frame. Here is the code I put into the php page.

echo "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' width='130' height='130' id='SMP1' align='middle'>";
echo "<param name='allowScriptAccess' value='sameDomain' />";
echo "<param name='movie' value='../images/darkThumb/loader.swf?I=".urlencode($row_rsSc['thumbnail'])."' />";
echo "<param name='quality' value='high' />";
echo "<param name='bgcolor' value='#ffffff' />";
echo "<embed src='../images/darkThumb/loader.swf?I=".urlencode($row_rsSc['thumbnail'])."' swLiveConnect=true quality='high' bgcolor='#ffffff' width='130' height='130' name='SMP1' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
echo "</object>";

Can you tell me where i am going wrong? Is sameDomain something i have to change or could it be that i need MX2004 for the code to work? Many thanks in advance.

Jupity