PDA

View Full Version : how can i have flash send a variable to another flash movie


smartie_on_computer
04-27-2006, 02:46 AM
how can i have flash send a variable to another flash movie on same domain but differn't computer's?

i've tryied localconnection, but does not work or i have'nt done it right:rolleyes:

sender.swf
var _sending_lc:LocalConnection = new LocalConnection();
_sending_lc.allowDomain("smartie.awardspace.com");
var rot:Number;
var prop:Array = new Array(3);
_root.onEnterFrame = function() {
rot = _root.player_mc._rotation;
_root._sending_lc.send("game", "prop",rot);
};

and the receiver:
var _aLocalConnection:LocalConnection = new LocalConnection();
_aLocalConnection.allowDomain("smartie.awardspace.com");
_aLocalConnection.connect("game");
_aLocalConnection.prop = function(prop) {
_root.enemy_mc._rotation=prop;
};

Flash Gordon
04-27-2006, 03:52 AM
XMLSocket.

Let me know if you ever get it working.

snapple
04-27-2006, 09:44 AM
You would use a local connection object for this. I wouldn't use the XMLSocket - thats for serverside stuff which is not really what your doing.

Flash Gordon - why, you had previous trouble with the XMLSocket class?

Regards, snapple

Flash Gordon
04-27-2006, 03:51 PM
Sorry for my mis-guided advice. Snapple is the man, go with what he says.

But yeah. I could never the the PHP scripts to work right to support the XMLSocket. :( I know you're a Java man. I think I stumped upon a thread where you wrote you with it.

snapple
04-27-2006, 04:19 PM
Yeah - i have been using the XMLSocket class recently. I found it incredibly easy to set up and use (apart from 1 problem that i posted about - but it was only 'learning stuff' if you see what i mean, nothing hard).

I would recommend Java if your going to use the XMLSocket - its really easy to use and if you need a hand, just shout.

I have some data going inbetween Flash and my Java server.

Where i would say PHP is a lot easier is the parsing of the XML. I never parsed XML in PHP until the other month - and i did it first time and it was so nice and easy to use - with Java you've got loads of different parsers to chose from, loads of different API's that interface to those parsers, and i've yet to get the Java parsing the XML properly. But i only have a chance to work on my stuff about 7 hours a week.

Regards, snapple

smartie_on_computer
04-28-2006, 05:04 AM
ok im shouting :D
what i want really is to know how to have a variable send from flash to another computer into another flash file.
a bit like a two player game on differnt computers

i have got flash media server trial version

so thanks :)

snapple
04-28-2006, 07:35 AM
So whats the localConnection code you have so far? Because its what you should be using.

Regards, snapple

smartie_on_computer
04-28-2006, 08:49 PM
the same as i put at the top in the first post

snapple
04-28-2006, 10:50 PM
I never used the LocalConnection class before. But I found it very easy to use, in fact it worked first time:

in SWF 'a':


var localConnection:LocalConnection = new LocalConnection();
localConnection.send( "myConnection", "output", "This is a message from SWF a" );


in SWF 'b':


var localConnection:LocalConnection = new LocalConnection();
localConnection.connect( "myConnection" );
localConnection.output = function( str:String ):Void
{
// successfully prints the message sent from SWF 'a' into a TextField object.
_root.field.text = str;
}


That was all i needed. btw, i don't think you're using the allowDomain method correctly. The documentation appears to always have it as:


receiving_lc.allowDomain = function(sendingDomain)
{
return(sendingDomain=="www.domain.com" ||
sendingDomain=="store.domain.com");
}


It expects the return of a Boolean. The documentation states:


If the handler doesn't return true, the request from the sending object is ignored, and the method is not invoked.


This could be your problem.

Hope it is of some help.

Regards, snapple :]

smartie_on_computer
05-01-2006, 02:02 AM
still not working.
heres my swf files.
http://smartie.awardspace.com/one.swf
http://smartie.awardspace.com/two.swf

