using swf in a string to populate loader.loadbytes


#1

Hi all,

Is it possible to use a string to hold a swf file and then use that in loader.loadbytes to invoke/load the same since I wish to load it directly into the memory.If possible, kindly elaborate with an example.

Normally this action is carried out using an embedded swf file.

Thanks all !


#2

loadBytes loads SWF from a ByteArray. ByteArrays could potentially be strings, but generally you wouldn’t want to serialize it into a string just to have to convert it back to a ByteArray to use it in loadBytes.

Why do you want a string?


#3

Hi Senocular,

Thanks for the reply. Actually this continues from the previous post (loadbytes throws TypeError: Error #1007:) where I tried to embed the external swf from another file but could not get it to work even after many tries.

Then I thought let me pass the swf as a string from php into flash and I managed to do so using the amfphp. So as it stands I have the swf embedded in a string

CWS ~xœSKOQþf¦ó(¥*/I[Ñ!.JJ£c´>k£SÄ7u(Sh§dz¡5!)>¢h¢qUÂÂğàÂ+ë҈㊝ÍqeL©çÎÒ.HœŜs¿{ÏwÎùνUÈ9 ôèp±aô]›ÍæYiW6я1dK%vyÉ4§m¦^fkΨN°‚¢çÍêeƒfËÌ.Zó8°*;ïą́2ä—l۰Øtö*XªÄÍR^gŒ_°Bœ•¦ÜØ%Y9‹lAÏeÈë&åbv9›jÃÝ{7uZ2îúãxqiƒÝX0öJ Gk
P÷CƒJ}B"uš˜}"@à¸Ԋû8.Ôð
¼ïJ8üJDõ^hr®ŠûJ6Z÷Ѷ&;K5Ý Óö÷TøD’aš»Â?·+åÖáa6ɗräե´N·â s¸k‚ÿCο;{õ4·È7=^|Ø9xhÂaémû&&U4#>óÛɯÛï‰üSÝ}ýý±Ç[;ÅhøÎV
흡";"
k· üÿ¸˜¯srÌ(3d¬eÝ,Î
O™Þ-iâv+:õJ^‡p§•áƒÄÃn,Î’âåJ9ÓX6ÌHý.G}ÒÍSACé"¦<zߎ­Î2+A½!LÂmœœÁ[email protected]#I½?¯cOOì¬Gƒë¿PóA¸#$¹Í7”ç’ȍ=[¤ˆlÍ0aeȂrÎ.҅æŠÕ’¦jþQrTþ
ڛÀLpXÆOB’MѽO£­J6Îéë{·Röñ”2C^~^myu5?Ÿ ŠүÈ÷ÝûǰG}jPm#tôP\ùñÀyf.“æ1^=˜IkcrÔPù`6evÞgŠ ¿nño
660

The 660 at the end is it’s length and not part of the string. I must convert this into a byte array now ( the right type ?) and then use that to load the external swf in memory. I am unable to convert this into the byteArray that is needed.

Thanks loads.


#4

If you’re using amfphp you should be able to pass btyearrays through directly. But then, if you’re loading it through the server, why not just load it normally through a normal loader?


#5

You mean using URLRequest(“any.swf”). Would not that save the file to a disk first? That is something that i am trying to avoid and load the swf directly in the memory so that the swf is not readily available. I believe using the embed tags and then using loadbytes was the way to go to prevent the file from saving to disk. The [embed …] code did not work even when i compiled it using flex. So I decided to try it using the swf passed from php to flash as a string,

Well I am not exactly using amfphp, but a very sub version of that which is able to send data as an array of name value pairs where values are all strings.

Please help sort this. I am utterly flustered by this. If you want I can post the code that I have been trying. I have managed to create my byteArray flash side but it gives the following error:

Error #2044: Unhandled IOErrorEvent:. text=Error #2124: Loaded file is an unknown type.

Thanks.


#6

You mean in the cache? The original SWF would be cached, and if you got [Embed] to work, it would be part of that SWF. Any other request would also potentially be cached, but I guess not so much if you’re going through amf… or whatever version you’re using which sounds like it wouldn’t support a bytearray anyway.

Otherwise I’d suggest using a Loader with, yes, URLRequest(“any.swf”). If caching is your concern, you can turn that off with the appropriate headers. Otherwise, things are only loaded into memory, not saved to disk.


#7

Hi,

No, in one of the many articles / replies that I read on the issue, it stated that the external file is saved in one of the tmp folders on the local client machine. So I thank you for clarifying that it is not so and that it’s saved only in the cache.

Otherwise, things are only loaded into memory, not saved to disk.

Would that imply that embedding the file in the swf and using loadbytes to load it has no benefit over using URLRequest to do the same? Or is it that the in the latter case the swf is additionally cached while not in the former?

If using amfphp could work, then i think that there would be one great benefit which would be that the external swf and it’s path would be completely unexposed. commands like wget or curl would be rendered completely useless as the swf can be easily stashed in some folder above the root making it totally inaccessible.

I am uploading the bit of code that I am working on here in case you or anybody would care to take a look.

Looking forward to your reply and thank you loads
!flash_amfphp.zip (19.2 KB)


#8

Hi Senocular,

Ok, so it was a simple issue of encoding the string in php before sending it across to AS3.

I was confused because sending the file across into flash and using strToUTF16 was tracing an almost identical file as the php echo, and I mistook them to be the same. But when I tried to use the data to populate byteArray, it gave an EOF error which meant that something was amiss and that they were not identical. I think sending raw data across is, in any case, a bad idea.

I would be glad to receive a reply to the questions/doubts I had in #7 message. One more thing I would like to ask is that how safe do you think this method would be for loading a movie as compared to URLRequest or Embedding the data.?

Please find below the attached working code.
flash_amfphp.zip (13.8 KB)

Thanks loads.


#9

There’s nothing unsafe about doing it this way. Its not much different than any other, just a different format over the wire.


#10

:+1::+1:, Thanks !!