2 Replies Latest reply on Oct 22, 2007 9:43 AM by Nyan_Nami

    Load swf in ImageViewer

    Nyan_Nami
      Hello,
      how can i load a swf in ImageViewer (FIG PanZoom) instead of bitmap data?
      Thanks
        • 1. Re: Load swf in ImageViewer
          Nyan_Nami Level 1
          Hello,
          i'm making some mistake with this.. Can someone please take a look at this change i made of ImageViewer class to load swf files. i'm new in action script.. so please help...
          Thanks!


          package com.adobe.wheelerstreet.fig.panzoom
          {
          import com.adobe.wheelerstreet.fig.panzoom.modes.PanZoomCommandMode;
          import com.adobe.wheelerstreet.fig.panzoom.utils.ContentRectangle;

          import flash.display.Sprite;
          import flash.display.MovieClip;

          import flash.display.BlendMode;
          import flash.display.Loader;
          import flash.events.Event;
          import flash.events.IOErrorEvent;
          import flash.events.ProgressEvent;
          import flash.geom.Matrix;
          import flash.geom.Point;
          import flash.geom.Rectangle;
          import flash.net.URLRequest;

          import mx.controls.Label;
          import mx.controls.SWFLoader;
          import mx.core.UIComponent;
          import mx.effects.AnimateProperty;
          import mx.events.FlexEvent;
          import mx.events.ResizeEvent;
          import mx.events.TweenEvent;


          public class ImageViewer extends UIComponent
          {
          [Bindable]
          public var loadingImage:Boolean = false;
          [Bindable]
          public var mapScaleFactorMin:Number = .125;
          [Bindable]
          public var mapScaleFactorMax:Number = 5;

          private var _panZoomCommandMode:PanZoomCommandMode;
          public var viewRect:Rectangle;
          private var _contentRectangle:ContentRectangle;

          private var _map:Sprite;

          private var _mapScaleFactor:Number;

          private var _smoothBitmap:Boolean = false;

          private var _mapURL:String;
          private var _loader:Loader;
          private var _percentLoadedLabel:Label;

          // preloader assets
          [Embed(source="icons/iconography.swf", symbol="ProgressThrobber")]
          private var _progressThrobber:Class;
          private var _progressSWF:SWFLoader;


          [Bindable]
          public function get mapURL():String
          {
          return _mapURL;
          }
          public function set mapURL(value:String):void
          {
          // setting mapURL triggers loading sequence
          if (value == _mapURL)
          return;

          _loader = new Loader();
          _loader.load(new URLRequest(value));
          loadingImage = true;

          formatUI();

          _percentLoadedLabel.text = "";
          invalidateDisplayList();

          // load events
          _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleLoadComplete);
          _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, handleLoadIOError);
          _loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, handleLoadProgress);

          }
          public function get map():Sprite
          {
          return _map;
          }
          public function set map(value:Sprite):void
          {
          if (value == _map)
          return;
          _map = value;
          _contentRectangle = new ContentRectangle(0,0,_map.width, _map.height, viewRect);

          _panZoomCommandMode = new PanZoomCommandMode(this, _contentRectangle)
          _panZoomCommandMode.activate();

          invalidateDisplayList();
          }


          [Bindable]
          public function get mapScaleFactor():Number
          {
          return _mapScaleFactor;

          }
          public function set mapScaleFactor(value:Number):void
          {
          if (value == mapScaleFactor )
          return;

          if (value < mapScaleFactorMin)
          return;

          if (value > mapScaleFactorMax)
          return;

          _mapScaleFactor = value;
          invalidateDisplayList();
          }

          public function ImageViewer():void
          {
          viewRect = new Rectangle();
          _contentRectangle = new ContentRectangle(0,0,0,0,viewRect);

          addEventListener(ResizeEvent.RESIZE, handleResize);

          addEventListener(FlexEvent.CREATION_COMPLETE, handleCreationComplete);
          function handleCreationComplete(e:FlexEvent):void
          {
          _contentRectangle.zoom = .5;
          mapScaleFactor = _contentRectangle.zoom;
          invalidateDisplayList();
          }
          }

          override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
          {
          super.updateDisplayList(unscaledWidth, unscaledHeight);

          viewRect.width = width;
          viewRect.height = height;

          if (_map == null)
          {
          // if there's no bitmapData fill the component with black
          graphics.beginFill(0x000000,1)
          graphics.drawRect(0,0,unscaledWidth,unscaledHeight);

          } else if (viewRect != null)
          {

          var __mapTransform:Matrix = new Matrix(_contentRectangle.width / _map.width,
          0,
          0,
          _contentRectangle.height / _map.height,
          _contentRectangle.topLeft.x,
          _contentRectangle.topLeft.y
          );

          graphics.clear();
          graphics.beginFill(0x000000, 0.4);
          graphics.drawRect(0,0,unscaledWidth, unscaledHeight);
          }

          private function formatUI():void
          {
          _progressSWF = new SWFLoader();
          _progressSWF.source = _progressThrobber;
          _progressSWF.width = 16;
          _progressSWF.height = 16;
          _progressSWF.x = 40;
          _progressSWF.y = 15;
          addChild(_progressSWF);

          _percentLoadedLabel = new Label();
          _percentLoadedLabel.width = 300;
          _percentLoadedLabel.height = 32;
          _percentLoadedLabel.x = 55;
          _percentLoadedLabel.y = 15;
          _percentLoadedLabel.blendMode = BlendMode.INVERT;
          addChild(_percentLoadedLabel);
          }

          // load handlers
          private function handleLoadComplete(e:Event):void
          {
          /**** maybe here is a bad action script call !? ***/
          map = Sprite(_loader.content);

          removeChild(_progressSWF);
          removeChild(_percentLoadedLabel);

          loadingImage = false;
          _percentLoadedLabel.text = "Complete";
          trace(e.type)
          }

          private function handleLoadIOError(e:Event):void
          {
          removeChild(_progressSWF);
          loadingImage = false;
          _percentLoadedLabel.text = "failed to load image";
          }

          private function handleLoadProgress(e:Event):void
          {
          _percentLoadedLabel.text = String(
          Math.round(
          (ProgressEvent(e).bytesLoaded / ProgressEvent(e).bytesTotal)
          * 100
          ) + "%"
          );
          }
          }
          }
          • 2. Re: Load swf in ImageViewer
            Nyan_Nami Level 1
            Hi,
            in this code i have tried to change a bitmap in Sprite.. Is it ok or it should be a Shape?
            __________________
            private var _map:Sprite;

            and how to load it in the function
            ___________________________
            handleLoadComplete(e:Event):void

            _________
            map = Sprite(_loader.content);


            Is there anyone who can help? Thanks!