Sections
You are here: Home Forum Flash Running an .swf outside the Adobe Flash Editor

Running an .swf outside the Adobe Flash Editor

Up to Flash

Running an .swf outside the Adobe Flash Editor

Posted by g.j. van Trier at February 11. 2008

Hi, I'm pretty new to flash and I wanted to toy around a bit with it.

So far so good, everything works, all the examples work, but..

Once I run the .swf files outside the Adobe Flash Editor itself it all stops, after some time I finally managed to figure out why and it was (of course) security related.

Putting the "local playback security" in the publishing settings to "Access network only" fixed things for me, I thought..

Now the .swf files DO work in firefox,
but still not in Internet Explorer or in the Adobe Flash Player.

I'd like to use the full screen function from the Flash Player ; ) that's why i choose for flash, so it would be nice if someone could point me in the right direction.


*With "Access network only" switched on the examples DO make an XML connection with mchelper, while using IE or the Flash Player, but it only lasts like a split-second.


Re: Running an .swf outside the Adobe Flash Editor

Posted by g.j. van Trier at February 11. 2008

After some reading I'm starting to think that this problem is also related to Chris Cote's his: "AS3 Failed to load policy file" thread here on the forums.

Not sure tho ; )

Re: Running an .swf outside the Adobe Flash Editor

Posted by Liam Staskawicz at February 11. 2008
Have you been able to run in a non-debug mode? That was the conclusion that he came up with - it only made that request when running in debug mode.

Re: Running an .swf outside the Adobe Flash Editor

Posted by g.j. van Trier at February 12. 2008

I never tried the debug mode before ; )
With publishing settings at: "access networking only" results are:


working:
firefox
adobe flash editor

not working:

adobe flash player
adobe flash editor - debug mode
internet explorer


After I debugged once in the adobe flash editor my standalone adobe flash player throws out error messages from now on. (which it didn't do before)


Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation: file:///C|/Documents%20and%20Settings/Sir%20Evert/Desktop/MC/MakeController%2DAS3%2Dv1.0/
examples/SingleLED.swf cannot load data from localhost:11000.
    at com.makingthings.makecontroller::McFlashConnect/connect()
    at SingleLED_fla::MainTimeline/SingleLED_fla::frame1()

Again at mchelper it shows up as "new xml connection" and "xml peer disconnected" at the same moment.

Re: Running an .swf outside the Adobe Flash Editor

Posted by g.j. van Trier at February 12. 2008

When i run it from my apache local server it DOES work in internet explorer

"really confused"

So it really is an security sandbox violation somehow, since flash sees localhost as a server like any other?


Re: Running an .swf outside the Adobe Flash Editor

Posted by g.j. van Trier at February 12. 2008

I've found a workaround on:

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000349.html#wp122778

While using the "The User Flash Player Trust directory" method i can run the .swf in any program from the specified directory.

Yet this is supposed to be handled with the "Socket policy files" method I think. also described on that page.

Re: Running an .swf outside the Adobe Flash Editor

Posted by Liam Staskawicz at February 12. 2008
Again, if you determine there's a way to modify mchelper to make this easier/more straightforward please let me know.

Re: Running an .swf outside the Adobe Flash Editor

Posted by g.j. van Trier at February 15. 2008

I will look into it this weekend ; )

Re: Running an .swf outside the Adobe Flash Editor

Posted by Chris Cote at April 03. 2008

Hey guys, I figured this would come again. We should in fact be supplying a socket policy file. I've made a python OSC server that handles flash and the controller. it's still very early, but maybe (Liam) you could see how I'm handling the policy file request.



<code>

import socket
import select
from oscAPI import *
from OSC import *
import cjson
import time


