2 Replies Latest reply on Dec 17, 2009 5:58 PM by jerryhamby

    Perfect time to capture image size???

    jerryhamby Level 1

      I'm looking for the perfect event to retrieve the width and height of an image that just loaded.

      I need to resize the images before displaying.

       

      I'm getting different readings when I use a regular ImageElement as opposed to wrapping the same ImageElement

      inside a TemporalProxyElement.   The regular works fine and returns the currentTarget width and height,

      the TemporalProxyElement ImageElement  returns zeros for the width and height.

       

      Why the different???

       

      ================================================================================

      ===== code =======

      pImageSerialElement.addChild(new TemporalProxyElement(3, new ImageElement(new ImageLoader(), new URLResource(new URL("./images/image4.jpg")))));

       

      ===== traces =======

      mImageLoadableStateChange evt = [Event type="loadableStateChange" bubbles=false cancelable=false eventPhase=2]

      mImageLoadableStateChange evt.newState = loaded

      Successfully connected!

      pMediaSprite.width =  0

      pMediaSprite.height =  0

      AppMaster.getInstance().pStageWidth =  320

      AppMaster.getInstance().pStageHeight =  480

      mImageLoadableStateChange evt.currentTarget.width =  0

      mImageLoadableStateChange evt.currentTarget.height =  0

       

      =================================================================================

      ===== code =======

      var vImageElement = new ImageElement(new ImageLoader(), new URLResource(new URL( "./images/image4.jpg")));

       

      ===== traces =======

      mImageLoadableStateChange evt = [Event type="loadableStateChange" bubbles=false cancelable=false eventPhase=2]

      mImageLoadableStateChange evt.newState = loaded

      Successfully connected!

      pMediaSprite.width =  300

      pMediaSprite.height =  240

      AppMaster.getInstance().pStageWidth =  320

      AppMaster.getInstance().pStageHeight =  480

      mImageLoadableStateChange evt.currentTarget.width =  600

      mImageLoadableStateChange evt.currentTarget.height =  800

        • 1. Re: Perfect time to capture image size???
          RyanOConnell Level 2

          Could you post your code or file a bug?  It looks like you first example isn't complete, you are using a serial element as well?

           

          Thanks,

          Ryan

           

          Here is a working example:

           

          private static const REMOTE_IMAGE:String = "http://mediapm.edgesuite.net/osmf/image/adobe-lq.png";

           

          private function init():void

          {

          mediaPlayerWrapper.mediaPlayer.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_S TATE_CHANGE, onState);

          mediaPlayerWrapper.element = new TemporalProxyElement(3, new ImageElement(new ImageLoader(), new URLResource(new URL(REMOTE_IMAGE))));

           

          }

           

          private function onState(event:MediaPlayerStateChangeEvent):void

          {

          if(event.state == MediaPlayerState.READY)

          {

          trace('mediaPlayerWrapper.mediaPlayer.height' + mediaPlayerWrapper.mediaPlayer.height);

          trace('mediaPlayerWrapper.mediaPlayer.width' + mediaPlayerWrapper.mediaPlayer.width);

           

          }

          }

          ]]>

          </mx:Script>

          <players:MediaPlayerWrapper id="mediaPlayerWrapper" width="100%" height="100%"/>   

          </mx:Application>

          • 2. Re: Perfect time to capture image size???
            jerryhamby Level 1

            Filed bug: FM-301

             

            I will review your code, to see if I'm missing anything.

             

            My issue is with the:

            LoadableStateChangeEvent.LOADABLE_STATE_CHANGE

             

            Your code deals with it in:

            MediaPlayerStateChangeEvent.MEDI A_PLAYER_STATE_CHANGE

             

            I will give it a shot, but I still think it should work on LoadableStateChangeEvent.

            ImageElement worked fine there without the TemporalProxyElement wrapper.