PDA

View Full Version : AS3 - XML Socket only works during compile..?


ignitrix
10-06-2006, 09:01 PM
I wrote a Flash AS 3.0 Preview .fla & .as files that establishes a connection with a C++ server app via an XML Socket. Everything works great when I start the .swf file within Flash 9 Public Alpha by pressing [CTRL]+[ENTER]. But if I close the exported .swf file, and immediately open the file with the standalone Windows Flash 9 Player (I tried it with the player that comes with the Alpha preview and the brand new Player released on Oct 4 on Adobe Labs), no connection to the server is established. What gives?

ignitrix
10-09-2006, 10:10 PM
The problem was related to Flash's new Security settings. When you compile and run something using the Flash IDE, it is automatically a fully trusted application (since you compiled it). However, if you just run any old .swf file, it no longer automatically views this file as a "trusted" file (makes sense) and places it in a different security sandbox (http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/js/html/wwhelp.htm?href=00001950.html). I ended up making a new FlashPlayerTrust cfg file to get it to work. The FlashPlayerTrust folder on my computer was located at: C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrus t. Add a new file in the form, "whatever.cfg" and add the following:

# Trust the following folders and/or files:
C:\Documents and Settings\username\Desktop\MyFolderToTrust
C:\Documents and Settings\username\Desktop\MyMixedTrustFolder\myfil e.swf

For some other information on Flash security settings:
http://www.adobe.com/devnet/flashplayer/articles/flash_player_9_security.pdf
http://livedocs.macromedia.com/labs/as3preview/langref/flash/system/Security.html

Hope that helps,
~JC

levrek1
01-25-2007, 03:26 PM
I have the same problem. Using the flash code and Php code from Kirupa's tutorial (with proper adjustments in IP , etc), everything works fine when I run the .swf in my local Flash player. But when I move it to a browser, I get "Connection to Server Failed!". I've tried it locally. I've alsoput the .php file, the .swf file and the embedding .html file all in the same directory on the server (all the same sandbox?) and it fails. Whats up?

ignitrix
01-25-2007, 03:56 PM
I finally figured my problem out. It all has to do with security settings. Since flash has become "more powerful", a hacker could use it to do some bad things. So, by default, a program cannot access local files or network connections unless you "trust" it.

If you run it after a compile, it is automatically "trusted". If you run it in the standalone player, create a text file called blahblah.cfg (blahblah can be whatever you wish) and add the local path to the file you wish to "trust" or you can add the local path to the folder that contains the file you wish to trust. Then save this file in the following location:

Windows:
C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrus t

Linux:
~/.macromedia/Flash_Player/#Security/DigiTrusts.cfg

Mac:
(not sure, haven't needed to use...)

If you are running it in a browser, go to the following web page: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html#117502, click "Edit locations..." --> "Add location..." --> and the location of the file you wish to trust.


HTH,

~Nate Chatellier

levrek1
01-26-2007, 04:28 PM
Thank you. This (i.e. the C:\WINDOWS\system32\Macromed\Flash\FlashPlayerTrus t file) definitely solves it for local .swf files shown either through the Flash player or via a browser. I had hoped to actually store the swf file on a server somewhere and this doesn't seem to be possible. The Global Security Settings form does not seem to work for remote files. Indeed, the documentation says it is only for local files. If you know different, please let me know. Also, if you know some tricks about the format in which to enter remote, server-resident files into the GSS, please let me know that as well since it is possible that I am simply making a syntactic error. (e.g. I am assuming it is "http:// xx.xx.xx/directory"(...)

ignitrix
01-26-2007, 05:55 PM
Although I have not had personal reason to do/test this yet, I remember reading something about using a "cross-domain policy file". I'm pretty sure this is what you need to use.

Do some web research. Try starting here:
http://livedocs.macromedia.com/flex/2/langref/flash/system/Security.html


HTH,
~Nate

jsquared90
05-30-2007, 03:49 PM
Being a nubee to the world of computer programming, and completely self-taught, I would love a little enlightenment to writing this cfg file. I too need to alleviate the security settings to SWF files (that involve XML sockets) that I've compiled, and what I've read in this thread is brilliant to solving my dilemna.

So here are my questions:

1. Can a .cfg file be written in any text editor?
2. If so, does it need to be saved in UTF-8 or something else?
3. How does this file get executed/ implemented in relation to Flash? (ie: does it need to be in the Windows start folder? run before running Flash Player? What app does it get run with?etc....)
4. Does the "trusted" directory NEED to reside in a 'Macromedia' style path as suggected by the example, or can it be any arbitrary place?

Many thanks to anyone who can help?

ignitrix
05-31-2007, 06:34 PM
See http://natejc.com/blog/?p=54 for more information.