i'll post fla later, that almost has the same script that snapple gave :rolleyes:

P.S. if you want fla now, decompile them, i don't mind

snapple
05-01-2006, 08:00 AM
I'm affraid those 2 swfs mean nothing to me. I don't know what your trying to do or how your trying to do it. I am not going to decompile you SWF's because it is unreliable (no matter which decompiler you use), it also changes all variable names to there 'compilation equivalent" e.g. _12 or _7 - which again, are meaningless. Which would just lead to error and missunderstanding.

Regards, snapple

smartie_on_computer
05-01-2006, 09:30 AM
sorry
looks like i'm gona try to find another way with flash media server.

but you guys were really helpful :) ;) :p :D

snapple
05-01-2006, 09:52 AM
If your looking to update physical assets on the other SWF's stage - then Flash media Server would be the way to go (remember there is now an open-source versionn of this, red5), i would use global shared Objects, or maybe an XMLSocket class (seeing as your moving objects around and need to push data into Flash... no just transmit infomation).

XMLSocket would require some extra backend/serverside progrmaming.

Regards, snapple

smartie_on_computer
05-02-2006, 07:21 AM
anyone got some good tutorials on flash media server i could use, i found one one macromedia but that isn't really helpful

snapple
05-02-2006, 07:37 AM
A good book that includes a chapter on Flash Media Server is:

Flash MX 2004: For Rich Internet Applications, 'Replacing Web Pages with Applications', by Phillip Kerman. (Publish by New Riders).

It has a chapter: "Foundation Communication Server" and "Advanced Communication Server".

Regards, snapple

smartie_on_computer
05-02-2006, 07:42 AM
thanks

any more?

MidwestBoyInLA
05-03-2006, 09:51 PM
Hey Snapple,

With your latest chunk of code there, do you put the "swf a" code on a button?

I've got a .swf that's collecting various variables from user Input fields and selections, and I want to pass that into another .swf (not a child or _level of the original).

In that case, would the following code work, too:

on(Release){
var localConnection:LocalConnection = new LocalConnection();
localConnection.send( "myConnection", "output", variable1, variable2, variable3, variable4);
}

??

snapple
05-03-2006, 10:01 PM
No the code is not on a button - it just sits on the root.

I don't know if it would work when fired by an event... try it and see what happens. But what is important is that one swf is initialised before hte other. I think this would be your main restriction to creating the connection with an event handler.

I haven't read the documentation on this, i've never used the LocalConnection class before.

I'll be interested to here the results of your test.

Regards, snapple :]

MidwestBoyInLA
05-04-2006, 12:49 AM
Well, something didn't work... either as a button or just sitting on the root timeline. LOL I'm not sure where I went wrong... but given I'm not an actionscript guru like you guys... it's not surprising.

To show you what I'm working on... since Flash doesn't have an easy 'export as .jpg' function, I'm trying to load variables from one movie into another one that you can print direct (or use ALT-PrtScn to get a screenshot).

Take a look:
http://www.photobrad.com/hp/wizardcards/index.html

(click the "print" button to see the example of what I'm trying to do with this script)

With that code sitting on the root of the first movie, is it always broadcasting the variables? I'm assuming the receiving .swf doesn't 'initialize' until the popup window opens (and loads the .swf)... so hopefully that isn't an issue in this case.

smartie_on_computer
05-10-2006, 05:19 AM
ok, i can't seem to get the xml socket to work. i have m=been trying for a week now.(maube i have know idea how to use it lol :D).

i need to know how to use it, any tutorials?

snapple
05-10-2006, 07:48 AM
What langauge are you using to connect to it?

smartie_on_computer
05-11-2006, 09:31 AM
ok, i'vemanaged to get a simple thing ot work, just using actionscript. im not going to use thexml socketanymore, looks more simple straight out
the only tutorials i found were, this one on adobe and they are a little easy, not enough to expand on it, (do you get what i am saying?).

i need just a push in the right direction lol

Roman