class oscserver(object):
   
    def __init__(self, host, tcp_port, udp_port):
        self.tcp_port = tcp_port
        self.udp_port = udp_port
        self.udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
        self.tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.host = host
        self.bind(self.udp, host, udp_port)
        self.bind(self.tcp, host, tcp_port, True)
        self.inputs = [self.tcp, self.udp]
        self.outputs = []
        self.policy_flag = '<policy-file-request/>'
        self.running = False
        self.udp_outdata = None
        self.tcp_outdata = None
        self.addr = {}
        self.data = {}
        self.on = 1
        self.finding = True
        self.find_controller()
       
    def bind(self, _socket, host, port, listen=False):
        try:
            _socket.bind((host, port))
            _socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 0)
            _socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
            if listen: _socket.listen(1)
        except socket.error, err:
            print "Couldn't be a server on port %d : %s" % (port, err)
            raise SystemExit
           
    def find_controller(self):
        #while self.finding:
            msg = createBinaryMsg('/network/find', [])
            self.udp.sendto(msg, ('<broadcast>', self.udp_port))
            #print self.finding
   
    def flash_policy_file(self):
        return "<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\""+str(self.tcp_port)+"\" /></cross-domain-policy>\0"
   
    def start(self):
        self.running = True
        try:
            while self.running:
                input, output, exc = select.select(self.inputs, self.outputs, [])
                for sock in input:
                    if sock == self.tcp:
                        client, addr = sock.accept()
                        self.inputs.append(client)
                        self.addr[client] = addr
                        print "Connected from: ",addr
                    else:
                        if sock == self.udp:
                            data, address = sock.recvfrom(512)
                            if data.find('/network/find') != -1:
                                address = (address[0], self.udp_port)
                                print "we have the controller at: ",address
                                self.addr[sock] = address
                                self.finding = False
                        else:
                            data = sock.recv(512)
                        if data:
                            if data.find(self.policy_flag) != -1:
                                sock.send(self.flash_policy_file())
                                print "Sent policy file to", self.addr[sock]
                            else:
                                self.data[sock] = data
                                if sock not in output: output.append(sock)
                                print "%s bytes from %s" % (data, self.addr[sock])
                        else:
                            print "disconnected from", self.addr[sock]
                            del self.addr[sock]
                            try: output.remove(sock)
                            except ValueError: pass
                            sock.close()
                            self.inputs.remove(sock)
                               
                for sock in output:
                    sendata = self.data.get(sock)
                    if sendata:
                        totsent = False
                        for key in self.inputs:
                            if key != sock:
                                #don't send to yourself
                                if key == self.udp:
                                    #if it's a controller
                                    try:
                                        sendata = self.str_binary(sendata)
                                        if sendata:
                                            totsend = 0
                                            print "DAAATA: ",sendata
                                            for da in sendata:
                                                totsend+= key.sendto(da, self.addr[key])
                                    except KeyError:
                                        print "no controller yet"
                                elif key != self.tcp:
                                    print "sending to tcp client"
                                    sendata = self.binary_str(sendata)
                                    totsend = 0
                                    if sendata:
                                        for da in sendata:
                                            print "DA: ",da
                                            totsent+= key.send(da)
                                if totsent:
                                    print "%d bytes to %s" % (len(sendata), self.addr[key])
                                    sendata = sendata[totsent:]
                            else: pass
                    if sendata:
                        print "%s bytes exist for %s to send" % (sendata, self.addr[sock])
                    else:
                        try: del self.data[sock]
                        except KeyError: pass
                        output.remove(sock)
                        #print "No data curently remain for", self.addr[sock]
           
               
        finally:
            self.close()
           
    def binary_str(self, data):
        print "raw from cont: ",data
        message = decodeOSC(data)
        messes = [];
        if isinstance(message[0], list):
            for mess in message:
                a = {}
                a['address'] = mess[0]
                a['typetags'] = mess[1]
                a['arguments'] = mess[2:]
                try:
                    str = cjson.encode(a)
                    print "Encoded JSON: ",str
                    messes.append(str)
                except TypeError,cjson.EncodeError:
                    print "couldn't encode binary"
        else:
            a = {}
            a['address'] = message[0]
            a['typetags'] = message[1]
            a['arguments'] = message[2:]
            try:
                str = cjson.encode(a)
                print "Encoded JSON: ",str
                messes.append(str)
            except TypeError,cjson.EncodeError:
                print "couldn't encode binary"
               
        return messes
   
    def str_binary(self, data):
        try:
            objs = data.split('__|*|__')
            rets = []
            for jso in objs:
                if len(jso) > 0:
                    obj = cjson.decode(jso)
                    if isinstance(obj, list):
                        bundle = createBundle()
                        for msg in list:
                            appendToBundle(bundle, msg['address'], msg['arguments'])
                        ret = bundle.message
                    else:
                        ret = createBinaryMsg(obj['address'], obj['arguments'])
                       
                    rets.append(ret)
               
            return rets
        except cjson.DecodeError:
            print data
            print "couldn't decode json string"
            return rets
   
    def __del__(self):
        self.close()
   
    def close(self):
        self.udp.close()
        self.tcp.close()
        print "Servers closed"
                       
   
 </code>

Re: Running an .swf outside the Adobe Flash Editor

Posted by Chris Cote at April 03. 2008

I would imagine in your Board.c file right by the /nework/find logic, you could slide it in.

Re: Running an .swf outside the Adobe Flash Editor

Posted by ben rigby at July 06. 2008

i dunno if this is the problem, but whenever i run into sandbox violations, it's usually something to do with the crossdomain.xml file. http://cflex.net/showFileDetails.cfm?ObjectID=287&Object=File&ChannelID=1

Powered by Ploneboard
Document Actions