topical media & game development

talk show tell print

hush-video.mx

hush-video.mx [swf] [flash] flex


  <?xml version="1.0" encoding="utf-8"?>
  <mx:Application 
   xmlns:mx="http://www.adobe.com/2006/mxml" 
   paddingLeft="0" paddingTop="0" paddingBottom="0" paddingRight="0"
   width="100%" height="100%"
   horizontalAlign="center" verticalAlign="middle" 
   creationComplete="init()"
  >
  
  

script


   <mx:Script>
    <![CDATA[
     import flash.events.MouseEvent;
    import mx.core.UIComponent;
    
    public var fx:Number = 1.5;
     [Bindable] public var config:String = "@mx-hush-video.xml";
     private var xml:XML;
     private var urlLoader:URLLoader = new URLLoader();
     [Bindable] public var hello:String = "hello (default) world";
     [Bindable] public var message:String = "(default) world";
     [Bindable] public var button:String = "(default) click me!";
     [Bindable] public var source:String = "../assets/clips/tube/balloon.flv";
     [Bindable] public var volume:Number = 0.75;
  
   

variable(s)


     private var item:Sprite;
     [Bindable] private var drawing:Boolean = false;
     [Bindable] private var mode:uint = 0;
     private var beginX:Number = 0;
     private var beginY:Number = 0;
     
     private var hold:UIComponent = null;
  
    private function init():void {
     if (Application.application.parameters.config) {
      config = Application.application.parameters.config;
     }
     urlLoader.addEventListener(Event.COMPLETE,loaded);
     urlLoader.load(new  URLRequest(config));
    }
  
  

loaded


  
     private function loaded(e:Event):void{
     xml =  new XML(e.target.data);
    button = xml..button.@text;
    message = xml..button.@panel;
    hello = xml..button;
    if (xml..video.@source) { video.source = xml..video.@source; }
    if (xml..video.@volume) { video.volume = xml..video.@volume; }
    if (xml..video.@fx) { fx = xml..video.@fx; }
    //note.text = video.source + " " + video.volume + " " + video.height;
  

play & listen


    video.play();
     //trace(xml);
    video.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
     video.addEventListener(MouseEvent.MOUSE_UP, onMouseUp)  
     video.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);   
    //ExternalInterface.call( "jsfun", "init" );
    //ExternalInterface.addCallback( "function1", callback1 );
    //ExternalInterface.addCallback( "function3", callback3 );
    ExternalInterface.addCallback( "drawf", cdraw );
       // callback1();
       // callback1();
     }
  
  

callback(s)


  
  private var count:Number = 0;
  private function callback1() : void
  {
     // note.text = "test function1: " + count++;
  }
  private function callback3(parameter : *) : String
  {
   //note.text = parameter.toString();   
   return "received from mx: "  + parameter.toString();
  }
  
     private function handler ( event:MouseEvent ):void
     {
      //field.text = hello;
     }
  
  

report (ignore)


  private function cdraw(parameter : *) : String
  {
     //note.text = parameter.toString();   
   //return "received from mx: "  + parameter.toString();
        var dir:String = parameter.toString();
        //var fx:Number = 2;
        var dx:Number = 0;
        var dy:Number = 0;
        if (dir == "left") dx = -1;
        if (dir == "right") dx = 1;
        if (dir == "up") dy = -1;
        if (dir == "down") dy = 1;
        dx *= fx; dy *= fx;
        
        item = new Sprite();
        var c:UIComponent = new UIComponent();
        c.addChild(item);
        item.graphics.lineStyle(3, 0x0000FF);
        item.graphics.moveTo(beginX, beginY);
        video.addChild(c);
        beginX += dx; beginY += dy;
        item.graphics.lineTo(beginX, beginY);
        
       //    note.text = parameter.toString() +  " " + dx + " " + dy; 
   
   return "OK";
  }
  
  

mouse down


     private function onMouseDown(event:MouseEvent):void
     {
       drawing = true;
       hold = null;
       beginX = event.localX; beginY = event.localY;
       if (mode == 0) {
        item = new Sprite();
        var c:UIComponent = new UIComponent();
        c.addChild(item);
        item.graphics.lineStyle(3, 0xFF0000);
        item.graphics.moveTo(event.localX, event.localY);
        video.addChild(c);
       }
     }
  

mouse up


        
     private function onMouseUp(event:MouseEvent):void
     {
       drawing = false;
       trace("stop:" + event.localX + "/" + event.localY);
     }
     
  

mouse move


     private function onMouseMove(event:MouseEvent):void
     {
        if (drawing){
        item.graphics.lineTo(event.localX, event.localY);
   
        var dx:Number = event.localX - beginX;
        var dy:Number = event.localY - beginY;
        var dir:String = "none";
        if ((dx <= 0) && (Math.abs(dx) >= Math.abs(dy))) dir = "left";
        if ((dx > 0) && (Math.abs(dx) >= Math.abs(dy))) dir = "right";
        if ((dy <= 0) && (Math.abs(dx) < Math.abs(dy))) dir = "up";
        if ((dy > 0) && (Math.abs(dx) < Math.abs(dy))) dir = "down";
        var value:String = " " + event.localX + " " + event.localY;
       ExternalInterface.call( "jscoord", dir);
       beginX = event.localX;
       beginY = event.localY;
       //note.text = value;
       }   
        trace("move:" // + mouseX + "/" + mouseY + "  :" 
        + event.localX + "/" + event.localY );
     }
  
    ]]>
   </mx:Script>
  
  

end script / start panel


   <!--
   <mx:Panel 
    title="{message}" horizontalAlign="center"
    paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10" 
   >
    <mx:Label id="field" width="180" fontWeight="bold" fontSize="24"/>
    
    <mx:Button label="{button}" click="handler(event);" />
    
   </mx:Panel>
   -->
  

video display


   <mx:VideoDisplay  id="video" height="100%" width="100%" maintainAspectRatio="false" autoPlay="false"/>
  <!--
   <mx:Label id="note" width="400" fontWeight="bold" fontSize="24"/>
  -->
  </mx:Application>
  


(C) Æliens 04/09/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.