1 Reply Latest reply on Jun 7, 2012 7:50 AM by BARRYC16

    How to include an ActionScript based media player in Flex

    broeks

      Hi,

       

      Flex/ AS3 newbie here.

       

      I'm attempting to port/include the flowplayer (http://flowplayer.org) into a flex project.

       

      I've included the .swc file for the player in my flex project. While trying to instantiate the player I'm running into an issue where the player code does not know about what seems to me should be important things (such as the stage) -- they are always coming back as null.

       

       

       

      <?xml version="1.0" encoding="utf-8"?>
      
      <mx:Application 
          xmlns:mx="http://www.adobe.com/2006/mxml"
          xmlns:flowplayerView="org.flowplayer.view.*"
          applicationComplete="init();" 
         
      >
      
      <mx:Script>
           <![CDATA[
                import mx.core.UIComponent;
                
                import org.flowplayer.view.*;
                
                
                public function init(): void
                {     
                     var ui:UIComponent = new UIComponent();
                              var sprite:Sprite = new Sprite();
                              var movieClip:Preloader = new  Preloader();
                              ui.addChild(sprite);
                              ui.addChild(movieClip);
                              myPanel.rawChildren.addChild(ui);
           
                          
                }
           ]]>
      </mx:Script>
      
      <mx:Panel id="myPanel"
              paddingTop="10"
              paddingBottom="10"
              paddingLeft="10"
              paddingRight="10"
              height="300"
              width="600"        
          >
          </mx:Panel>
           
      </mx:Application>
      

       

       

           The goal is to start up this preloader code, which will make the flowplayer go in the same way as if I started it via Javascript. However, the marked items below are always null. What do I need to do to propogate these high level flash system variables into this included code?

       

       

       

      public class Preloader extends MovieClip {
      
                private var _app:DisplayObject;
                private var _percent:TextField;
      
                public function Preloader() {
                  stop();
      // !!null pointer here on loader info
      //
      if (loaderInfo.bytesLoaded == loaderInfo.bytesTotal) {
                       init();
                       return;
                  }
                  _percent = new TextField();
                     var format:TextFormat = new TextFormat();
                     format.font = "Lucida Grande, Lucida Sans Unicode, Bitstream Vera, Verdana, Arial, _sans, _serif";
                     _percent.defaultTextFormat = format;
                     _percent.text = "Loading...";
                  addChild(_percent);
                  addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
                }
                
                private function onAddedToStage(event:Event):void {
                  loaderInfo.addEventListener(ProgressEvent.PROGRESS, onLoadProgress);
                  loaderInfo.addEventListener(Event.COMPLETE, init);
                }
      
                private function onLoadProgress(event:ProgressEvent):void {
                       var percent:Number = Math.floor((event.bytesLoaded*100) / event.bytesTotal);
                  graphics.clear();
                   _percent.text = (percent + "%"); 
                  _percent.x = stage.stageWidth / 2 - _percent.textWidth / 2;
                  _percent.y = stage.stageHeight / 2 - _percent.textHeight / 2;
                   }
             
              private function init(event:Event = null):void {
                   if (_percent) {
                        removeChild(_percent);
                   }
                   nextFrame();
                   prepareStage();
                     var mainClass:Class = Class(getDefinitionByName("org.flowplayer.view.Launcher"));
                  _app = new mainClass() as DisplayObject;
                     addChild(_app as DisplayObject);
              }
      
                private function prepareStage():void {
                     //!!null pointer here on stage
                     stage.align = StageAlign.TOP_LEFT;
                     stage.scaleMode = StageScaleMode.NO_SCALE;
                }
          }