Click here to Skip to main content
6,295,667 members and growing! (12,382 online)
Email Password   helpLost your password?
Web Development » Applications & Tools » Tools with source code     Beginner License: The Code Project Open License (CPOL)

Replace the value of variables in a SWF file

By BruceWang_korea

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.
C++ (VC6, VC7, VC7.1, VC8.0), C, Windows (Win2K, WinXP, Win2003, Vista, TabletPC), Win32, CEO, Architect, DBA, Dev, QA, Design
Version:2 (See All)
Posted:22 Jan 2008
Updated:18 Feb 2008
Views:11,029
Bookmarked:13 times
Unedited contribution
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
4 votes for this article.
Popularity: 1.90 Rating: 3.15 out of 5
1 vote, 25.0%
1

2
1 vote, 25.0%
3

4
2 votes, 50.0%
5

Introduction

= 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.


Background



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.



Using the code

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".


Thanks for mr. Mike Swanson, and I hope my little changes in his code help some other person who was searching for this kind of simple function.
Please use this free, because I have to admit that this kind of modification can be done anyone of you, if you were just interested. And
actually I did no special thing to mr Mike Swanson's original code. I just hope my buggy code NOT give you a horrible problem. :P

Points of Interest

I think reading and changing the ActionScript code inside the SWF file will be also interesting thing. Let's try later. :)

History

Keep a running update of any changes or improvements you've made here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

BruceWang_korea


Member
- From South Korea.
- Currently working and living in Japan.
- C/C++/C#/PHP/Ruby/FlashLite/Flex developer.
- Experience and interest in Information Security,
TCP/IP networking, Online game, Web, Mobile, etc..
Occupation: Software Developer (Senior)
Location: Korea, Republic Of Korea, Republic Of

Other popular Applications & Tools articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
GeneralDownload not available PinmemberJoachim7413:32 14 Apr '09  
GeneralUpdate DefineText2 PinmemberKoudjo1:06 31 Oct '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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