Two Users One Flash/Communication between users

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
mark_bcn
Forum Newbie
Posts: 4
Joined: Mon Nov 01, 2010 11:28 am

Two Users One Flash/Communication between users

Post by mark_bcn »

Hello,

I just made a simple site where people can register/login and see the other users online.

Now I would like that they will be able to play a little flash game I made against each other online, but I've searched how to do so and can't find anything, not even an idea.

I have two options in my head but don't know if they are possible or not:

1- That both users interact with the same page where the embbed flash is. (don't know how to "send" the two users to the same php page tho)
2- Load the flash in two diferent pages (one per each player) and communicate between each other (maybe with sessions or smth dont know), refreshing the flash with what the opponent did.

I would appreciate so much any idea or suggestion!
Thanks!!!!

-Mark
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Two Users One Flash/Communication between users

Post by Jonah Bron »

They will be on the same page. You need to setup a database of "rooms", and store the ID of the room the user is in in a variable in Flash, and in a session. I haven't worked with Flash for a while, but I believe it has support for sockets, so use sockets to communicate with the server (google "flash sockets").
mark_bcn
Forum Newbie
Posts: 4
Joined: Mon Nov 01, 2010 11:28 am

Re: Two Users One Flash/Communication between users

Post by mark_bcn »

First of all, thanks a lot for answering man.

Now OT :P
Sorry but I don't understand exactly what you mean.
Do I have to create multiple "php's" called roomX.php with the flash embbeded so the users can go there and play? Will both see the same flash?

My idea was:
- one user challenges another one online (user2)
- then user2 receives an alert or something to Accept/Deny the challenge (altho I don't have any idea how two communicate between users)
- if so, "send" both users to a new page so they could play and destroy that page once the game ended

About flash communication don't worry I know how to it.

Thanks in advance.

ps: a bit OT here, if I have all this set in my computer as local, it is possible that another computer in the same LAN connects to the web?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Two Users One Flash/Communication between users

Post by Jonah Bron »

mark_bcn wrote:Do I have to create multiple "php's" called roomX.php with the flash embbeded so the users can go there and play? Will both see the same flash?
No, they all visit the same room.php page. But they don't all see what the other person is doing automatically. You have to do that.
mark_bcn wrote:- one user challenges another one online (user2)
- then user2 receives an alert or something to Accept/Deny the challenge (altho I don't have any idea how two communicate between users)
Create a database table of "challenges". When user1 challenges user2, it creates a new row in the table. User2's flash updates periodically, and sees that there is a new challenge with his name on it. If he denies, the row is marked for deletion. User1's flash updates, and see's that user2 denied. After he sees that, that row is deleted. If user2 accepts, then you move on from there.
mark_bcn wrote:if so, "send" both users to a new page so they could play and destroy that page once the game ended
They don't need to go to a new page. The flash should start the game when user2 accepts.
mark_bcn wrote:About flash communication don't worry I know how to it.
My money says if you knew, you wouldn't be here :wink: (no offense intended). What exactly do you know, or what have you done before?
mark_bcn wrote: if I have all this set in my computer as local, it is possible that another computer in the same LAN connects to the web?
Yes, you can access the localhost from another computer on the same network. Type http://[computer's local IP address here] into the other computer's browser.
mark_bcn
Forum Newbie
Posts: 4
Joined: Mon Nov 01, 2010 11:28 am

Re: Two Users One Flash/Communication between users

Post by mark_bcn »

Wow, thanks for that reply!

Really thanks.

Just one last question as that communication between flash and php is not working fine :P

In my flash i have one dynamic text and one button, i want to change the text when the user presses the button.

Code: Select all

// Red Button
redbt.addEventListener(MouseEvent.CLICK, redbtnDown);

function redbtnDown(event:MouseEvent):void {
	// Assign a variable name for our URLVariables object
	var redvariables:URLVariables = new URLVariables();
	// Build the varSend variable
	var redvarSend:URLRequest = new URLRequest("http://localhost/roomSolid.php");
	redvarSend.method = URLRequestMethod.POST;
	redvarSend.data = redvariables;
	// Build the varLoader variable
	var redvarLoader:URLLoader = new URLLoader;
	redvarLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
	redvarLoader.addEventListener(Event.COMPLETE, redcompleteHandler);
	
	redvariables.uname = "ha clicat";
	redvariables.sendRequest = "parse";	
	// Send the data to the php file
	redvarLoader.load(redvarSend);
	
	// When the data comes back from PHP we display it here		
	function redcompleteHandler(event:Event):void {
		var redphpVar1 = event.target.data.uname2;
		redname.text = redphpVar1;
	}	
	
}
And the php code...

Code: Select all

if ($_POST['sendRequest'] == "parse") {
	// Access the value of the dynamic text field variable sent from flash
	$uname2 = $_SESSION['playername'];
	echo $_POST['uname'];
	// Print var back to flash
	echo $uname2;
}
I can search for info if you dont want to answer.
Again, ty.
Last edited by Weirdan on Tue Nov 02, 2010 10:48 am, edited 1 time in total.
Reason: added syntax highlighting
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Two Users One Flash/Communication between users

Post by Jonah Bron »

Hm, I haven't worked with ActionScript in a while, and I don't know what the text box is called. You would probably get a better answer on a Flash forum.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Two Users One Flash/Communication between users

Post by josh »

You told us the expected result but not the actual result, we can't help you unless you clarify whats not working.
Post Reply