|
|
|
#1 |
|
Moderator
Join Date: Jul 2001
Location: Estonia
Posts: 8,193
|
[F9/AS3] byteArray example
Lets say you have swf which (for the sake of our example) simply has 1 line of code:
PHP Code:
The swf is then exported under name "loadedswf.swf". Now instead of loading it directly, we will convert it into byteArray object to be used in our larger project. PHP Code:
Now you need to load byteArray from text file and convert it into usable swf file again in your main movie: PHP Code:
Instead of loading byteArra from external file, you could also include it straight into main file: PHP Code:
For anyone decompiling the main swf or looking at the loaded text file, the content of loaded.swf remains only visible as bunch of unhelpful bytes. Sorry for not using proper classes and FCS3 here, examples are made with F9Alpha, you can simply copy/paste the code into Flash and test the movie. |
|
|
|
|
|
#2 |
|
5+5=55
Join Date: Jun 2006
Posts: 698
|
This is really cool Tonypa! Thanks for the example
Any idea how fast this would be for larger swfs? |
|
|
|
|
|
#3 |
|
Student
Join Date: Apr 2001
Location: -
Posts: 4,756
|
I somehow miss a summary,- for wich fields is this technique usefull- can you give us/ me some samples ? You directly get to the practice- but I am not yet sure what it is for.
__________________
my new home: polycount old: Curing C. tech | Curing C. designs | tank | ortho. | zelda LTTP | Tile Edit. | scrolling 3d: 3d engine kit | ASE format | 3d binary format |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Sep 2000
Posts: 1,339
|
Very nice Tonypa. I've been playing around with some of this too. One suggestion, before you convert your byte array to a hex string, you should compress it using the compress() command and then use uncompress() right before you pass the byte array to the loader. This will cut the output size a great deal as zlib is pretty effective.
__________________
Michael Grundvig Electrotank, Inc. http://www.electrotank.com mike@electrotank.com ElectroServer 4 multi-user server - forum |
|
|
|
|
|
#5 | |||
|
Moderator
Join Date: Jul 2001
Location: Estonia
Posts: 8,193
|
Quote:
Quote:
*to make it harder for every kid poking around in your swf code. I believe there is already too many tutorials and application for cheaters and thieves so taking extra steps to avoid cheating/stealing can only be good thing. I am not claiming this is some magical way to get rid of every bad guy, it is one possible step among others. *this can be used to cut down bandwidth on your host and speed up loading of game. Lets say you game is 5 MB, every time someone loads the game your host sends 5 MB out again, even when the player returns next day. swf files are rarely used from browsers cache (I could be wrong about that, but I dont see cached swfs being used much). Now if you have 50kB loader swf and 5MB main swf loaded as byteArray, you can save the 5MB in users computer using ShareObject. Next time someone from same computer plays the game, you only need to send the small loader swf, check the version saved in SharedObject and load main file straight from there. Not only does it save your bandwidth, but it also loads much faster for visitor (making them happy). Quote:
|
|||
|
|
|
|
|
#6 |
|
M.D.
Join Date: Dec 2002
Location: Shelter
Posts: 4,058
|
I like the sound of stopping hackers more than caching load times. Nice work
|
|
|
|
|
|
#7 | |
|
Senior Member
Join Date: Jun 2003
Location: italy
Posts: 395
|
Interesting
![]() Quote:
The next time you load the same swf, the browser will use the locally cached file. (Quick test: check this game -> http://www.gotoandplay.it/_games/playGame.php?g=190 then close your browser, reopen it and go back to that page. Unless you have turned off your browser cache you'll notice that the game gets loaded instantly) Lapo
__________________
www.gotoandplay.it Flash game developers community www.smartfoxserver.com Multiplayer Flash Server |
|
|
|
|
|
|
#8 |
|
Hype over content...
Join Date: Apr 2001
Location: Lost forever in a happy crowd...
Posts: 5,827
|
Yeah one of the projects I'm working on is a 100% dependant on using the cache to preload assets ( Not sure how much I trust it myself, but the coders who have put that part of it together are confident so I'll take their word for it ).
Nice example T, it's little things like this are making me itch to get all down and dirty with AS3. Squize.
__________________
![]() www.gamingyourway.com | 651:Announce | Voxel Landscape | Kaleidoscope | Tunnel | Dot vectors | Plasma |
|
|
|
|
|
#9 |
|
Moderator
Join Date: Jul 2001
Location: Estonia
Posts: 8,193
|
The cache settings in browsers can be changed by user (turn it off completely, clear it all on exit, clear it when trash is deleted, amount of space given to cached files etc). i also think in case of swf files it depends how you embed them in page (which again I have not tested).
The files that get cached are also easily decompiled. The common route to decompile swf is to get it from browsers cache, I dont see any harm providing alternative way to achieve same thing. The sharedObject itself is of course readable too, but converting it back into original swf requires more work. Good thing about byteArray is that is simply bunch of bytes. You could split it up into multiple files, you could remove header and footer from your swf and include them again in main swf, you could scramble the byteArray, write it backwards.. whatever your imagination can come up with
|
|
|
|
|
|
#10 |
|
Junior Member
Join Date: Jul 2008
Posts: 2
|
multimedia protector
Hi, Somebody use multimedia protector to protect swf project?
|
|
|
|
|
|
#11 |
|
Student
Join Date: Apr 2001
Location: -
Posts: 4,756
|
works only if you wrap it in the proprietary (and probably ugly) *.exe player- not an option thus for online stuff where Flash is dominant
__________________
my new home: polycount old: Curing C. tech | Curing C. designs | tank | ortho. | zelda LTTP | Tile Edit. | scrolling 3d: 3d engine kit | ASE format | 3d binary format |
|
|
|
|
|
#12 |
|
invading soon
Join Date: Mar 2008
Posts: 306
|
Nice method. Its always good to have multiple sets of proofing on your projects, to put off people trying to view your code. Has anyone tested large files with this method, specifically the reconstruction speed?
Is there a way you could use JavaScript or some other language to trigger a browser cache clear. Like ctrl + f5? |
|
|
|
|
|
#13 |
|
Junior Member
Join Date: Jan 2006
Posts: 4
|
Thank you tonypa, your code is of great value for me.
|
|
|
|
|
|
#14 |
|
Junior Member
Join Date: Jul 2009
Posts: 15
|
EDIT: Never mind, I figured it out. Just in case anyone else stumbles upon this with the same problem, I just added the ldr.content to the display list and it worked
![]() sorry for resurrecting this old thread, but it was just what I was looking for in terms of using an swf's bytes. So I did this, and created a simple animation of a box moving: PHP Code:
|
|
|
|
![]() |
|
||||||
| Thread Tools | |
| Display Modes | |
|
|