||unity-dev|| Holiday help!

Discussion list for Unity developers. unity-dev at moock.org
Wed Dec 27 10:23:53 CST 2006


in the line:
e.getRoomID().setAttributeOnServer("selectedButton", this, true)

first, the attribute 'value' has to be a string. so i'm guessing you 
want something like this:

setAttributeOnServer("selectedButton", "button3", true)

second, e.getRoomID() only gives you the string ID of the room. 
setAttributeOnServer() is a method of URoom, not String. if you are 
using the basic structure of uSimpleChat, then you can get a reference 
to the room via ChatRoomView's instance property 'room'. as in:

room.setAttributeOnServer("selectedButton", "button3", true)

if not, you have to use RoomManager.getRoom(). you can obtain a 
reference to RoomManager using UClient.getRoomManager(). for example, 
within your UClient subclass, you would do this:

getRoomManager().getRoom(yourRoomID).setAttributeOnServer("selectedButton", 
"button3", true)

colin




Discussion list for Unity developers. wrote:
> Thank you to everyone for your help...
> 
> I am getting closer. Here is my latest code. Seems I can't get the  
> room attribute to trigger an event. Any ideas?
> 
>    ///////////////////////////////////////////////////////////////////// 
> /////////////////////
> 
>    		
> 		// First, create an array of labels for the buttons
> 		var labels_ar:Array = ["Option 1","Option 2","Option 3","Option 4"];
> 
>    		// Second, build 4 buttons and position them
> 		public function addButtons(labels:Array, container:MovieClip,  
> startX:Number, startY:Number):Void
> 		{
> 			var button_offset:Number = 30;
> 			var button_depth:Number = 10;
> 			var i:Number = 0;
> 			for (i = 0; i<labels.length;i++)
> 			{
> 				var current_button:MovieClip = container.createClassObject 
> (mx.controls.Button, "option" + i, button_depth,{label:labels[i]});
> 				current_button.move(startX,startY+(button_offset*(i+1)));
> 				current_button.setSize(200, 20);
> 				current_button.addEventListener("click", clickHandler);
> 				button_depth++;
> 			}
> 		}
> 
> 		// Third, listen for button clicks and when a button is clicked do  
> the following:
> 		//     1) Trace out which button was clicked
> 		//     2) Set the room attribute "selectedButton" equal to the  
> value of the button clicked
> 		//     3) Highlight the selected button component
> 		public function clickHandler(e:Object):Void
> 		{
> 		  	trace(this + " was just pressed.");
> 			e.getRoomID().setAttributeOnServer("selectedButton", this,  
> true) // I can't figure out how to get the right room name
> 			changeColor(this);
> 			//setClientAttribute("whichButton", this, null, true, false, false);
> 		}
> 		
> 		// Fourth, when the room attribute is changed (selectedButton  
> changes) do something...
> 		public function onUpdateRoomAttribute (e:URoomEvent):Void
> 		{
> 			trace("=============== selectedButton changed ===============");
> 		}
> 	
> 	  	// Change the color of the all of the buttons to "false", and set  
> the selectedButton color to "emphasized"
> 		public function changeColor(buttonToColor):Void
> 		{
> 			trace("changeColor(" + buttonToColor + ") was called.");
> 			_level0.option0.setStyle("emphasized", false);
> 			_level0.option1.setStyle("emphasized", false);
> 			_level0.option2.setStyle("emphasized", false);
> 			_level0.option3.setStyle("emphasized", false);
> 			
> 			buttonToColor.setStyle("emphasized", true);
> 		}
> 
>    ///////////////////////////////////////////////////////////////////// 
> /////////////////////
> 
> 
> 
> Thanks!!! really appreciate it!
> 
> Ryan
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> On Dec 21, 2006, at 12:02 AM, Discussion list for Unity developers.  
> wrote:
> 
>> hi ryan,
>> as jose already suggested, you should implement the four
>> "button-selected" states using a room attribute. assuming you already
>> have a chat room functional, and you have an object registered for
>> events from that room, you can call URoom.setAttributeOnServer() to  
>> set
>> your attribute, and then implement  
>> URoomListener.onUpdateRoomAttribute()
>> in your event-handling class to respond to changes in the attribute.
>>
>> your attribute-setting code might look like this:
>> yourRoom.setAttributeOnServer("selectedButton", "3", true)
>>
>> and your event-handling code might look like this:
>> public function onUpdateRoomAttribute (e:URoomEvent):Void {
>>    if (e.getChangedAttr().attrVal == "1") {
>>      // Display button-one-selected state
>>    }
>>    // ...etc
>> }
>>
>> here's more info from the docs:
>>
>> =====
>> setAttributeOnServer
>>
>> public function setAttributeOnServer(attrName:String,  
>> attrValue:String,
>> isShared:Boolean, isPersistent:Boolean, appendVal:Boolean):Void
>>
>> Asks Unity to set an attribute for this room. An attribute is simply a
>> named piece of information stored by the room on the server, much  
>> like a
>> variable, with the added benefit that it can be automatically shared
>> with all clients in the room. Room attributes are intended to store
>> information about the room's environment, such as the highscore in a
>> game room or perhaps the position of the furniture in a virtual house.
>>
>> If setAttributeOnServer() is called with isShared set to true, then  
>> the
>> attribute value is automatically propagated to all clients in the room
>> on which the attribute is set. Clients can respond to the changing  
>> of a
>> shared room attribute value via the
>> URoomListener.onUpdateRoomAttribute() event. Clients can only set
>> attributes on rooms they are in.
>> ======
>>
>> colin
>>
>>
>> Discussion list for Unity developers. wrote:
>>> Hello,
>>>
>>> I am trying to incorporate Unity into my web app for work. We are a
>>> non-profit lab and our group is just myself and one other semi-
>>> developer. Can someone please help me?
>>>
>>> Here is the scenario: Each person logged in has a view of a screen
>>> with 4 buttons on it. When one user selects a button, it becomes
>>> selected on everyone else's screen. If another user changes the
>>> selection, everyone's is changed. I was thinking of using a "room
>>> variable" to do this. But between the listeners and the local
>>> variables, I am lost.
>>>
>>> Here is my code... I need to hook up something like the chat window
>>> listener so that when I select a button, it sets a room variable
>>> called "whichButtonIsSelected" and some way of having everyone else's
>>> screen constantly check to see the state of that variable.
>>>
>>> Is this the right way to do it? I am stuck... and the documentation
>>> and examples works fine for chat, but not for much more.
>>>
>>> Thank you so much for your help,
>>>
>>> Ryan
>>> Cambridge, MA
>>>
>>>
>>> import mx.skins.RectBorder;
>>> import mx.core.ext.UIObjectExtensions;
>>>
>>>
>>>
>>> // Listen for send Button clicks.
>>> send.clickHandler = function (e:Object):Void {
>>>    sc.sendMessage();
>>> }
>>>
>>>
>>> // ////////////////////////////////////////////////////////////////// 
>>> //
>>>
>>> // Listen for 4 Button clicks.
>>> option0.clickHandler = function (e:Object):Void {
>>>    sc.setCurrentButton(this);
>>> }
>>> option1.clickHandler = function (e:Object):Void {
>>>    sc.setCurrentButton(this);
>>> }
>>> option2.clickHandler = function (e:Object):Void {
>>>    sc.setCurrentButton(this);
>>> }
>>> option3.clickHandler = function (e:Object):Void {
>>>    sc.setCurrentButton(this);
>>> }
>>>
>>> // ////////////////////////////////////////////////////////////////// 
>>> //
>>>
>>>
>>>
>>> // Listen for enter key presses in outgoing.
>>> var outgoingEnterHandler:Object = new Object();
>>> outgoingEnterHandler.enter = function (e:Object):Void {
>>>    sc.sendMessage();
>>> };
>>> outgoing.addEventListener("enter", outgoingEnterHandler);
>>>
>>> // Listen for setName Button clicks.
>>> setName.clickHandler = function (e:Object):Void {
>>>    sc.setName();
>>> }
>>>
>>> // Listen for enter key presses in nameInput.
>>> var nameInputEnterHandler:Object = new Object();
>>> nameInputEnterHandler.enter = function (e:Object):Void {
>>>    sc.setName();
>>> };
>>> nameInput.addEventListener("enter", nameInputEnterHandler);
>>>
>>>
>>> //var currentButton:String = "option0";
>>> //option0.setStyle("themeColor", "haloOrange");
>>> //option0.setStyle("emphasized", "true");
>>> //trace("Current selection is on " + currentButton);
>>>
>>>
>>>
>>> --
>>> you're a unity-dev subscriber. to unsubscribe, visit www.moock.org/ 
>>> mailman/listinfo/unity-dev/
>>>
>>> superb hosting for this list and moock.org is generously provided  
>>> by Rackspace. See: http://www.rackspace.com/?supbid=moock
>> --
>> you're a unity-dev subscriber. to unsubscribe, visit www.moock.org/ 
>> mailman/listinfo/unity-dev/
>>
>> superb hosting for this list and moock.org is generously provided  
>> by Rackspace. See: http://www.rackspace.com/?supbid=moock
> 
> 
> 
> 
> 
> THE INFORMATION TRANSMITTED IN THIS ELECTRONIC COMMUNICATION IS INTENDED ONLY FOR THE PERSON OR ENTITY TO WHOM IT IS ADDRESSED AND MAY CONTAIN CONFIDENTIAL AND/OR PRIVILEGED MATERIAL.  ANY REVIEW, RETRANSMISSION, DISSEMINATION OR OTHER USE OF OR TAKING OF ANY ACTION IN RELIANCE UPON, THIS INFORMATION BY PERSONS OR ENTITIES OTHER THAN THE INTENDED RECIPIENT IS PROHIBITED.  IF YOU RECEIVED THIS INFORMATION IN ERROR, PLEASE CONTACT THE SENDER AND THE PRIVACY OFFICER, AND PROPERLY DISPOSE OF THIS INFORMATION.
> 
> 
> --
> you're a unity-dev subscriber. to unsubscribe, visit www.moock.org/mailman/listinfo/unity-dev/
> 
> superb hosting for this list and moock.org is generously provided by Rackspace. See: http://www.rackspace.com/?supbid=moock


More information about the unity-dev mailing list