topical media & game development

talk show tell print

actionscript-graph-high-ConceptGraphHigh.ax

actionscript-graph-high-ConceptGraphHigh.ax [swf] flex


  package {
          import flash.display.*;
          import flash.events.Event;
          import flash.net.*;
      import flash.net.URLRequest;
          import @ax-actionscript-graph-high-ConceptGraphHigh.Character;
          import @ax-actionscript-graph-high-ConceptGraphHigh.CharacterHandler;
          import flash.events.MouseEvent;
          import flash.display.StageScaleMode;
          import @ax-actionscript-graph-high-ConceptGraphHigh.Relation;
          import flash.text.TextFieldAutoSize;
          import flash.text.TextField;  
          import flash.geom.Matrix;
          import flash.media.Video;
          public class @ax-actionscript-graph-high-ConceptGraphHigh extends Sprite {
                  private var container:Sprite = new Sprite();
                  private var containerInfo:Sprite = new Sprite(); 
                  private var affineTransform:Matrix; 
                  private var affineTranslate:Matrix;        
                  private var selectedLabel:TextField = new TextField();
                  private var descriptionLabel:TextField = new TextField();
          private var nc:NetConnection;
          private var ns:NetStream;
          private var video:Video;
          private var client:Object;
          private var _loader:Loader=new Loader();
          private var originInfoY:uint=50;
          private var originInfoX:uint=975;
          private var rectWidth:uint=350;
          private var rectHeight:uint=600;
          private var selectedLabelWidth:uint=300;
          private var selectedLabelHeight:uint=20;
          private var selectedLabelX:uint=25;
          private var selectedLabelY:uint=130;
          private var descriptionLabelWidth:uint=300;
          private var descriptionLabelHeight:uint=150;
          private var descriptionLabelX:uint=25;
          private var descriptionLabelY:uint=160;
          private var imageWidth:uint=100;
          private var imageHeight:uint=100;
          private var imageX:uint=125;
          private var imageY:uint=15;
          private var videoWidth:uint=300;
          private var videoHeight:uint=240;
          private var videoX:uint=25;
          private var videoY:uint=330;
          private var zoomFactor:Number=21/20;
                  private var textToolTip:TextField = new TextField();        
                  private var textToolTipWidth:uint = 150;
                  private var textToolTipHeight:uint = 100;
                  private var textToolTipBackGroundColor:Number = 0xFFCC22;
          public function bitmapLoader(  ):void {                //Loads the info i image
              _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
              _loader.load(new URLRequest("info.png"));
          }
              public function onComplete(event:Event):void {        //Sets the info i image
                  var image:Bitmap = Bitmap(_loader.content);
                  var bitmap:BitmapData = image.bitmapData;
                  image.width=imageWidth;
                  image.height=imageHeight;
                  image.x=originInfoX+imageX;
                  image.y=originInfoY+imageY;
                  containerInfo.addChild(image);
              }   
              public function @ax-actionscript-graph-high-ConceptGraphHigh() {
                            stage.scaleMode = StageScaleMode.NO_SCALE;                                //No Scale
                          stage.align=StageAlign.TOP_LEFT;                                                //Alignment TOP-LEFT
                          stage.addChild(container);
                          stage.addChild(containerInfo);
                          setDisplayInfo();
                          trace("Making XMLoader instance");
                                var loader:URLLoader = new URLLoader(  );
                                loader.addEventListener( Event.COMPLETE, handleComplete );                //Handle event
                                loader.load( new URLRequest( "data.xml" ) );                                        //XML file
                        trace("Out of XMLLoader constructor");
              }
              private function setVideo():void {                        //Sets the video 
              nc = new NetConnection();
              nc.connect (null); // Not using a media server.
              ns = new NetStream(nc);
              video = new Video(videoWidth,videoHeight);
              video.x=originInfoX+videoX;
              video.y = originInfoY+videoY;
              containerInfo.addChild(video);
              client = new Object();
              ns.client=client;
              video.attachNetStream(ns);                    
              }
              private function setDisplayInfo(): void {
                      containerInfo.graphics.lineStyle(2);                        //Draw the rectangle
                      containerInfo.graphics.beginFill(0x99BBDD);
                          containerInfo.graphics.drawRect(originInfoX,originInfoY,rectWidth,rectHeight);
                          containerInfo.graphics.endFill();
                      selectedLabel.x=originInfoX+selectedLabelX;                                                        //Set the label with the information
                      selectedLabel.y=originInfoY+selectedLabelY;                                                        //about what character is selected
                      selectedLabel.width = selectedLabelWidth;
                      selectedLabel.height = selectedLabelHeight;
                      containerInfo.addChild(selectedLabel);
                      selectedLabel.border=true;
                      selectedLabel.background=true;
                      descriptionLabel.border=true;                                        //Set the label with the information
                      descriptionLabel.x=originInfoX+descriptionLabelX;                                                //about the description of the character
                      descriptionLabel.y=originInfoY+descriptionLabelY;
                      descriptionLabel.width=descriptionLabelWidth;
                      descriptionLabel.height=descriptionLabelHeight;
                      descriptionLabel.wordWrap=true;
                      descriptionLabel.background=true;
                          textToolTip.width=textToolTipWidth;                        //Set the tooltiptext format
                          textToolTip.height=textToolTipHeight;
                          textToolTip.background=true;
                          textToolTip.backgroundColor=textToolTipBackGroundColor;
                          textToolTip.border=true;                
                          textToolTip.wordWrap=true;
                          textToolTip.visible=false;                
                          containerInfo.addChild(textToolTip);                                            
                      containerInfo.addChild(descriptionLabel);
                      bitmapLoader();
                          setVideo();
              }
              private function handleComplete( event:Event ):void {                //Handle XML file when loaded
                try {
                        var arrayChars:Array = new Array();                //Here we store the data about the characters
                        var arrayRelations:Array = new Array();                //Here we store the data about the relations among characters
                  trace("Handling XMLoader");
                          var example:XML = new XML( event.target.data );
                          var num:Number=10
                                  trace("Reading Character information");
                          for each (var dataCharacter:XML in example.Nodes.elements()) {
                                          var charData:Object = new Object();
                                  charData.id=dataCharacter.@id;
                                  charData.nameChar=dataCharacter.@name;
                                  charData.imageURL=dataCharacter.@imageURL;
                                  charData.videoURL=dataCharacter.@videoURL;
                                  charData.description=dataCharacter.@description;
                                          arrayChars.push(charData);                        //New charData added to the arrayFigures
                                          trace("Person stored as ID: " +  charData.id + " Name: " + charData.name + " Hops: " + charData.hops + " imageURL: " + charData.imageURL );
                          }
                          for each (var dataRelation:XML in example.Relations.elements()) {
                                  var relation:Relation= new Relation(dataRelation.@fromID, dataRelation.@toID, dataRelation.@relation, dataRelation.@relationExplanation);
                                  arrayRelations.push(relation);           
                                  trace("Relation stored as fromID: " +  relation.getFromID + " toID " + relation.getToID);                                
                          }
                                 var handler:CharacterHandler = new CharacterHandler(arrayChars, arrayRelations, selectedLabel, descriptionLabel, ns, textToolTip);                //Call CharacterHandler Class
                          container.addChild(handler.getContainer());                        //Display the CharacterHandler
                                  stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
                                  stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
                                  stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);                                                
                } 
                catch ( e:TypeError ) {                        //If error
                          trace( "Could not parse text into XML" );
                          trace( e.message );
                }
                trace ("XMLoader handled!");
              }
              private function onMouseDown(ev:Event):void{
                      container.startDrag();
              }
              private function onMouseUp(ev:MouseEvent):void{
                      container.stopDrag();
              }            
                  private function onMouseWheel( event : MouseEvent ) : void {
                          var origenX : Number = event.stageX;
                          var origenY : Number = event.stageY;
                          if( !event.altKey ) {
                                  if( event.delta > 0 ) {
                                          scaleAt(zoomFactor, event.stageX, event.stageY );
                                  } else {
                                          scaleAt((1/zoomFactor), event.stageX, event.stageY );
                                  }
                          }
                  }    
                  public function scaleAt( scale : Number, originX : Number, originY : Number) : void {
                          affineTransform = container.transform.matrix;
                          affineTransform.translate( -originX, -originY );
                          affineTransform.scale( scale, scale );
                          affineTransform.translate( originX, originY );
                          container.transform.matrix=affineTransform;
                  }                    
          }
  }


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.