8 Replies Latest reply on Jan 28, 2010 1:09 PM by mmoorman

    SlideElement for ASM2

    mmoorman

      Hi,

       

      for viewing presentationSlides we use a presentationholder.swf which is written in Flash8. This presentationholder loads some swfs from the AdobeConnect converter. So in order to view i cannot use the SWFElement in OSMF because it doesn't load "Pre AS3 Code". Now i was wondering whether to build my own SlideElement to load this swf and communicate via LocalConnections. The Problem is that the new element isn't shown by the MediaPlayerWrapper.

      I've following Code:

      model.wrapper.element = new SlideElement(url, height, width);
      

      SlideElement:

      package org.osmf.slide
      {
           import flash.display.Sprite;
           import flash.events.Event;
           
           import flurfunk.model.util.Flex2SWFConnector;
           
           import mx.containers.Canvas;
           import mx.controls.SWFLoader;
           
           import org.osmf.events.MediaPlayerCapabilityChangeEvent;
           import org.osmf.media.MediaElement;
           import org.osmf.traits.MediaTraitType;
      
           public class SlideElement extends MediaElement
           {
                private var view:SlideViewTrait;
                private var play:SlidePlayTrait;
      
                private var flex2SWF:Flex2SWFConnector;
      
                private var loader:SWFLoader;
      
                private var url:String;
      
                private function onComplete(event:Event):void
                {
                     var canvas:Sprite = new Sprite();
                     canvas.addChild(loader);
                     view = new SlideViewTrait(canvas, 400, 400);
                     addTrait(MediaTraitType.VIEW, view);
                     flex2SWF = new Flex2SWFConnector();
                     flex2SWF.sendingLC.send(flex2SWF.connectionName_sendingLC, "setLecturesFolder_lc", url);
                     dispatchEvent(new MediaPlayerCapabilityChangeEvent(MediaPlayerCapabilityChangeEvent.VIEWABLE_CHANGE));
      
                     play = new SlidePlayTrait(flex2SWF);
                     addTrait(MediaTraitType.PLAY, play);
                }
      
                public function SlideElement(url:String, 
                     width:Number, 
                     height:Number)
                {
                     super();
                     this.url = url;
                     loader = new SWFLoader();
                     loader.width = 400;
                     loader.height = 400;
                     loader.trustContent = true;
                     loader.load("presentationholder169.swf");
                     loader.addEventListener(Event.COMPLETE, onComplete);
                }
      
           }
      }
      

      SlideViewTrait:

      package org.osmf.slide
      {
           import flash.display.DisplayObject;
           import org.osmf.traits.ViewTrait;
      
           internal class SlideViewTrait extends ViewTrait
           {
                public function SlideViewTrait(view:DisplayObject, mediaWidth:Number=0, mediaHeight:Number=0)
                {
                     super(view, mediaWidth, mediaHeight);
                }
                
                public function setDimensions(mediaWidth:Number, mediaHeight:Number):void
                {
                     setMediaDimensions(mediaWidth, mediaHeight);
                }
                
           }
      }
      

      SlidePlayTrait:

      package org.osmf.slide
      {
           import flash.events.TimerEvent;
           import flash.utils.Timer;
           
           import flurfunk.model.util.Flex2SWFConnector;
           
           import org.osmf.events.PlayEvent;
           import org.osmf.events.TimeEvent;
           import org.osmf.traits.PlayState;
           import org.osmf.traits.PlayTrait;
      
           public class SlidePlayTrait extends PlayTrait
           {
      
                private var _flex2SWF:Flex2SWFConnector;
                private var _duration:Number;
                private var _slideSteps:Array;
                private var _timer:Timer;
                private var _currentSlide:Number = 1;
      
                public function SlidePlayTrait(flex2SWF:Flex2SWFConnector)
                {
                     super();
                     this._flex2SWF = flex2SWF;
                     addEventListener(PlayEvent.PLAY_STATE_CHANGE, onPlayStateChange);
                }
                
                private function onPlayStateChange(event:PlayEvent):void
                {
                     switch(event.playState)
                     {
                          case PlayState.PAUSED  :
                               pauseSlide();
                               break;
                          case PlayState.STOPPED :
                               stopSlide();
                               break;
                          case PlayState.PLAYING :
                               playSlide();
                               break;
                     }
                }
                
                private function playSlide():void
                {
                     if (_timer == null)
                     {
                          //_timer = new Timer((_duration / _slideSteps.length)*1000, _slideSteps.length);
                          _timer = new Timer(5000, 10);
                          _timer.addEventListener(TimerEvent.TIMER_COMPLETE, onSlideComplete);
                          _timer.addEventListener(TimerEvent.TIMER, onNextSlideTimer);
                          _timer.start();
                     }
                     else
                     {
                          _timer.start();
                     }
                }
      
                private function pauseSlide():void
                {
                     _timer.stop();
                }
      
                private function stopSlide():void
                {
                     _timer.stop()
                     _currentSlide = 1;
                     gotoSlide(_currentSlide);
                     _timer = null;
                }
                
                public function nextSlide():void
                {
                     gotoSlide(++_currentSlide);
                }
                
                public function prevSlide():void
                {
                     gotoSlide(--_currentSlide);
                }
      
                private function onSlideComplete(event:TimerEvent):void
                {
                     dispatchEvent(new TimeEvent(TimeEvent.DURATION_REACHED));
                }
      
                private function onNextSlideTimer(event:TimerEvent):void
                {
                     gotoSlide(++_currentSlide);
                }
      
                private function gotoSlide(slide:Number):void
                {
                     try
                     {
                          _flex2SWF.sendingLC.send(_flex2SWF.connectionName_sendingLC,"gotoSlide_lc", slide);
                     }
                     catch (error:ArgumentError)
                     {
                          trace("Error in sendingLC");
                     }
                }
      
           }
      }
      

      All other Elements from OSMF such as VideoElement or ImageElement are properly shown by the wrapper. Maybe there is someone having an advice for this problem.

       

      greetings from cold Germany

      Markus Moormann

        • 1. Re: SlideElement for ASM2
          bringrags Level 4

          I would try:

           

           canvas.addChild(loader.content);

          instead of:

           canvas.addChild(loader);

           

          But it seems like we ought to address the more fundamental problem (that you can't load AS2 SWFs).  We have an open bug on this (FM-66).  I'm curious, if you remove the AS2 check (in ContentLoader's onLoadComplete method, where we check LoaderInfo.actionScriptVersion), does everything work for you?  If so, then perhaps we just need to add an "allowAS2Content" property to ContentLoader so that you can override the default behavior.

          • 2. Re: SlideElement for ASM2
            mmoorman Level 1

            Well, both proposals don't work.

            first one throws the error that an AVM1Movie cannot be converted into an UIComponent. Have also tried to

            push loader.content directly to the ViewTrait than I get following error:

            Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a
            different part of the displayList when it has been loaded into AVM2
            (AS3) content.
            

             

            I get the same error, when I remove the AS2 check in the ContentLoader.

            So the problem is that the movie lying in loader.content cannot be moved. I get a result when I do the following: Remove the AS2 check in ContentLoader so it likes like this

            function onLoadComplete(event:Event):void
            {
                 toggleLoaderListeners(loader, false);     
                 
                 updateLoadTrait(loadTrait, LoadState.READY, loadedContext);     
            }
            

            and replace the following line(103) in ContentElement

            view = context.loader.content;
            

            to

            view = context.loader;
            

            now my swf is loaded and mostly properly shown. mostly because the swf isn't resized correctly, but that maybe my mistake.

            Could you check on this and report if this is a good way and if it really works?

             

            greetings

             

            EDIT:

            The scaling problem still exists. I've hoped that giving the wrapper the correct dimension would cause the correct scaling of the loaded swf, but neither the wrapper nor the swf have correct dimensions after everything is loaded. I've tried putting correct dimensions in DebugMode but that only causes the swf to be so large I only see a part of it on my screen. Has anybody an idea how to solve this? I've put my ContentLoader and ContentElement attached

             

            Message was edited by: mmoorman

            • 3. Re: SlideElement for ASM2
              bringrags Level 4

              And what happens if you wrap loader.content in a UIComponent before assigning to the canvas?

               

              var uic:UIComponent = new UIComponent();

              uic.addChild(loader.content);

              canvas.addChild(uic);

               

              (Note you might need to set explicit width and height on the UIComponent.)

              • 4. Re: SlideElement for ASM2
                mmoorman Level 1

                I had already tried that in the first try but it again just gives the error

                Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a
                different part of the displayList when it has been loaded into AVM2
                (AS3) content.
                

                I've read once about the resizing problem of the Loader class in another forum but I can't find it again. I've just tried to replace the Loader in ContentLoader.as by the mx.control.SWFLoader but I cannot import it. Why? Isn't it a normal FlexProject?

                • 5. Re: SlideElement for ASM2
                  bringrags Level 4

                  No, OSMF has no dependency on Flex, it's a pure AS3 project.

                   

                  I've linked this thread to bug FM-66, so that we can take your case into account when we address it.

                  • 6. Re: SlideElement for ASM2
                    mmoorman Level 1

                    All right.

                    thanks so far

                    • 7. Re: SlideElement for ASM2
                      bringrags Level 4

                      I've applied a fix to the underlying bug (FM-66) in public trunk (revision 1381(.  Can you see if your issue still exists once you have the fix?  You can either sync to public trunk now, or wait for the Sprint 9 release (coming in the next few days).  Thanks!

                      • 8. Re: SlideElement for ASM2
                        mmoorman Level 1

                        Well, as far as I can see, the code you comitted ist nearly the same

                        I've already posted..but appart from that I've tested it and nothing

                        changed. The loaded swf doesn't use the given dimensions, you can test

                        it by using the attached swf and the mediaPlayerWrapper. It is some kind

                        of streched. I think this problem occurrs because the loader and it's

                        content have scaling stuff. Maybe one could have a look at the SWFLoader

                        from Flex Framework how that one is doing the job.

                         

                        greetings

                        Markus Moormann

                         

                        [EDIT]

                        I've browsed through the SWFLoader source in FlexFramework and found a difference. Correct me if I'm wrong: When the Loader has loaded the SWF the DisplayObjectTrait ist created and added to the media. Then the displayObject ist added to stage. When and where is that done?

                        In Flex SWFLoader the loader is added in front of loading: there is following statement in the SWFLoader.as.

                         // addChild needs to be called before load()
                         addChild(loader);
                        

                        I think I've read already about that issue somewhere. Is it possible to add the DisplayObject BEFORE the media is loaded?

                        [/EDIT]