Thread: [virtualcommons-svn] SF.net SVN: virtualcommons:[413] mentalmodels/trunk/flex/src (Page 3)
Status: Beta
Brought to you by:
alllee
From: <kj...@us...> - 2009-12-10 21:56:24
|
Revision: 413 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=413&view=rev Author: kjonas Date: 2009-12-10 21:56:15 +0000 (Thu, 10 Dec 2009) Log Message: ----------- added comments to custom/FisheryExperimentCore.mxml and FisheryExperimentShell.mxml Modified Paths: -------------- mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml Modified: mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml =================================================================== --- mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml 2009-12-08 20:47:25 UTC (rev 412) +++ mentalmodels/trunk/flex/src/FisheryExperimentShell.mxml 2009-12-10 21:56:15 UTC (rev 413) @@ -9,6 +9,8 @@ [Bindable] public var progressBarWidth:Number = 600; private var repetitions:int = 100; + // This timer ticks every 100 milliseconds + // repetitions need to be seconds * 10 public function setProgressBarTime(hours:int,minutes:int,seconds:int):void { repetitions = seconds * 10; @@ -23,18 +25,16 @@ } public function timerTick(event:TimerEvent):void { - tick(progressTimer.currentCount/progressTimer.repeatCount); + // set to current/total % of the full progressbar's width + progressBarBlock.width = progressBarWidth*(progressTimer.currentCount/progressTimer.repeatCount); } - private function tick(percentBlock:Number):void - { - progressBarBlock.width = progressBarWidth*percentBlock; - } ]]></mx:Script> <mx:HBox id="shell" horizontalGap="30" y="{(height - shell.height)/2}" x="{(width - shell.width)/2}"> + <!-- information windows --> <mx:VBox id="vbxInfo"> <mx:TitleWindow id="InformationWindowA" width="400" height="220" title="Information Window A" clipContent="true" horizontalScrollPolicy="on" verticalScrollPolicy="on"> @@ -54,6 +54,7 @@ <mx:Button id="btnResetPopups" label="Reset Popups" click="{closedFunction(1);closedFunction(2)}"/> </mx:VBox> + <!-- END information windows --> <mx:VBox id="vbxContent" horizontalAlign="center" verticalAlign="middle"> <mx:VBox id="progressBars" x="0" y="0" verticalGap="0"> @@ -84,15 +85,20 @@ import mx.managers.PopUpManager; import mx.messaging.events.MessageFaultEvent; + // These are the actual windows that pop up and can be moved around public var popupA:InformationWindowPopup = null; public var popupB:InformationWindowPopup = null; + // Lists that contain the data that goes into information windows public var allInfoWindowsA:ArrayCollection = null; public var allInfoWindowsB:ArrayCollection = null; public var allInfoWindowsDescriptions:ArrayCollection = null; + + // used to update things like daybydaydecisions within information windows public var updateObjectA:InformationWindowCreator = null; public var updateObjectB:InformationWindowCreator = null; + // list of the windows available for this block public var currInfoWindowsA:ArrayCollection = null; public var currInfoWindowsB:ArrayCollection = null; public var currInfoWindowsDescriptions:ArrayCollection = null; @@ -109,8 +115,18 @@ var str:String = msg.body as String; Alert.show("String came from server: " + str); } + public function init():void { + initWindows(); + } + + // Since the FisheryExperimentShell file is largely concerned with + // information windows, this function creates lists of all possible windows + // A and B copies must be generated, as Flex will not allow us to display the + // same component in two different locations + public function initWindows():void + { // temporarily store all 3 objects returned... allInfoWindowsA = makeWindows(); allInfoWindowsB = makeWindows(); @@ -127,36 +143,36 @@ // Display only the default windows. selectCurrentWindows( new ArrayCollection() ); - } + // pops up window 1 or 2 (A or B) + // This function takes all the data from an information window and puts it into + // a larger popup that can be dragged around the screen. public function popupInformationWindow(window:int):void { var temp:DisplayObject = null; + // first, create the popup (object. this does not make it visible) var popupNew:InformationWindowPopup = PopUpManager.createPopUp(this, InformationWindowPopup, false) as InformationWindowPopup; popupNew.closedFunction = closedFunction; popupNew.window = window; var old:TitleWindow = null; - if(window == 1) - { - old = InformationWindowA; - popupA = popupNew; - btnPickerA.enabled = cbxPickerA.enabled = false; - } - else if(window == 2) - { - old = InformationWindowB; - popupB = popupNew; - btnPickerB.enabled = cbxPickerB.enabled = false; - } - else - { + // set up some variables + if(window == 1){ + old = InformationWindowA; // data source + popupA = popupNew; // data destination + btnPickerA.enabled = cbxPickerA.enabled = false; // only one "A" popup at a time + }else if(window == 2){ + old = InformationWindowB; // data source + popupB = popupNew; // data destination + btnPickerB.enabled = cbxPickerB.enabled = false; // only one "B" popup at a time + }else{ return; } + // transfer all data, scale to full size while(old != null && old.numChildren > 0) { temp = old.removeChildAt(0); @@ -165,14 +181,17 @@ popupNew.addChild(temp); } + // show the popup itself PopUpManager.centerPopUp(popupNew); } + // Closing all popups public function closedFunction(window:int):void { var temp:DisplayObject = null; if(popupA != null && window == 1) { + // transfer all data, scale to 75% while(popupA.numChildren > 0) { temp = popupA.removeChildAt(0); @@ -180,12 +199,14 @@ temp.scaleY = 0.75; InformationWindowA.addChild(temp); } + // destroy the popup PopUpManager.removePopUp(popupA); popupA = null; } if(popupB != null && window == 2) { + // transfer all data, scale to 75% while(popupB.numChildren > 0) { temp = popupB.removeChildAt(0) @@ -193,14 +214,18 @@ temp.scaleY = 0.75; InformationWindowB.addChild(temp); } + // destroy the popup PopUpManager.removePopUp(popupB); popupB = null; } + // allow "A" and "B" to be popped up again btnPickerA.enabled = btnPickerB.enabled = true; cbxPickerA.enabled = cbxPickerB.enabled = true; } + // generates and returns a list of all possible information windows + // and saves their descriptions to a single arraycollection public function makeWindows():ArrayCollection { var windowData:ArrayCollection = InformationWindowCreator.makeWindows(); @@ -209,19 +234,26 @@ return windowData; } + // only enable the user to see the windows associated with the current block public function selectCurrentWindows(selectedWindows:ArrayCollection):void { + // these windows are mandatory: 0,2,3 var mustHaveWindows:ArrayCollection = new ArrayCollection([0,2,3]); + // close all popups. closedFunction(1); closedFunction(2); + // drop data from previous executions currInfoWindowsA = new ArrayCollection(); currInfoWindowsB = new ArrayCollection(); currInfoWindowsDescriptions = new ArrayCollection(); + // sort through all possible windows for(var i:int = 0; i < allInfoWindowsA.length; i++) { + // if any window is in the list for the block, or mandatory + // then add it to the lists of current windows if(selectedWindows.contains(i) || mustHaveWindows.contains(i)) { currInfoWindowsA.addItem(allInfoWindowsA.getItemAt(i)); @@ -229,20 +261,25 @@ currInfoWindowsDescriptions.addItem(allInfoWindowsDescriptions.getItemAt(i)); } } - cbxPickerA.dataProvider = currInfoWindowsDescriptions; cbxPickerB.dataProvider = currInfoWindowsDescriptions; + // refresh the information windows on the sides cbxChanged(); } + // refreshes which information window is shown (ex: user switches selection, or new block) public function cbxChanged():void { var temp:DisplayObject = null; + + // if a valid selection is made if(cbxPickerA.selectedIndex >= 0 && cbxPickerA.selectedIndex <= currInfoWindowsA.length && cbxPickerA.enabled) { + // discard old data InformationWindowA.removeAllChildren(); + // transfer all data, scale to 75% var windowA:ArrayCollection = currInfoWindowsA.getItemAt(cbxPickerA.selectedIndex) as ArrayCollection; for(var i:int = 0; i < windowA.length; i++) { @@ -253,10 +290,13 @@ } } + // if a valid selection is made if(cbxPickerB.selectedIndex >= 0 && cbxPickerB.selectedIndex <= currInfoWindowsB.length && cbxPickerB.enabled) { + // discard old data InformationWindowB.removeAllChildren(); + // transfer all data, scale to 75% var windowB:ArrayCollection = currInfoWindowsB.getItemAt(cbxPickerB.selectedIndex) as ArrayCollection; for(var j:int = 0; j < windowB.length; j++) { @@ -268,16 +308,20 @@ } } + // new block is received public function loadBlock(block:Block):void { if(block != null) { + // store the new block currentBlock = block; + var tempArray:ArrayCollection = new ArrayCollection(); - var i:int = 0; var temp:Object = null; + // search the block's information windows for all valid "BlockInformationWindow" objects + // add the valid ones to the list of desired windows and update the display var str:String = currentBlock.informationWindows.length + " of them.\n"; for(i = 0; i < currentBlock.informationWindows.length; i++) { Modified: mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2009-12-08 20:47:25 UTC (rev 412) +++ mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2009-12-10 21:56:15 UTC (rev 413) @@ -5,6 +5,8 @@ width="720" height="490"> <mx:states> + <!-- This state has nothing but the sociodemographic information + It is used to get the game ID to connect to the server --> <mx:State name="socioDemographic"> <mx:AddChild relativeTo="{content}"> <comp:SocioDemographicPage id="socioDemographic" @@ -14,6 +16,7 @@ <mx:SetStyle target="{content}" name="horizontalCenter" value="0"/> </mx:State> + <!-- This is a temporary state that jumpstarts the "instructions" state for the first time --> <mx:State name="instructionsLoad"> <mx:AddChild relativeTo="{content}"> <comp:InstructionPage id="instructions" initialize="gotoInstructions()" x="0" y="0" @@ -21,25 +24,28 @@ </mx:AddChild> </mx:State> + <!-- This state displays Blocks received from the server using InstructionPage --> <mx:State name="instructions" enterState="instructions.init(currentBlock)"> <mx:RemoveChild target="{instructions}"/> <mx:AddChild relativeTo="{content}" target="{instructions}"/> <mx:SetProperty target="{instructions}" name="visible" value="true"/> </mx:State> + <!-- This state is used between Blocks (ex: a student finishes a block early) --> <mx:State name="wait"> <mx:AddChild relativeTo="{content}"> <mx:Label id="lblWaiting" text="Waiting for next Block from server..." fontSize="16"/> </mx:AddChild> </mx:State> + <!-- This state should only show up when the game is completely finished --> <mx:State name="none"> - <!--<mx:RemoveChild target="{instructions}"/>--> <mx:AddChild relativeTo="{expiredContent}" target="{instructions}"/> <mx:SetProperty target="{instructions}" name="visible" value="false"/> <mx:AddChild relativeTo="{content}"> <mx:Label id="end" text="Thank you for playing!" fontSize="30"/> </mx:AddChild> + <!-- disable navigation buttons --> <mx:SetProperty target="{btnAccept}" name="enabled" value="false"/> <mx:SetProperty target="{btnReset}" name="enabled" value="false"/> <mx:SetProperty target="{btnBack}" name="enabled" value="false"/> @@ -47,9 +53,12 @@ </mx:State> </mx:states> + <!-- Content - SocioDemographicPage or InstructionPage or "THE END" (visible to user) + ExpiredContent - holds sociodemographic and instructionpage so they aren't destroyed (invisible to user) --> <mx:Canvas id="content" x="0" y="0" width="720" height="460"/> <mx:Canvas id="expiredContent" x="-1" y="-1" width="1" height="1" visible="false"/> + <!-- Navigation Buttons --> <mx:HBox id="buttonBar" left="{(width-buttonBar.width)/2}" bottom="0" horizontalGap="100"> <mx:Button id="btnBack" label="« Back" click="back()" enabled="false"/> <mx:Button id="btnAccept" label="Accept" click="accept()" /> @@ -57,7 +66,7 @@ <mx:Button id="btnForward" label="Forward »" click="forward()" enabled="false"/> </mx:HBox> - + <!-- services that control the connection to the server --> <mx:RemoteObject id="studentService" destination="studentService" fault="faultHandler(event)"> <mx:method name="createStudent" result="studentResultHandler(event)"/> </mx:RemoteObject> @@ -68,7 +77,8 @@ <mx:method name="getAllLocations" result="locationResultHandler(event)"/> </mx:RemoteObject> - + <!-- Using Consumer instead of service so that the server can control + when responses are sent to multiple clients, (ex: end of block) --> <mx:Consumer id="consumer" destination="mme" message="messageHandler(event)" fault="faultMsgHandler(event)" channelSet="{cs}" /> <mx:ChannelSet id="cs"> @@ -106,22 +116,21 @@ // Important Variables // public var gameObject:actionscript.Game = null; -// public var currentModule:Module = null; -// public var currentModuleNumber:int = 0; public var currentBlock:Block = null; public var currentBlockNumber:int = 0; [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); + public var instructionsLoaded:Boolean = false; + [Bindable] public var studentObject:actionscript.Student; + [Bindable] public var roundObject:actionscript.Round; + // should be set when created by the FisheryExperimentShell (aka "shell") public var shell:FisheryExperimentShell = null; + // information window objects given by the shell public var updateObjectA:InformationWindowCreator = null; public var updateObjectB:InformationWindowCreator = null; - public var instructionsLoaded:Boolean = false; - [Bindable] public var studentObject:actionscript.Student; - [Bindable] public var roundObject:actionscript.Round; - public function faultMsgHandler(msgevent:MessageFaultEvent):void { Alert.show("Error in getting message: " + msgevent.faultString); @@ -131,6 +140,10 @@ { var msg:IMessage; + // Responds to receiving a Block or Game by initializing the new block included + // 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) { setBlock(event.message.body as actionscript.Block); @@ -163,32 +176,36 @@ // Alert.show("Current Student Information is: " + "\n"+studentObject.id +"\n"+studentObject.gameCode+"\n"+studentObject.studentNo); } } - private function blockResultHandler(event:ResultEvent):void - { - setBlock(event.result as actionscript.Block); - } + + // new block received private function setBlock(block:Block):void { -// Alert.show(currentState); + // if the game is over, pop up an error message if(currentState == "none") { Alert.show("Block received in End of Game state.","Unexpected Block"); } + // if we're waiting for a block, call the function to load the new block else if(currentState == "wait") { loadNextBlock(block); } + // if we're not finished with the last block, force it to complete, then load the new block else if(currentState == "instructions") { -// Alert.show("FORCING"); accept(true); loadNextBlock(block); } + // if we're not ready for any blocks, show an error + // This will cause a crash for this client + // but this should never happen else if(currentState == "socioDemographic") { currentState = "none"; Alert.show("Block received in Socio Demographic state.","Unexpected Block"); } + // If somehow receiving a second block before loading the first is finished + // avoid conflicts and corrupt data by crashing else if(currentState == "instructionsLoad") { currentState = "none"; @@ -200,24 +217,34 @@ { var newLoc:Location = new Location(); //newLoc.maxCapacity = maxCapacity; - newLoc.growthRate = growth; //newLoc.initialPopulation = maxCapacity / 2.0; + newLoc.growthRate = growth; return newLoc; } - public function init():void { - + // asks server to get the list of all locations getLocations(); } + // asks server to get the list of all locations + private function getLocations():void + { + locationService.getAllLocations(); + } + + // this method executed when the instructionsLoad private function gotoInstructions():void { + // enable navigation btnForward.enabled = btnBack.enabled = btnReset.enabled = true; + instructionsLoaded = true; currentState = "instructions"; } + + // sends answers to questions to the server private function sendBlockQuestions():void { if(currentBlock == null) return; @@ -226,10 +253,12 @@ var studentResponse:StudentResponse; var pages:ArrayCollection = instructions.pageDisplay.pages; + // for each page... for(var i:int=0; i<pages.length; i++) { var curr:VBox = pages.getItemAt(i) as VBox + // for each question... for(var j:int=0; j<curr.numChildren; j++) { studentResponse = new StudentResponse(); @@ -238,6 +267,7 @@ var row:int, col:int; + // try to get a student response and send it if(curr.getChildAt(j) is TextQuestionC) { studentResponse.question = (curr.getChildAt(j) as TextQuestionC).question; @@ -308,7 +338,6 @@ } else if(curr.getChildAt(j) is StrategyDesignQuestionC) { -// Alert.show("Strategy Saving"); studentResponse.response = null; studentResponse.question = null; @@ -326,6 +355,7 @@ answeringService.saveStrategy(tempDBObjects); } + // if there was a question found, add it to the list to submit if(studentResponse.question != null) { responseList.addItem(studentResponse); @@ -333,14 +363,11 @@ } } + // submit the list of answers answeringService.saveQuestion(responseList); } - private function getLocations():void - { - locationService.getAllLocations(); - } - + // save the last instances of each key component to the shell for use in information windows private function saveDataToShell():void { if(instructions.savedDayByDayDecisions != null) @@ -362,6 +389,7 @@ } } + // When a new block is received, this method is executed private function loadNextBlock(nextBlock:Block):void { // save questions from previous Block @@ -372,7 +400,7 @@ saveDataToShell(); } - // update with new block + // update reference to recently received block currentBlock = nextBlock; if(currentBlock == null @@ -384,6 +412,8 @@ return; } + // If this is the first block, make sure instructions have been loaded first + // (instructionsLoad state will proceed to instructions afterward) if(!instructionsLoaded) { currentState = "instructionsLoad"; @@ -393,46 +423,18 @@ gotoInstructions(); } + // tell shell that a new block has arrived shell.loadBlock(currentBlock); - // start timer to alert students to hurry + // start timer shell.setProgressBarTime(0,0,currentBlock.duration); shell.progressBarInit(); } -// private function moduleResultHandler(event:ResultEvent):void -// { -// currentModule = (event.result as actionscript.Module); -// -// if(currentModule == null) -// { -// currentState = "none"; -// } -// else if(currentModule.blocks == null || currentModule.blocks.length < 1 || -// (currentModule.blocks.getItemAt(0) as Block) == null || -// (currentModule.blocks.getItemAt(0) as Block).questionGroups == null || -// (currentModule.blocks.getItemAt(0) as Block).questionGroups.length < 1) -// { -// currentState = "none"; -// } -// else if(!instructionsLoaded) -// { -// currentState = "instructionsLoad"; -// } -// else -// { -// gotoInstructions(); -// } -// } - public function getLocation():void - { - - } private function locationResultHandler(event:ResultEvent):void { if(event.result is ArrayCollection) { -// Alert.show(""+(event.result as ArrayCollection).length,"locations received"); locations = event.result as ArrayCollection; if(instructions != null) { @@ -442,16 +444,17 @@ } private function strategyResultHandler(event:ResultEvent):void { - Alert.show("Strategy Saved"); + //Alert.show("Strategy Saved"); } + // complete student object received from server private function studentResultHandler(event:ResultEvent):void { studentObject = event.result as actionscript.Student; if(studentObject == null) { - Alert.show("event.result is null"); + Alert.show("event.result is null in studentResultHandler()"); } else { @@ -466,44 +469,37 @@ Alert.show("Fault:\n"+event.fault.message + "\n" + event.fault.getStackTrace()); } + // navigation public function back():Boolean { - if(content.numChildren == 0) - { return false; } + if(content.numChildren == 0) return false; var obj:DisplayObject = content.getChildAt(0); - if(obj is InstructionPage) - { - try - { + if(obj is InstructionPage){ + try{ return (InstructionPage)(obj).back(); - } - catch(err:Error){} + }catch(err:Error){} } return false; } public function forward():Boolean { - if(content.numChildren == 0) - { return false; } + if(content.numChildren == 0) return false; var obj:DisplayObject = content.getChildAt(0); - if(obj is InstructionPage) - { - try - { + if(obj is InstructionPage){ + try{ return (InstructionPage)(obj).forward(); - } - catch(err:Error){} + }catch(err:Error){} } return false; } + // user says they are done with the block/sociodem public function accept(force:Boolean=false):Boolean { - if(content.numChildren == 0) - { return false; } + if(content.numChildren == 0) return false; var obj:DisplayObject = content.getChildAt(0); var returnValue:Boolean = false; @@ -515,6 +511,7 @@ obj.visible = false; expiredContent.addChild(obj); + // feed the info for a student into an object and send to server var newStudent:actionscript.Student = new actionscript.Student(); newStudent.birthYear = (int)((obj as SocioDemographicPage).getYear()); newStudent.gender = (obj as SocioDemographicPage).getGender(); @@ -524,10 +521,10 @@ studentService.createStudent(newStudent); + // move from sociodemographic state to waiting for next block currentState = "wait"; btnBack.enabled = btnForward.enabled = btnReset.enabled = true; - //getNextBlock(); returnValue = true; } } @@ -541,9 +538,7 @@ obj.visible = false; expiredContent.addChild(obj); currentState = "wait"; - //consumer.subscribe(); - //getNextBlock(); returnValue = true; } } @@ -553,11 +548,13 @@ } } + // enable navigation if the current state is instructions btnBack.enabled = btnForward.enabled = btnReset.enabled = (currentState == "instructions"); return returnValue; } + // try to reset questions on any instruction pages public function reset():void { if(content.getChildAt(0) is InstructionPage) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kj...@us...> - 2009-12-13 20:46:39
|
Revision: 414 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=414&view=rev Author: kjonas Date: 2009-12-13 20:46:31 +0000 (Sun, 13 Dec 2009) Log Message: ----------- added comments to actionscript/PageDisplay.as, custom/InstructionPage.mxml, and custom/SocioDemographicPage.mxml Modified Paths: -------------- mentalmodels/trunk/flex/src/actionscript/PageDisplay.as mentalmodels/trunk/flex/src/custom/InstructionPage.mxml mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml Modified: mentalmodels/trunk/flex/src/actionscript/PageDisplay.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/PageDisplay.as 2009-12-10 21:56:15 UTC (rev 413) +++ mentalmodels/trunk/flex/src/actionscript/PageDisplay.as 2009-12-13 20:46:31 UTC (rev 414) @@ -39,6 +39,9 @@ return newLoc; } + // requires a block, and a list of locations. + // the "minimumPagesRead" variable will not let the student finish the block until that + // many pages have been viewed. public function PageDisplay(newBlock:Block, minimumPagesRead:int, locations:ArrayCollection) { currBlock = newBlock; @@ -47,9 +50,11 @@ highestPageReached = currentPageNumber; this.locations = locations; + // generates the objects that will be displayed on each "page" in the block loadPages(); } + // generates the objects that will be displayed on each "page" in the block public function loadPages():void { pages = new ArrayCollection(); @@ -65,6 +70,7 @@ return; } + // for each "questionGroup" in the block, make a "page" for(var group:int=0; group<currBlock.questionGroups.length; group++) { var questionGroup:QuestionGroup = QuestionGroup(currBlock.questionGroups.getItemAt(group)); @@ -73,16 +79,11 @@ if(questionGroup.questions != null && questionGroup.questions.length != 0) { + // for each question, try to make a component appear on screen for(var question:int=0; question<questionGroup.questions.length; question++) { var tempQuestion:Question = Question(questionGroup.questions.getItemAt(question)); -// //This should be handled inside the question itself. -// var txt:Text = new Text(); -// txt.width = 300; -// txt.htmlText = tempQuestion.question; -// tempBox.addChild(txt); - if(tempQuestion is Categorical) { var cq:CategoricalQuestionC = new CategoricalQuestionC(); @@ -101,6 +102,8 @@ } else { + // these questions don't have a *Question class associated with them + // they are differentiated by Question.type:String if(tempQuestion == null || tempQuestion.type == null) { var tq:TextQuestionC = new TextQuestionC(); @@ -146,6 +149,7 @@ tempBox.addChild(ffq); } + // when all else fails, text question else { tq = new TextQuestionC(); @@ -165,8 +169,7 @@ var head:Text = new Text(); var desc:Text = new Text(); head.setStyle("fontSize", 12); - head.width = 600; - desc.width = 600; + head.width = desc.width = 600; head.htmlText = questionGroup.header; desc.htmlText = questionGroup.description; if(desc.htmlText.length != 0) tempBox.addChildAt(desc,0); @@ -176,6 +179,8 @@ // msg += "item added\n"; } + // if this is a communication round + // trying to add a communication component to the first page if(gameObject == null) return; if(gameObject.currentRound != null) { @@ -194,17 +199,21 @@ } } - public function componentsNotFinished(force:Boolean=false):Boolean + // returns true if all components on all pages are all finished + public function componentsFinished(force:Boolean=false):Boolean { - var returnValue:Boolean = false; + var returnValue:Boolean = true; var curr:VBox; var messages:String = ""; + // for each page for(var pageNumber:int=0; pageNumber < pages.length; pageNumber++) { curr = pages.getItemAt(pageNumber) as VBox; + var tempQuestion:DisplayObject; - var tempQuestion:DisplayObject; + // for each Strategy or DaybyDay decisions component + // if it is not complete, set the return value to false for(var i:int=0; i < curr.numChildren; i++) { tempQuestion = (curr.getChildAt(i) as DisplayObject); @@ -214,7 +223,7 @@ messages += "D"; if((tempQuestion as DayByDayDecisionsQuestionC).dayByDayContent.numChildren < 30) { - returnValue = true; + returnValue = false; } } else if(tempQuestion is StrategyDesignQuestionC) @@ -222,7 +231,7 @@ messages += "S"; if(!(tempQuestion as StrategyDesignQuestionC).accept()) { - returnValue = true; + returnValue = false; } } else @@ -232,35 +241,54 @@ } // Alert.show(messages + returnValue); } - return returnValue && !force; + + // if the force value is true, return true anyways + // else return the return value generated + return returnValue || force; } + + // returns whether the user has read enough pages, or if it's being forced public function finished(force:Boolean=false):Boolean - { return highestPageReached >= minPagesRead - 1 || force; } + { + return highestPageReached >= minPagesRead - 1 || force; + } public function get length():int - { return pages.length; } + { + return pages.length; + } + // returns the current page as a DisplayObject (VBox) + // This should be displayed public function get currentPage():DisplayObject { - if(pages != null && pages.length > 0) // pages? + if(pages != null && pages.length > 0) { - if(currentPageNumber < 0) currentPageNumber = 0; - if(currentPageNumber >= pages.length) currentPageNumber = pages.length - 1; - return (DisplayObject)(pages.getItemAt(currentPageNumber)); // VALID_RESULT + // fix the pagenumber + currentPageNumber = fix(currentPageNumber, 0, pages.length-1); + + // return a valid result if any pages at all exist + return (DisplayObject)(pages.getItemAt(currentPageNumber)); } - return null; // no pages + return null; // no pages exist } + + // go to the next page, update highest page reached if necessary public function nextPage():Boolean { currentPageNumber = fix(currentPageNumber + 1, 0, pages.length-1); highestPageReached = Math.max(currentPageNumber, highestPageReached) return true; } + + // go to the previous page public function prevPage():Boolean { currentPageNumber = fix(currentPageNumber - 1, 0, pages.length-1); return true; } + + // makes sure that a pagenumber is valid private function fix(n:Number,min:Number,max:Number):Number { if(n < min) return min; @@ -268,6 +296,7 @@ return n; } + // resets several types of questions to "abstain" public function reset():void { var curr:VBox = currentPage as VBox; Modified: mentalmodels/trunk/flex/src/custom/InstructionPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2009-12-10 21:56:15 UTC (rev 413) +++ mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2009-12-13 20:46:31 UTC (rev 414) @@ -16,8 +16,8 @@ import mx.collections.ArrayCollection; [Bindable] public var gameObject:actionscript.Game = null; - [Bindable] public var moduleNumber:int = 1; - [Bindable] public var module:Module; + //[Bindable] public var moduleNumber:int = 1; + //[Bindable] public var module:Module; [Bindable] public var blockNumber:int = 0; [Bindable] public var block:Block; [Bindable] public var pageDisplay:PageDisplay; @@ -26,6 +26,7 @@ [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); + // saved for use in information windows, etc public var savedForecastPeople:ArrayCollection = null; public var savedForecastFish:ArrayCollection = null; public var savedStrategyDesign:ArrayCollection = null; @@ -38,6 +39,8 @@ return newLoc; } + // makes sure the pageDisplay has been created + // then gives it gameObject public function setGameObject(newGameObject:actionscript.Game):void { this.gameObject = newGameObject; @@ -69,11 +72,15 @@ // init(module.blocks.getItemAt(blockNumber) as Block); // } + // this runs the first time a block is received + // creates a pagedisplay + // assigns pagedisplay a block + // displays first page to user public function init(newBlock:Block):void { block = newBlock; try{ -// debug2.text += "creating pageDisplay...\n"; + //debug2.text += "creating pageDisplay...\n"; var minPagesRead:int = 0; pageDisplay = null; if(block != null && block.questionGroups != null) @@ -86,9 +93,8 @@ debug2.text += "pageDisplay is null\n"; pageDisplay = new PageDisplay(makeBlock(),0,locations); } -// pageDisplay = new PageDisplay(block, block.questionGroups.length); - }catch(errObject:Error){ + // worst case scenario... still needs to have a pagedisplay debug2.text += "pageDisplay creation failure\n" + errObject.message +"\n"+ errObject.getStackTrace() +"\n"; pageDisplay = new PageDisplay(makeBlock(),0,locations); @@ -96,13 +102,16 @@ } setGameObject(this.gameObject); + // set page numbers currPage = pageDisplay.currentPageNumber; numPages = pageDisplay.pages.length; + // add to display content.removeAllChildren(); content.addChild(pageDisplay.currentPage); } + // try to turn the page back public function back():Boolean { preTurn(); @@ -114,6 +123,7 @@ return pageSuccess; } + // try to turn the page forward public function forward():Boolean { preTurn(); @@ -124,6 +134,8 @@ } return pageSuccess; } + + // save the first forecasting component, if it exists private function preTurn():void { var currPageArray:Array = (pageDisplay.currentPage as VBox).getChildren(); @@ -135,12 +147,12 @@ } } } + // load values into new forecasting component, if it exists private function postTurn():void { currPage = pageDisplay.currentPageNumber; currPageLabel.htmlText = - "Module: "+moduleNumber+ - "<br>Block: "+(blockNumber+1)+ + "Block: "+(blockNumber+1)+ "<br>Page: "+(currPage+1)+" / "+numPages; content.removeAllChildren(); @@ -157,11 +169,12 @@ } + // try finishing the block public function accept(force:Boolean=false):Boolean { try { - if(pageDisplay.componentsNotFinished(force)) + if(! pageDisplay.componentsFinished(force)) { Alert.show("You must complete all required sections of the Block.","Cannot Advance"); } @@ -181,6 +194,7 @@ return false; } + // reset questions to abstain values public function reset():void { if(pageDisplay != null) @@ -189,6 +203,7 @@ } } + // save all components that we can, for use in infowindows etc public function saveData():void { var currPageArray:Array = (pageDisplay.currentPage as VBox).getChildren(); @@ -225,6 +240,7 @@ block = (loadArray.getItemAt(0) as Block); } + // creates a dummy block, in case something goes wrong creating the pagedisplay public function makeBlock():Block { var block:Block = new Block(); @@ -246,7 +262,7 @@ ]]> </mx:Script> - <mx:Text id="currPageLabel" htmlText="Module: {moduleNumber}<br>Block: {(blockNumber+1)}<br>Page: {(currPage+1)} / {numPages}"/> + <mx:Text id="currPageLabel" htmlText="Block: {(blockNumber+1)}<br>Page: {(currPage+1)} / {numPages}"/> <mx:VBox id="content"/> <mx:Text id="debug" text="{pageDisplay.msg}" width="300"/> Modified: mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml 2009-12-10 21:56:15 UTC (rev 413) +++ mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml 2009-12-13 20:46:31 UTC (rev 414) @@ -37,13 +37,16 @@ var red:String = "#FF0000"; var white:String = "#FFFFFF"; - if(getGender().length != 1) // possible genders are: "M", "F", "Err" + // possible genders are: "M", "F", "Err" + if(getGender().length != 1) { boxGender.setStyle(bgcolor, red); ready=false; }else{ boxGender.setStyle(bgcolor, ""); } + + // age must be less than 180 years ago var today:Date = new Date(); if(getYear().length != 4 || Number(getYear()) < today.fullYear - 180 || Number(getYear()) > today.fullYear) { @@ -131,7 +134,7 @@ <mx:HBox> <mx:Label text="Semester:" fontWeight="bold" width="100" textAlign="right"/> <mx:ComboBox id="cbxSemester" selectedIndex="0" dataProvider="{new ArrayCollection(['Freshman','Sophomore','Junior','Senior','Graduate/Other'])}"/> - <!--<mx:TextInput id="txtSemester" width="75" maxChars="6"/>--> + <!--<mx:TextInput id="txtSemester" width="75" maxChars="7"/>--> </mx:HBox> <mx:HBox> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kj...@us...> - 2010-01-15 21:20:38
|
Revision: 433 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=433&view=rev Author: kjonas Date: 2010-01-15 21:20:31 +0000 (Fri, 15 Jan 2010) Log Message: ----------- error-testing in progress in InstructionPage.mxml changed planner, strategy design to new specs Modified Paths: -------------- 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/strategyDesign/Planner.mxml mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml mentalmodels/trunk/flex/src/test.mxml Modified: mentalmodels/trunk/flex/src/custom/CommunicationC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/CommunicationC.mxml 2010-01-15 20:38:59 UTC (rev 432) +++ mentalmodels/trunk/flex/src/custom/CommunicationC.mxml 2010-01-15 21:20:31 UTC (rev 433) @@ -42,10 +42,13 @@ tempCommunication.timestamp = new Date(); tempCommunication.message = txtMessage.text; tempCommunication.student = DataModel.instance.studentObject; - tempCommunication.round = DataModel.instance.gameObject.currentRound; + if(DataModel.instance.gameObject != null) + { + tempCommunication.round = DataModel.instance.gameObject.currentRound; + communicationService.saveCommunication(tempCommunication); + } txtMessage.text = ""; - communicationService.saveCommunication(tempCommunication); } public function btnSelfComm_click():void { Modified: mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2010-01-15 20:38:59 UTC (rev 432) +++ mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2010-01-15 21:20:31 UTC (rev 433) @@ -353,7 +353,7 @@ var strategy:StrategyDesignQuestionC = StrategyDesignQuestionC(curr.getChildAt(j)); var tempDBObjects:ArrayCollection = strategy.toDatabaseObject(); - roundObject = strategy.notRepeated.round; + roundObject = strategy.repeated.round; for(var k:int=0;k<tempDBObjects.length;k++) { Modified: mentalmodels/trunk/flex/src/custom/InstructionPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2010-01-15 20:38:59 UTC (rev 432) +++ mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2010-01-15 21:20:31 UTC (rev 433) @@ -97,7 +97,7 @@ }catch(errObject:Error){ // worst case scenario... still needs to have a pagedisplay debug2.text += "pageDisplay creation failure\n" + - errObject.message +"\n"+ errObject.getStackTrace() +"\n"; + errObject.name +"\n"+ errObject.message +"\n"+ errObject.getStackTrace() +"\n"; pageDisplay = new PageDisplay(makeBlock(),0,locations); // Alert.show(debug2.text); } Modified: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml 2010-01-15 20:38:59 UTC (rev 432) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml 2010-01-15 21:20:31 UTC (rev 433) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="custom.*" - width="350" height="200" - borderStyle="solid" verticalScrollPolicy="off" horizontalScrollPolicy="off"> + borderStyle="solid" verticalScrollPolicy="off" horizontalScrollPolicy="off" + width="350" height="200" creationComplete="init()"> <mx:Script> <![CDATA[ Modified: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml 2010-01-15 20:38:59 UTC (rev 432) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml 2010-01-15 21:20:31 UTC (rev 433) @@ -9,30 +9,8 @@ ]]> </mx:Script> - <mx:HBox> - <mx:VBox> - <mx:Label text="Not Repeated decisions (start-up)" fontSize="18"/> - <qComp:Planner id="notRepeated"/> - </mx:VBox> - <mx:VBox> - <mx:Label text="Repeated decisions (after start-up)" fontSize="18"/> - <qComp:Planner id="repeated" valueRequired="true"/> - </mx:VBox> - </mx:HBox> + <qComp:Planner id="repeated" valueRequired="true"/> - <mx:HBox> - <mx:Label text="Suspend repetition:" fontWeight="bold" width="130"/> - <mx:Label text="If during one repetition"/> - <mx:NumericStepper id="suspendWeight" value="5" minimum="0.1" maximum="100" stepSize="0.1" height="20" width="50"/> - <mx:Label text="lbs could not be fished,"/> - </mx:HBox> - <mx:HBox> - <mx:Label width="113"/> - <mx:Label text="then stay in the harbor for"/> - <mx:NumericStepper id="suspendDays" value="1" minimum="0" maximum="30" stepSize="1" height="20" width="50"/> - <mx:Label text="days before starting the next repetition."/> - </mx:HBox> - <mx:RemoteObject id="GameService" destination="gameService" fault="faultHandler(event)"> <mx:method name="getCurrentRoundNo" result="roundResultHandler(event)"/> </mx:RemoteObject> @@ -68,42 +46,33 @@ } public function setRound(newRound:Round):void { - repeated.round = notRepeated.round = newRound; + repeated.round = newRound; } public function faultHandler(event:FaultEvent):void { Alert.show("Error finding round for Strategy Design!"); - repeated.round = notRepeated.round = null; + repeated.round = null; } - public function getNotRepeated():ArrayCollection - { return notRepeated.save(); } - public function getRepeated():ArrayCollection { return repeated.save(); } public function accept():Boolean { - return repeated.hasBeenChanged || notRepeated.hasBeenChanged; + return repeated.hasBeenChanged; } public function save():ArrayCollection { var saveArray:ArrayCollection = new ArrayCollection(); - saveArray.addItem(notRepeated.save()); saveArray.addItem(repeated.save()); - saveArray.addItem(suspendWeight.value); - saveArray.addItem(suspendDays.value); return saveArray; } public function load(loadArray:ArrayCollection):void { - if(notRepeated == null || repeated == null || loadArray == null) return; - notRepeated.load(loadArray.getItemAt(0) as ArrayCollection); + if(repeated == null || loadArray == null) return; repeated.load(loadArray.getItemAt(1) as ArrayCollection); - suspendWeight.value = loadArray.getItemAt(2) as Number; - suspendDays.value = loadArray.getItemAt(3) as Number; } public function loadFromQuestion(question:Question):void @@ -113,9 +82,7 @@ initialize(); init(); - notRepeated.locations = locations; repeated.locations = locations; - notRepeated.init(); repeated.init(); } @@ -124,26 +91,10 @@ var array:ArrayCollection = new ArrayCollection(); var tempObject:StudentStrategy; - var notRepeatedArray:ArrayCollection = notRepeated.save(); var repeatedArray:ArrayCollection = repeated.save(); var i:int; var tempArray:ArrayCollection; - - for(i=0;i<notRepeatedArray.length;i++) - { - tempArray = notRepeatedArray.getItemAt(i) as ArrayCollection; - tempObject = new StudentStrategy(); - tempObject.location = strToLocation(tempArray.getItemAt(0) as String); - tempObject.days = int(tempArray.getItemAt(1) as Number); - tempObject.threshold = (tempArray.getItemAt(2) as Number); - tempObject.round = notRepeated.round; - - tempObject.allocationSeqNo = i; - tempObject.repeatedDecision = false; - - array.addItem(tempObject); - } for(i=0;i<repeatedArray.length;i++) { tempArray = repeatedArray.getItemAt(i) as ArrayCollection; @@ -153,7 +104,7 @@ tempObject.threshold = (tempArray.getItemAt(2) as Number); tempObject.round = repeated.round; - tempObject.allocationSeqNo = i+notRepeatedArray.length; + tempObject.allocationSeqNo = i; tempObject.repeatedDecision = true; array.addItem(tempObject); Modified: mentalmodels/trunk/flex/src/test.mxml =================================================================== --- mentalmodels/trunk/flex/src/test.mxml 2010-01-15 20:38:59 UTC (rev 432) +++ mentalmodels/trunk/flex/src/test.mxml 2010-01-15 21:20:31 UTC (rev 433) @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="utf-8"?> -<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:actionscript="actionscript.*" xmlns:custom="custom.*"> +<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:actionscript="actionscript.*" xmlns:custom="custom.*" xmlns:strategyDesign="custom.questions.strategyDesign.*"> <custom:CommunicationC/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kj...@us...> - 2010-01-15 23:40:50
|
Revision: 439 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=439&view=rev Author: kjonas Date: 2010-01-15 23:40:43 +0000 (Fri, 15 Jan 2010) Log Message: ----------- added list of locations to the DataModel.as file and updated references to load/save from here. SocioDemographicPage.mxml pre-fills data fields with testing information StrategyDesignQuestionC.mxml has been tested to at least *look* properly. may not function (save to server) Modified Paths: -------------- mentalmodels/trunk/flex/src/actionscript/DataModel.as mentalmodels/trunk/flex/src/actionscript/PageDisplay.as mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml mentalmodels/trunk/flex/src/custom/InstructionPage.mxml mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml Modified: mentalmodels/trunk/flex/src/actionscript/DataModel.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/DataModel.as 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/actionscript/DataModel.as 2010-01-15 23:40:43 UTC (rev 439) @@ -1,12 +1,22 @@ package actionscript { + import mx.collections.ArrayCollection; + public class DataModel { private static const INSTANCE:DataModel = new DataModel(); public var studentObject:actionscript.Student = null; public var gameObject:actionscript.Game = null; + public var locations:ArrayCollection = null; + private function newLocation(maxCapacity:Number,growth:Number):Location + { + var newLoc:Location = new Location(); + newLoc.growthRate = growth; + return newLoc; + } + public function DataModel():void { if (INSTANCE != null) Modified: mentalmodels/trunk/flex/src/actionscript/PageDisplay.as =================================================================== --- mentalmodels/trunk/flex/src/actionscript/PageDisplay.as 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/actionscript/PageDisplay.as 2010-01-15 23:40:43 UTC (rev 439) @@ -29,27 +29,17 @@ public var currentPageNumber:int; public var highestPageReached:int; - public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); - public var currBlock:Block; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - // requires a block, and a list of locations. // the "minimumPagesRead" variable will not let the student finish the block until that // many pages have been viewed. - public function PageDisplay(newBlock:Block, minimumPagesRead:int, locations:ArrayCollection) + public function PageDisplay(newBlock:Block, minimumPagesRead:int) { currBlock = newBlock; minPagesRead = minimumPagesRead; currentPageNumber = 0; highestPageReached = currentPageNumber; - this.locations = locations; // generates the objects that will be displayed on each "page" in the block loadPages(); @@ -116,9 +106,8 @@ else if(tempQuestion.type.toLowerCase() == "strategydesign") { var sdq:StrategyDesignQuestionC = new StrategyDesignQuestionC(); - sdq.locations = locations; - sdq.setRound(gameObject.currentRound); sdq.loadFromQuestion(Question(tempQuestion)); + sdq.setRound(DataModel.instance.gameObject.currentRound); sdq.id = "q"+question; tempBox.addChild(sdq); @@ -126,7 +115,6 @@ else if(tempQuestion.type.toLowerCase() == "daybydaydecisions") { var ddq:DayByDayDecisionsQuestionC = new DayByDayDecisionsQuestionC(); - ddq.locations = locations; ddq.loadFromQuestion(Question(tempQuestion)); ddq.id = "q"+question; @@ -135,7 +123,6 @@ else if(tempQuestion.type.toLowerCase() == "forecastingfishermen") { var fpq:ForecastingPeopleQuestionC = new ForecastingPeopleQuestionC(); - fpq.locations = locations; fpq.loadFromQuestion(tempQuestion); fpq.id = "q"+question; @@ -144,7 +131,6 @@ else if(tempQuestion.type.toLowerCase() == "forecastingfish") { var ffq:ForecastingFishQuestionC = new ForecastingFishQuestionC(); - ffq.locations = locations; ffq.loadFromQuestion(tempQuestion); ffq.id = "q"+question; Modified: mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/FisheryExperimentCore.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -19,8 +19,7 @@ <!-- This is a temporary state that jumpstarts the "instructions" state for the first time --> <mx:State name="instructionsLoad"> <mx:AddChild relativeTo="{content}"> - <comp:InstructionPage id="instructions" initialize="gotoInstructions()" x="0" y="0" - preinitialize="instructions.setLocations(locations)"/> + <comp:InstructionPage id="instructions" initialize="gotoInstructions()" x="0" y="0"/> </mx:AddChild> </mx:State> @@ -118,7 +117,6 @@ public var gameObject:actionscript.Game = null; public var currentBlock:Block = null; public var currentBlockNumber:int = 0; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); public var instructionsLoaded:Boolean = false; [Bindable] public var studentObject:actionscript.Student; [Bindable] public var roundObject:actionscript.Round; @@ -144,7 +142,7 @@ // 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.Game) + if(event.message.body as actionscript.Game != null) { gameObject = event.message.body as actionscript.Game; DataModel.instance.gameObject = gameObject; @@ -154,12 +152,12 @@ instructions.setGameObject(this.gameObject); } } - else if(event.message.body is actionscript.Block) + else if(event.message.body as actionscript.Block != null) { Alert.show("Server sent Block, not Game.",""); setBlock(event.message.body as actionscript.Block); } - else if(event.message.body is ArrayCollection) + else if(event.message.body as ArrayCollection != null) { var students:ArrayCollection = new ArrayCollection(); students = ArrayCollection(event.message.body); @@ -182,7 +180,7 @@ } } } -// Alert.show("Current Student Information is: " + "\n"+SingletonStudent.instance.studentObject.id +"\n"+SingletonStudent.instance.studentObject.gameCode+"\n"+SingletonStudent.instance.studentObject.studentNo); +// Alert.show("Current Student Information is: " + "\n"+DataModel.instance.studentObject.id +"\n"+DataModel.instance.studentObject.gameCode+"\n"+DataModel.instance.studentObject.studentNo); } } @@ -221,15 +219,6 @@ Alert.show("Block received in Instructions (load) state.","Unexpected Block"); } } - - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - //newLoc.maxCapacity = maxCapacity; - //newLoc.initialPopulation = maxCapacity / 2.0; - newLoc.growthRate = growth; - return newLoc; - } public function init():void { @@ -302,7 +291,7 @@ else if(curr.getChildAt(j) is ForecastingPeopleQuestionC) { var forecast1:ForecastingPeopleQuestionC = (curr.getChildAt(j) as ForecastingPeopleQuestionC); - for(row=0; row<locations.length; row++) + for(row=0; row<DataModel.instance.locations.length; row++) { studentResponse = new StudentResponse(); studentResponse.student = studentObject; @@ -325,7 +314,7 @@ else if(curr.getChildAt(j) is ForecastingFishQuestionC) { var forecast2:ForecastingFishQuestionC = (curr.getChildAt(j) as ForecastingFishQuestionC); - for(row=0; row<locations.length-1; row++) + for(row=0; row<DataModel.instance.locations.length-1; row++) { studentResponse = new StudentResponse(); studentResponse.student = studentObject; @@ -357,7 +346,7 @@ for(var k:int=0;k<tempDBObjects.length;k++) { - (tempDBObjects.getItemAt(k) as StudentStrategy).student = studentObject; + (tempDBObjects.getItemAt(k) as StudentStrategy).student = DataModel.instance.studentObject; (tempDBObjects.getItemAt(k) as StudentStrategy).round = roundObject; } @@ -444,11 +433,7 @@ { if(event.result is ArrayCollection) { - locations = event.result as ArrayCollection; - if(instructions != null) - { - instructions.setLocations(locations); - } + DataModel.instance.locations = event.result as ArrayCollection; } } private function strategyResultHandler(event:ResultEvent):void Modified: mentalmodels/trunk/flex/src/custom/InstructionPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/InstructionPage.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -25,21 +25,12 @@ [Bindable] public var numPages:int = 1; [Bindable] public var currPage:int = 0; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); - // saved for use in information windows, etc public var savedForecastPeople:ArrayCollection = null; public var savedForecastFish:ArrayCollection = null; public var savedStrategyDesign:ArrayCollection = null; public var savedDayByDayDecisions:ArrayCollection = null; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - // makes sure the pageDisplay has been created // then gives it gameObject public function setGameObject(newGameObject:actionscript.Game):void @@ -87,18 +78,18 @@ if(block != null && block.questionGroups != null) { minPagesRead = block.questionGroups.length - pageDisplay = new PageDisplay(block, minPagesRead,locations); + pageDisplay = new PageDisplay(block, minPagesRead); } if(pageDisplay == null) { debug2.text += "pageDisplay is null\n"; - pageDisplay = new PageDisplay(makeBlock(),0,locations); + pageDisplay = new PageDisplay(makeBlock(),0); } }catch(errObject:Error){ // worst case scenario... still needs to have a pagedisplay debug2.text += "pageDisplay creation failure\n" + errObject.name +"\n"+ errObject.message +"\n"+ errObject.getStackTrace() +"\n"; - pageDisplay = new PageDisplay(makeBlock(),0,locations); + pageDisplay = new PageDisplay(makeBlock(),0); // Alert.show(debug2.text); } setGameObject(this.gameObject); @@ -251,15 +242,6 @@ return block; } - public function setLocations(newLocations:ArrayCollection):void - { - locations = newLocations; - if(pageDisplay != null) - { - pageDisplay.locations = newLocations; - } - } - ]]> </mx:Script> Modified: mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/SocioDemographicPage.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -1,10 +1,19 @@ <?xml version="1.0" encoding="utf-8"?> -<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" verticalAlign="middle" horizontalAlign="center"> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" verticalAlign="middle" horizontalAlign="center" + creationComplete="test_init()"> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; + public function test_init():void + { + radioMale.selected = true; + txtYear.text = "2010"; + txtMajor.text = "CSE"; + txtGameCode.text = "test1"; + } + public function getGender():String { if(radioMale.selected) { return "M"; } Modified: mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -22,6 +22,7 @@ <mx:Script> <![CDATA[ + import actionscript.DataModel; import actionscript.Location; import mx.controls.Alert; import mx.collections.ArrayCollection; @@ -30,18 +31,10 @@ import actionscript.questions.*; import custom.questions.dayByDayDecisions.OneDay; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); [Bindable] public var deciding:int = 0; [Bindable] public var cumTotal:Number = 0; [Bindable] public var dollarPerLb:Number = 3.99; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - public function init():void { buttons.removeAllChildren(); @@ -64,7 +57,7 @@ txtTemp.text = "Harbor"; labels.addChild(txtTemp); - for(var i:int = 1; i < locations.length; i++) + for(var i:int = 1; i < DataModel.instance.locations.length; i++) { btnTemp = new Button(); btnTemp.label = "Bay" + (i); @@ -125,7 +118,6 @@ } var newDay:OneDay = new OneDay(); - newDay.locations = locations; newDay.initialize(); newDay.day = dayByDayContent.numChildren + 1; newDay.dollarPerLb = dollarPerLb; @@ -149,7 +141,6 @@ var day:OneDay = dayByDayContent.getChildAt(i) as OneDay; var newDay:OneDay = new OneDay(); - newDay.locations = locations; newDay.initialize(); newDay.day = day.day; newDay.dollarPerLb = day.day; Modified: mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -3,12 +3,12 @@ <mx:Script> <![CDATA[ + import actionscript.DataModel; import actionscript.Location; import mx.controls.Text; import mx.controls.Label; import mx.collections.ArrayCollection; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); [Bindable] public var decisions:ArrayCollection; public var previousTotal:Number = 0; @@ -16,20 +16,13 @@ public var day:int = 1; public var dollarPerLb:Number = 3.99; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - public function init():void { if(decisions == null) { drawNull(); } - else if(decisions.length < locations.length+1) + else if(decisions.length < DataModel.instance.locations.length+1) { drawPartial(); } @@ -55,7 +48,7 @@ public function drawPartial():void { var temp:OneDecision; - for(var i:int = decisions.length; i < locations.length; i++) + for(var i:int = decisions.length; i < DataModel.instance.locations.length; i++) { temp = new OneDecision(); temp.active = false; @@ -78,7 +71,7 @@ dayText.minWidth = 50; addChild(dayText); - for(var i:int = 0; i < locations.length && i < decisions.length; i++) + for(var i:int = 0; i < DataModel.instance.locations.length && i < decisions.length; i++) { var temp:OneDecision = (decisions.getItemAt(i) as OneDecision); presentTotal += temp.lbsFished; @@ -108,7 +101,7 @@ } else { - for(var i:int = 0; i < locationChosen && i < locations.length; i++) + for(var i:int = 0; i < locationChosen && i < DataModel.instance.locations.length; i++) { var tempInactive:OneDecision = new OneDecision(); tempInactive.active = false; Modified: mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -5,6 +5,7 @@ <mx:Script> <![CDATA[ + import actionscript.DataModel; import actionscript.Location; import mx.controls.Alert; import mx.events.FlexEvent; @@ -26,7 +27,7 @@ // Game Data [Bindable] public var style:int = 0; // 0:People, 1:Fish, 2:Calculated // [Bindable] public var numBays:int = 3; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); + [Bindable] public var locations:ArrayCollection = DataModel.instance.locations; [Bindable] public var numColumns:int = -1; [Bindable] public var numFields:int = 15; [Bindable] public var minValue:int = 0; @@ -38,13 +39,6 @@ // for lining up grids [Bindable] public var minimumWidth:int = 160; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - // // public accessible functions // Modified: mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -27,6 +27,7 @@ <mx:Script> <![CDATA[ + import actionscript.DataModel; import actionscript.questions.Question; import actionscript.Location; import mx.controls.Alert; @@ -36,17 +37,10 @@ public var loadFish:ArrayCollection = null; public var loadPeople:ArrayCollection = null; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); + [Bindable] public var locations:ArrayCollection = DataModel.instance.locations; [Bindable] public var numColumns:int = 6; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - public function init():void { if(fishEntry == null || peopleDisplay == null || calculated == null) return; Modified: mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -24,6 +24,7 @@ <mx:Script> <![CDATA[ + import actionscript.DataModel; import actionscript.questions.Question; import actionscript.Location; import actionscript.questions.ForecastingPeople; @@ -31,17 +32,10 @@ import custom.questions.forecasting.ForecastComponent; public var loadPeople:ArrayCollection = null; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); + [Bindable] public var locations:ArrayCollection = DataModel.instance.locations; [Bindable] public var numColumns:int = 15; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - public function init():void { if(peopleEntry == null) return; Modified: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -12,16 +12,8 @@ public var valueRequired:Boolean = false; public var hasBeenChanged:Boolean = false; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); public var round:Round = null; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - public function init():void { if(valueRequired && grid.numChildren == 0) @@ -40,7 +32,6 @@ { var newRow:PlannerRow = new PlannerRow(); newRow.valueRequired = this.valueRequired; - newRow.locations = locations; newRow.initialize(); newRow.init(); var newNumber:Label = new Label(); Modified: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -3,18 +3,12 @@ <mx:Script> <![CDATA[ + import actionscript.DataModel; import actionscript.Location; public var valueRequired:Boolean = false; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); + [Bindable] public var locations:ArrayCollection = DataModel.instance.locations; - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - public function init():void { locs.removeAll(); Modified: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml 2010-01-15 23:36:34 UTC (rev 438) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml 2010-01-15 23:40:43 UTC (rev 439) @@ -26,15 +26,6 @@ import actionscript.questions.Question; import mx.collections.ArrayCollection; - [Bindable] public var locations:ArrayCollection = new ArrayCollection([newLocation(0, 0)]); - - private function newLocation(maxCapacity:Number,growth:Number):Location - { - var newLoc:Location = new Location(); - newLoc.growthRate = growth; - return newLoc; - } - public function init():void { } @@ -82,7 +73,6 @@ initialize(); init(); - repeated.locations = locations; repeated.init(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |