all groups > macromedia flash flash remoting > march 2005 >
You're in the

macromedia flash flash remoting

group:

Reusing Flash Remoting 2.0 in several .swf


Reusing Flash Remoting 2.0 in several .swf J.Sal
3/8/2005 8:58:34 AM
macromedia flash flash remoting:
I am making an application using flash mx 2004 and remoting 2.0 that uses
several different .swf files (about 30 files, each one with about 8 kb without
remoting). This architecture is important since these swf movies are only
loaded when needed, and are reused in another projects.

I need to use remoting in every files, so, since it's remoting 2.0, i have to
drag the remotingClasses to the stage of each file. Since remotingClasses is
about 10 kb, my movies that once had 8kb, now have 18 kb. Multiplied by 30, my
flash application now has 540 kb (and once, it was 240 kb).

I've tried to reuse the RemotingClasses, only putting them in the library.swf
(shared by all movies), but it didn't work, since i get actionscript errors
when compiling the movies, originated by actionscript 2.0 script typing:

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: The class

'ResultEvent' could not be loaded.
function echoString_Result(result:ResultEvent)


So, my question is:

- How can i reuse Remoting 2.0 Classes in every swf file, without adding 10 kb
to each of them?....


Thanks for your attention, and sorry for my English. (I'm Portuguese ) :P
Re: Reusing Flash Remoting 2.0 in several .swf Pete Thomas
3/11/2005 4:46:01 PM
Hi Your best bet is probably to use import.mx.remoting etc.. into a base movie
that loads subsequent SWFs. Create your service etc there and put it into
global scope. Then ALL you need to do is make your calls to the global scope
with custom responders. The code below should do the trick but in no means is
the only way of doing it import mx.remoting.DataGlue; import
mx.remoting.NetServices;
NetServices.setDefaultGatewayUrl('http://localhost/flashservices/gateway');
gatewayConnection = NetServices.createGatewayConnection(); _global.myService =
gatewayConnection; _global.serviceConnection =
_global.myService.getService('myservices.service.cfc');
_global.serviceConnection.yourmethod(new CustomReponder(),yourargs);
function CustomResponder() { this.onResult = function(result) { // stuff to
do } } this.onStatus = function(error) { trace(error.code+' -
'+error.description); } }
Re: Reusing Flash Remoting 2.0 in several .swf J.Sal
3/12/2005 12:55:09 PM
First of all, thanks for your reply!

That was what i was trying to do: only the main movie imports remoting,
instances the services to the global stack and then it loads subsequent movies.
But, when the subsequent movies call the service, they have to attach
responders to the call. Like:

_global.serConfig.getInfoEtiqueta().responder = new RelayResponder(this,
"echoString_Result", "onStatus");

The problem, is where i define this responders. It would be great help, if
they were defined in my loaded movies. The problem is that actionscript 2.0
strict typing doesn't allow this, i have to import the remoting services. I mean

Responder Definition Header:

function echoString_Result(result:ResultEvent)


Error retrieved

**Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 5: The class
'ResultEvent' could not be loaded. function
echoString_Result(result:ResultEvent)

Now... I am thinking in two possible solutions (not perfect, but, hey...). The
first one, is to create a general custom responder that is defined in the root
movie, and it receives also a callback function (defined in the loaded movie).
When the responder is called, it passes the value on result.result to the
callback. The second one, is to import the ResultEvent class in every movie
that needs it. Problems: added filesize, and... doesn't know if it really works.

Well... i'll try both this solutions, but if there is a better one, please,
let me know!!
(The ideal one was to put the remotingClasses in a shared library, and use
them importing from the library.. but, i wasn't able to get it to work).

Thanks for your attention, once again!
AddThis Social Bookmark Button