[virtualcommons-svn] SF.net SVN: virtualcommons:[429] mentalmodels/trunk/flex/src
Status: Beta
Brought to you by:
alllee
From: <kj...@us...> - 2010-01-15 19:13:15
|
Revision: 429 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=429&view=rev Author: kjonas Date: 2010-01-15 19:12:57 +0000 (Fri, 15 Jan 2010) Log Message: ----------- working on CommunicationC, Seema has an error to resolve with the server (messages sent to server, but not pushed to clients) DataModel.as made to store Singleton variables. Modified Paths: -------------- mentalmodels/trunk/flex/src/StartGame.mxml mentalmodels/trunk/flex/src/actionscript/Communication.as mentalmodels/trunk/flex/src/actionscript/PageDisplay.as mentalmodels/trunk/flex/src/actionscript/Student.as mentalmodels/trunk/flex/src/custom/CommunicationC.mxml mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml mentalmodels/trunk/flex/src/custom/InstructionPage.mxml mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml Added Paths: ----------- mentalmodels/trunk/flex/src/actionscript/DataModel.as Modified: mentalmodels/trunk/flex/src/StartGame.mxml =================================================================== --- mentalmodels/trunk/flex/src/StartGame.mxml 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/StartGame.mxml 2010-01-15 19:12:57 UTC (rev 429) @@ -137,9 +137,8 @@ // Server Response Events public function gameObjectResultHandler(event:ResultEvent):void { - if(event.result != null) + if(event.result as Game != null) { - var description:String = (event.result as Game).gameCode; btnStartGame.enabled = true; game = event.result as Game; @@ -197,10 +196,7 @@ { Alert.show((event.message.body as int).toString()); } - - - - + } ]]> Modified: mentalmodels/trunk/flex/src/actionscript/Communication.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/Communication.as 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/actionscript/Communication.as 2010-01-15 19:12:57 UTC (rev 429) @@ -6,7 +6,7 @@ { public var id:Number; public var message:String; - public var date:Date; + public var timestamp:Date; public var student:actionscript.Student; public var round:Round; } Added: mentalmodels/trunk/flex/src/actionscript/DataModel.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/DataModel.as (rev 0) +++ mentalmodels/trunk/flex/src/actionscript/DataModel.as 2010-01-15 19:12:57 UTC (rev 429) @@ -0,0 +1,34 @@ +package actionscript +{ + public class DataModel + { + private static const INSTANCE:DataModel = new DataModel(); + + public var studentObject:actionscript.Student = null; + public var gameObject:actionscript.Game = null; + + public function DataModel():void + { + if (INSTANCE != null) + { + //Flash forces constructors to be public + //An error is thrown to prevent any new instances from being created. + throw new Error("An instance of DataModel already exists."); + } + else + { + initialize(); + } + } + + private function initialize():void + { + trace("DataModel created"); + } + + public static function get instance():DataModel + { + return INSTANCE; + } + } +} \ No newline at end of file Modified: mentalmodels/trunk/flex/src/actionscript/PageDisplay.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/PageDisplay.as 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/actionscript/PageDisplay.as 2010-01-15 19:12:57 UTC (rev 429) @@ -23,6 +23,7 @@ public var msg:String = ""; public var gameObject:actionscript.Game = null; + public var studentObject:actionscript.Student = null; public var pages:ArrayCollection; public var minPagesRead:int; public var currentPageNumber:int; @@ -149,6 +150,16 @@ tempBox.addChild(ffq); } + else if(tempQuestion.type.toLowerCase() == "communication") + { + var coq:CommunicationC = new CommunicationC(); + coq.id = "q"+question; + + coq.initialize(); + coq.init(); + + tempBox.addChild(coq); + } // when all else fails, text question else { Modified: mentalmodels/trunk/flex/src/actionscript/Student.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/Student.as 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/actionscript/Student.as 2010-01-15 19:12:57 UTC (rev 429) @@ -8,7 +8,7 @@ public class Student { public var id:int; - public var group:int; + public var group:Group; public var studentNo:int; public var birthYear:int; public var major:String; @@ -17,6 +17,7 @@ public var gender:String; public var gameCode:String; public var game:Game; + public var money:Number; /** * input: @@ -30,7 +31,7 @@ * returns: * modified list of students */ - public static function assignGroups(students:ArrayCollection, maxGroupSize:int=5):ArrayCollection + /* public static function assignGroups(students:ArrayCollection, maxGroupSize:int=5):ArrayCollection { var groupSize:int = 0; var groupNum:int = 1; @@ -49,6 +50,6 @@ } return students; - } + } */ } } \ No newline at end of file Modified: mentalmodels/trunk/flex/src/custom/CommunicationC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/CommunicationC.mxml 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/custom/CommunicationC.mxml 2010-01-15 19:12:57 UTC (rev 429) @@ -3,6 +3,9 @@ <mx:Script> <![CDATA[ + import actionscript.DataModel; + import actionscript.DataModel; + import mx.controls.Alert; import mx.messaging.events.MessageEvent; import mx.rpc.events.FaultEvent; import actionscript.Communication; @@ -10,15 +13,24 @@ import mx.controls.Label; import mx.controls.Text; - public var student:Student = null; + public function init():void + { + Alert.show("commCons:"+(communicationConsumer == null) + +"\nstudent:"+(DataModel.instance.studentObject == null) + +"\ngroup:"+(DataModel.instance.studentObject==null || DataModel.instance.studentObject.group == null),"Null = true"); + + communicationConsumer.subtopic = DataModel.instance.studentObject.gameCode + "." + DataModel.instance.studentObject.group.id; + Alert.show(communicationConsumer.subtopic,"subtopic is"); + communicationConsumer.subscribe(); + } - public function faultHandler(event:FaultEvent):void + public function faultHandler(event:Object):void { // Silent Failure } public function messageHandler(event:MessageEvent):void { - if(event.message.body is actionscript.Communication) + if(event.message.body != null && event.message.body is actionscript.Communication) { commReceived(event.message.body as actionscript.Communication); } @@ -27,18 +39,19 @@ public function btnSend_click():void { var tempCommunication:actionscript.Communication = new actionscript.Communication(); - tempCommunication.date = new Date(); + tempCommunication.timestamp = new Date(); tempCommunication.message = txtMessage.text; - tempCommunication.student = this.student; + tempCommunication.student = DataModel.instance.studentObject; + tempCommunication.round = DataModel.instance.gameObject.currentRound; txtMessage.text = ""; - //<service>.<method>(tempCommunication); + communicationService.saveCommunication(tempCommunication); } public function btnSelfComm_click():void { var comm:actionscript.Communication = new actionscript.Communication(); comm.message = txtMessage.text; - comm.date = new Date(); + comm.timestamp = new Date(); comm.student = new actionscript.Student(); comm.student.id = 1; txtMessage.text = ""; @@ -61,7 +74,7 @@ private function commToText(comm:actionscript.Communication):Text { var newText:Text = new Text(); - newText.text = "["+comm.date.toLocaleTimeString()+"] "+comm.student.id+": "+comm.message; + newText.text = "["+comm.timestamp.toLocaleTimeString()+"] "+comm.student.id+": "+comm.message; return newText; } @@ -69,15 +82,16 @@ </mx:Script> <mx:RemoteObject id="communicationService" destination="communicationService" fault="faultHandler(event)"> - <mx:method name="sendCommunication" result="messageHandler(event)"/> + <mx:method name="saveCommunication" result="messageHandler(event)"/> </mx:RemoteObject> + <mx:Consumer id="communicationConsumer" destination="mme" fault="faultHandler(event)" message="messageHandler(event)"/> <mx:VBox id="vbxMessages" width="500" height="300" verticalScrollPolicy="on"/> <mx:HBox> - <mx:TextInput id="txtMessage" width="500"/> - <mx:Button id="btnSend" label="Send" click="btnSend_click()" visible="false"/> + <mx:TextInput id="txtMessage" width="400"/> + <mx:Button id="btnSend" label="Send" click="btnSend_click()" visible="true"/> <mx:Button id="btnSelfComm" label="SelfComm" click="btnSelfComm_click()" visible="false"/> </mx:HBox> Modified: mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2010-01-15 19:12:57 UTC (rev 429) @@ -144,19 +144,21 @@ // Responds to ArrayCollection by assuming it is of Student objects // This code assigns group and student numbers based on the object whose id // matches studentObject - if(event.message.body is actionscript.Block) + if(event.message.body is actionscript.Game) { - setBlock(event.message.body as actionscript.Block); - } - else if(event.message.body is actionscript.Game) - { gameObject = event.message.body as actionscript.Game; + DataModel.instance.gameObject = gameObject; setBlock(gameObject.currentBlock); if(instructions != null) { instructions.setGameObject(this.gameObject); } } + else if(event.message.body is actionscript.Block) + { + Alert.show("Server sent Block, not Game.",""); + setBlock(event.message.body as actionscript.Block); + } else if(event.message.body is ArrayCollection) { var students:ArrayCollection = new ArrayCollection(); @@ -170,10 +172,17 @@ { studentObject.group = actionscript.Student(students.getItemAt(i)).group; studentObject.studentNo = actionscript.Student(students.getItemAt(i)).studentNo; + + DataModel.instance.studentObject = studentObject; + + if(DataModel.instance.studentObject.group == null) + { + Alert.show("student group is null. Student ID is"+DataModel.instance.studentObject.id,"Error!"); + } } } } -// Alert.show("Current Student Information is: " + "\n"+studentObject.id +"\n"+studentObject.gameCode+"\n"+studentObject.studentNo); +// Alert.show("Current Student Information is: " + "\n"+SingletonStudent.instance.studentObject.id +"\n"+SingletonStudent.instance.studentObject.gameCode+"\n"+SingletonStudent.instance.studentObject.studentNo); } } @@ -285,7 +294,7 @@ studentResponse.response += ", "; studentResponse.response += (curr.getChildAt(j) as CategoricalQuestionC).comboSpecific.selectedItem as String; } - else if(curr.getChildAt(j) is DayByDayDecisionsQuestionC) + else if(curr.getChildAt(j) is DayByDayDecisionsQuestionC || curr.getChildAt(j) is CommunicationC) { //SKIP IT studentResponse.question = null; @@ -460,7 +469,7 @@ { consumer.subtopic = studentObject.gameCode; consumer.subscribe(); - //Alert.show("GameCode is '" + studentObject.gameCode + "'"); +// Alert.show("GameCode is '" + studentObject.gameCode + "'"); //Alert.show("subscribed to destination: " + consumer.destination); } } Modified: mentalmodels/trunk/flex/src/custom/InstructionPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2010-01-15 19:12:57 UTC (rev 429) @@ -16,6 +16,7 @@ import mx.collections.ArrayCollection; [Bindable] public var gameObject:actionscript.Game = null; + public var studentObject:actionscript.Student = null; //[Bindable] public var moduleNumber:int = 1; //[Bindable] public var module:Module; [Bindable] public var blockNumber:int = 0; Modified: mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml 2010-01-14 06:30:33 UTC (rev 428) +++ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml 2010-01-15 19:12:57 UTC (rev 429) @@ -100,6 +100,7 @@ public function clicked(event:MouseEvent):void { + //event.currentTarget. try { deciding = 0; @@ -136,6 +137,7 @@ dayByDayContent.validateNow(); dayByDayContent.verticalScrollPosition = dayByDayContent.maxVerticalScrollPosition; + } public function save():ArrayCollection This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |