I have written a php script that changes the value of a string within a SWF file. I use the php script on the server side to hard code new values for variables in a SWF.
I wrap values in xml tags to identify the variables. For example, in the Flash authoring tool I create an actionscirpt variable:
fristname = "<fn>First Name1</fn>" // has 20 characters
The php script opens the SWF, and finds and replaces the text within the <fn> tags with my new text value.
The problem is that the SWF file expects the character length of the variable value to be the same length as the original value (20 characters in the above example). There is a binary value that defines the length of the firstname variable. Flash will not display the swf if the value is not the exact length that the binary value defines. I can work around this when I pass values shorter than the original, by padding the string with spaces, but do not have a solution for longer values.
// pad the new 7 character string with 5 spaces so the entire string totals 20, including the tags
firstname = "<fn>new val_____</fn>"
My next goal is to use php to change the binary value of the variable length so that it matches the string I want to insert, so I do not have to truncate strings that are too long and pad strings that are too short.
So I want to be able to use php to write any new string into a given variable.
Are there any PHP based open source solutions that do something similar? I am using a shared web server and cannot install c libraries like MING or com objects. So this would be a php solution only.
If not, can someone help me understand how I would find and change the binary value of the variable? I can follow up with php specific questions in another forum, I am just trying to get some understanding of how a script might find the variable corresponding to a given text within a SWF file, read and write the binary value defining the length of the variable.
reading a swf file through php, and then altering some values, seems to be a big task - although it is feasible. There is an easier approach, if it suits your application: you could create a swf without these data, and then use php to amend the swf with just one action block that sets all the required variables.
This is equivalent to adding something like
Code:
var name = 'John Doe';
var amount = 54.00;
var counter = 23;
to the first frame. Of course, if you dont want to clutter the root namespace, you could also compile
Code:
var mydata = {name:'John Doe', amount:54.00, counter:23};
I don't know why today it is working... I don't know...
I have an other problem:
I can't download the flas file. When I embed your script in an html page, it is showing perfectly the new modified swf. but I don't know how to donload it. when I open the page of the script it is downloading an incorrect flash file (not empty, and not corrupted).
here is an example of what I want to do: www.aslabs.com/swf/index.php
you have here a flash called final.swf wich have at the top a button calling to clickTag parameter. from the first page I add in the link I wanto to open in the session then I have this php :
PHP Code:
<?php
session_start();
class object {}
class swf
{ var $fh;
var $buffer;
var $bufbits;
var $stdout = 0;
the same first page is also showing the new created file:
Code:
<object id="FlashID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="728" height="90">
<param name="movie" value="<?php echo $url; ?>" />
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="6.0.65.0" />
<!-- This param tag prompts users with Flash Player 6.0 r65 and higher to download the latest version of Flash Player. Delete it if you don’t want users to see the prompt. -->
<param name="expressinstall" value="Scripts/expressInstall.swf" />
<!-- Next object tag is for non-IE browsers. So hide it from IE using IECC. -->
<!--[if !IE]>-->
<object type="application/x-shockwave-flash" data="<?php echo $url; ?>" width="728" height="90">
<!--<![endif]-->
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="swfversion" value="6.0.65.0" />
<param name="expressinstall" value="Scripts/expressInstall.swf" />
<!-- The browser displays the following alternative content for users with Flash Player 6.0 and older. -->
<div>
<h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" width="112" height="33" /></a></p>
</div>
<!--[if !IE]>-->
</object>
<!--<![endif]-->
</object>
were "$url = swfaddvars.php".
now up to here it is working fine. but when I open the link:
well - when I open swfaddvars.php after completing the form, it seems to do the right thing - the button leads to whatever I entered into the form before.
There does not seem to be a way to set that $var_val variable to force downloading from the current browser ... and a download accelerator would not maintain the session
well - when I open swfaddvars.php after completing the form, it seems to do the right thing - the button leads to whatever I entered into the form before.
There does not seem to be a way to set that $var_val variable to force downloading from the current browser ... and a download accelerator would not maintain the session
Musicman
Hi thank you...
I have worked on the swfaddvars.php and now everything is working (it downloads the SWF file in the correct way)
I have now a little different problem:
I whould like now to save in the server the created file. I have tried to change "$oswf = new swf("", "w"); " by $oswf = new swf("newfile.swf", "w");
this is not working: the resulted file contains only:
Code:
FWS„
x „ C "–
How can I modify the script in order to save the created file?
as I said before, this is going to be a big task - effectively the php would have to interpret all actions associated with buttons, and then rewrite the right one.
What kind of problem would you want to solve there?
This would be great to change wrong click tags, insert stop() function at some frame, etc. These actions can be performed by "Action Script Replacer" tool and I was wondering if they could be done via PHP.
adding compression would not be too hard...
The basic problem - to edit vars this way yu need to
a) read the swf ... the loop above does that
b) check that the tag type is actions
c) parse the actions to make sure only the right things are altered
d) adjust tag length ... it is in the code
e) adjust overall size of swf file