package ConceptGraphHigh { import ConceptGraphHigh.Character; import flash.display.*; import flash.filters.*; import flash.net.NetConnection; import flash.net.NetStream; import flash.media.Video; import flash.text.TextFieldAutoSize; import flash.text.TextField; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.Transform; import flash.geom.Matrix; import flash.text.TextFormat; import flash.ui.Mouse; public class actionscript_graph_high_CharacterHandler extends Sprite{ private var characterHandler:Array = new Array() //Array with the updated index of the elements in arrayCharacter private var allCharacters:Array = new Array; //Array with all the character objects contained in the XML File (charData) private var arrayCharacter:Array = new Array; //Array containing the character Object (arrayCharacter.object) and the quality of the relation (arrayCharacter.relation) private var arrayRelations:Array = new Array; //Contains relations among persons: fromID, toID, quality private var subRelation:Array = new Array; private var container:Sprite = new Sprite(); private var originX:uint = 400; //Set the X center (where the clicked character is set) private var originY:uint = 365; //Set the Y center (where the clicked character is set) private var affineTransform:Matrix; private var distanceBetweenTurns:uint = 70; private var radiusCircle:uint = 100; private var radius:uint = 50; private var numCharactersFirstTurn:uint = 15; //Minimum 3 private var increaseCharactersFactor:uint = 3; private var selectedLabel:TextField; private var descriptionLabel:TextField; private var ns:NetStream; private var textObjectArray:Array = new Array(); private var textObjectDisplayed:int = 0; //Parameter of the application private var textToolTip:TextField; public function actionscript_graph_high_CharacterHandler (charData:Array, arrayRelations:Array, selectedLabel:TextField, descriptionLabel:TextField, ns:NetStream, textToolTip:TextField):void { this.arrayRelations = arrayRelations; this.selectedLabel=selectedLabel; this.descriptionLabel=descriptionLabel; this.ns = ns; this.textToolTip= textToolTip; for (var j:int=0; jtextObjectArray.length) { var textRelationDescription:TextField = new TextField(); textRelationDescription.background=true; textRelationDescription.border=true; textRelationDescription.autoSize=TextFieldAutoSize.CENTER; textObjectArray.push(textRelationDescription); container.addChild(textObjectArray[textObjectArray.length-1]); textObjectDisplayed++; } //While there are more characters in the screen than textFields visible, we need to add them to the container while ((arrayCharacter.length-1)>textObjectDisplayed) { container.addChild(textObjectArray[textObjectDisplayed]); textObjectDisplayed++; } //Set as visible only the textFields with content (not empty spaces) for (var m:int=1; m(arrayCharacter.length-1)) { container.removeChild(textObjectArray[textObjectDisplayed-1]); textObjectDisplayed--; } subRelation.splice(0, subRelation.length); } private function characterGeometry():void { var existentRelation:Boolean = false; var angle:Number = 0; var characterOne:Character; var indexTurns:int = 1; var increaseSize:Number = 0 //The size of the circle, the number of turs var currentTurn:int = 1; //The current number of turns var constantDivisionNum:int; var value:int; arrayCharacter[0].setXWanted(originX); arrayCharacter[0].setYWanted(originY); for (indexTurns; (increaseSize + numCharactersFirstTurn - 3 + Math.pow(increaseCharactersFactor, indexTurns)) < arrayCharacter.length; indexTurns++) { increaseSize += numCharactersFirstTurn - 3 + Math.pow(increaseCharactersFactor, indexTurns) } //Check for subrelations among characters in arrayCharacters (characterOne and characterTwo) for (var i:int = 1; i(value + numCharactersFirstTurn - 3 + Math.pow(increaseCharactersFactor, currentTurn)) || (i-1)==(value + numCharactersFirstTurn - 3 + Math.pow(increaseCharactersFactor, currentTurn)); currentTurn++) { value += numCharactersFirstTurn - 3 + Math.pow(increaseCharactersFactor, currentTurn) } if ((i-1) < increaseSize) { //If we are over increaseSize we divide the angle among the constantDivisionNum constantDivisionNum = numCharactersFirstTurn - 3 + Math.pow(increaseCharactersFactor, currentTurn); angle += (360/(constantDivisionNum))*Math.PI/180; } else { //Otherwise, we divide it amongst the rest of the characters angle += 360/(arrayCharacter.length-increaseSize-1)*Math.PI/180; } arrayCharacter[i].setXWanted(originX + (((radiusCircle + (currentTurn * distanceBetweenTurns))*Math.cos(angle)))); //Final destination of the character arrayCharacter[i].setYWanted(originY + (((radiusCircle + (currentTurn * distanceBetweenTurns))*Math.sin(angle)))); //Final destination of the character } } public function click(characterClicked:Character): void { var tempArray:Array = new Array(); selectedLabel.htmlText = "You have selected: " + characterClicked.getName(); descriptionLabel.htmlText = "Description: " + characterClicked.getDescription(); trace ("esto"+characterClicked.getVideoURL()+"es"); if ((characterClicked.getVideoURL()==null) || (characterClicked.getVideoURL()== "")) { ns.pause(); } else { ns.play(characterClicked.getVideoURL()); } for (var i:int = 0; i All the characters when the mouse was clicked //tempArray => All the characters that are related to the clicked character checkExistence(tempArray); //Update arrayCharacter with tempArray characterGeometry(); //Set the characters (math and geometry) } public function overCharacter(ev:MouseEvent):void { ev.target.filters=[new BevelFilter( )]; //Bevel Filter when the mouse is over the character ev.target.increaseSize(60); //Increase the size ev.target.setIndexDisplay(container.getChildIndex(Character(ev.target))); container.addChildAt(Character(ev.target), container.numChildren); //Display the character in the front } private function mouseMoveCharacter(ev:MouseEvent):void { toolTipIn(ev); //When the mouse is over the character the tooltiptext is on } private function toolTipIn (ev:MouseEvent):void { textToolTip.visible=true; //The tooltiptext is visible now textToolTip.x=mouseX+40; //The tooltiptext follows the mouse X textToolTip.y=mouseY+40; //The tooltiptext follows the mouse Y textToolTip.htmlText = "Name: " + ev.target.getName() + "\nRelation: " + ev.target.getRelationExplanation(); } public function outCharacter(ev:MouseEvent):void { ev.target.decreaseSize(); //Decrease size ev.target.filters=[]; //Eliminate Bevel Filter container.addChildAt(Character(ev.target), 1); //Place the character where it was situated toolTipOut(); //When the mouse is out of the character the tooltiptext disappear } private function toolTipOut():void { textToolTip.visible=false; //The tooltiptext is not visible now } public function onPress(ev:MouseEvent):void { click(Character(ev.target)); } } }