![]() |
Web Development »
Applications & Tools »
Tools with source code
Beginner
License: The Code Project Open License (CPOL)
Replace the value of variables in a SWF fileBy BruceWang_koreaThis simple tool enables you to change the 'initial text' of 'DefineEditText' object, which is basically the 'dynamic text' object in the Flash design tools. |
C++ (VC6, VC7, VC7.1, VC8.0), C, Windows (Win2K, WinXP, Win2003, Vista, TabletPC), Win32, CEO, Architect, DBA, Dev, QA, Design
|
||||||||||||
|
Advanced Search |
|
|
|
||||||||||||||||
= The sample image above is not at all related with this program itself, but just for your easier understanding =
This simple tool enables you to change the 'initial text' of 'DefineEditText' object, which is basically the 'dynamic text' object in the Flash design tools.
So For example, you can make a generic SWF file which opens a site of which the URL is defined in a 'Variable' inside the SWF file. And you deliver different SWF files with different URL information to every different users.
Of course, you can change the value of variable in the SWF file just by specifying the parameter for that specific SWF file on the browsers - either by JavaScript, 'Object' tags, and even with simple URL parameter -. BUT, sometimes you can not especially for the FlashLite SWF files which will be played on the mobile phones.
So, in those special cases you can use my simple tool. This is written in C++ so it can be run on Linux/Unix servers also, if those servers are using x86 CPUs -little endian-. Or you can understand the structure of SWF file -up to Flash 8- more easily by reading my code.
I know my code is not so flexible (for example, this works only for Little-Endian CPUs), because it was written in very short time for just checking my understanding of SWF file structure, but you will see you can change this code for your purposes very easily.
Actually this code was originally from [Mike Swanson's blog] who is the Techincal Evangelist of MS, and when I saw his article for the first time I was totally amused because his sample code was perfect to understand the SWF file strcuture even for me who had no idea how the SWF file is organized. So, I was able to finish this code within an hour.
His original code was written in C# and for showing the internal information of given SWF file. So I decided to write down my code for checking
my understanding and added one simple function to change the data in it. If I couldn't see his article, maybe I had to spend long period to understand
the SWF file structure, but by reading his code, everything became so easy. You need to read his article at least once.
Please don't get confused that I change ActionScript byte code itself, because this doesn't. And I didn't implement for the 'Compressed SWF' format,
but according to mr. Mike, it is also simple. I think my code will work for from FlashLite1.0 upto Flash8.
I hope my article can help you to understand the SWF file format more clear, for your academic purposes.
This is very simple. Please open the 'swfvartool.cpp' file and you will see the simplest 'main()' function.
You just open a SWF file, change the value of variable you want to change (by calling 'ChangeEditValue()' function of SWFFile class), and save to another file.
That's all.
SWFFile *swf = new SWFFile( (char*)argv[1]);
/// Change the value of 'outputtext' (the 'DefineEditText' object) in the given
/// SWF file to "hello, test".
swf->ChangeEditValue("/:url","http://iambrucewang.blogspot.com");
/// You can change other variables more just by calling
/// 'ChangeEditValue()' function many times.
///
//swf->ChangeEditValue("_myblog","http://www.test.com");
/// Now finally save the changed data into 'b.swf' file.
swf->SaveTo("b.swf");
delete swf;
For your test, I made simplest SWF file in the sample code project. This just open a URL which is written in the variable "/:url".I think reading and changing the ActionScript code inside the SWF file will be also interesting thing. Let's try later. :)
Keep a running update of any changes or improvements you've made here.
| You must Sign In to use this message board. | |||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 18 Feb 2008 Editor: |
Copyright 2008 by BruceWang_korea Everything else Copyright © CodeProject, 1999-2009 Web19 | Advertise on the Code Project |