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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use PHP to insert ActionScript into SWF 1

Status
Not open for further replies.

thenewa2x

Programmer
Dec 10, 2002
349
US
Is there an easy and portable way to insert ActionScript into a premade SWF using PHP? The only thing I want to do is define a variable in [tt]_root[/tt]:

Code:
_root.playlistURL = "[URL unfurl="true"]http://www.domain.com/path/to/playlist.xml";[/URL]

---------------------------------------
 
I'm only allowed to use the [tt]<embed></embed>[/tt] in certain web-sites when posting flash. FlashVars is out of the question but thanks for the suggestion anyway. Any other ideas?

#1.) I have to use PHP.
#2.) I must be able to insert/inject/add a single line of code defining a variable (preferably at the beginning of everything).
#3.) I must not use anything more than the embed tag.
#4.) I must not append anything to the URL in the src attribute in the embed tag: [tt]<embed src="...?var=value"></embed>[/tt]

Thanks.

---------------------------------------
 
dont think i fully understand what you want to do but you could have flash just load a txt file containing the variable

longer way round but you could also have php load the text file and send the contents to flash

text file is just

&playListURL=something

or as a straight php alternative set the variable in php and use the print statement to send it to flash

 
you should be able to put a ?varname=value after the .swf file name in the embed tag, and that should assign it. I used this technique in a webpage some time ago, and it still appears to be working fine. The only "problem" with this is that as the parameters change (from page to page, or as your PHP generates the HTML that houses the .swf), since the URL to the SWF changes, it is not "cached" by most browsers, and will re-download a new copy of the swf. But if you can stand that, this should work for you.
 
Thanks but

#1.) I have to use PHP.
#2.) I must be able to insert/inject/add a single line of code defining a variable (preferably at the beginning of everything).
#3.) I must not use anything more than the embed tag.
#4.) I must not append anything to the URL in the src attribute in the embed tag: <embed src="...?var=value"></embed>

---------------------------------------
 
Paraphrasing Bill to an extent but use the PHP to dynamically write a text file defining the variable in the same directory as the swf, your movie looks at to load in the variable via loadVars()? That way you don't have to alter the tags in the page at all or append data to the URL and the value of the variable is controlled via PHP.
 
thenewa2x, I don't really understand why "FlashVars is out of the question", as this is the best way to accommodate all your requirements. Let PHP to write an <embed> tag:

[tt]<EMBED src="some.swf" FlashVars="playlistURL=http://www.domain.com/path/to/playlist.xml"></EMBED>[/tt]

Kenneth Kawamoto
 
Everything about my SWF is dynamic. Someone visits my site, does something, and generates the embed code. What I try to defeat is the purpose of going back to regenerate the code so the person who created can see an updated version of what they created. For some one is somewhat computer illiterate, this could be irritating.

---------------------------------------
 
Perhaps you meant you want to create a variable from SWF via PHP. If so you can use loadVariables.
[tt]//
loadVariables(" _root)
//[/tt]
Then let your PHP to return variable name & value pair string like this: [tt]playlistURL=http://www.domain.com/path/to/playlist.xml[/tt]

Kenneth Kawamoto
 
the answer is no. you can't just magically (using PHP) insert actionscript into an existing .swf. If the following options are not available to you (which we collectively don't seem to really understand WHY), then you are most likely out of luck:

1. Flashvars, in the embed tag, to tell the browser to set the variable inside the .swf.

2. URL query sting... appending ?var=val to the end of the .swf source value.

3. Changing the .swf to call a PHP script to return it a value (LoadVars)

4. Changing the .swf to call a javascript function (using FSCommand) which could then get it the value from javascript somehow.

If you can't change the .swf file, and you can't dynamically create the embed tag for the user with PHP, and you can't have the .swf file call PHP or javascript, then there really are no other ways to facilitate run-time communication. Sorry.

It sounds to me like you need to figure out how to just create the .swf file completely dynamically using some PHP library.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top