Adobe Systems, Inc.

SwfClip.as

Go to the documentation of this file.
00001 /****************************************
00002 ** Copyright 2005-2006 Adobe Systems Incorporated
00003 ** Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
00004 ** or a copy at http://opensource.adobe.com/licenses.html)
00005 **
00006 ** SwfClip Class 
00007 ****************************************/
00008 import mx.transitions.*;
00009 import mx.xpath.XPathAPI;
00010 import amg.*;
00011 
00012 class amg.SwfClip extends MovieClip {
00013         //private member properties
00014         private var _xmlImgNode:XMLNode;
00015         public var strUID:String;
00016         private var _strCurrImgRendition:String;
00017         private var _strCurrMediaUrl:String;
00018         public var strThumbUrl:String;
00019         private var _strBaseRefUrl:String = "";
00020         private var _strTitle:String = "";
00021         private var _strCaption:String = "";
00022         private var _aRenditions:Array;
00023         private var _mcPhotoFile:MovieClip;
00024         private var _mcPhotoFrame:MovieClip;
00025         private var _jpegLoader:MovieClipLoader;
00026         private var _smartLoaderCallback:MovieClip;
00027         private var _bAbortFlag:Boolean = false;
00028         private var _iFrameDepth:Number = 10;
00029         private var _iPhotoDepth:Number = 1;
00030         public var iPercentLoaded:Number = 0;
00031         public var _iBorderColor:Number = 0xffffff;
00032         private var _iBorderAlpha:Number = 100;
00033         private var _iBorderWidth:Number = 0;
00034 
00035         //drop shadow 
00036         public var bDropShadows:Boolean = true;
00037         private var _mcThumbBorderBottom:MovieClip;
00038         private var _mcThumbBorderRight:MovieClip;
00039         private var _mcThumbBorderCapTop:MovieClip;
00040         private var _mcThumbBorderCapL:MovieClip;
00041         private var _mcThumbBorderCapR:MovieClip;
00042         
00043         //class constructor
00044         public function SwfClip() {
00045                 this._aRenditions = new Array();
00046         }
00047         
00048         public function initClip(imgNode:XMLNode,borderWidth:Number, borderColor:Number, borderAlpha:Number,dropShadows:Boolean,baseRefUrl:String) {
00049                 this._xmlImgNode = imgNode;
00050                 this.strUID = XPathAPI.selectSingleNode(imgNode,"/item/imageId").attributes.image;
00051                 this._strTitle = XPathAPI.selectSingleNode(imgNode,"/item/title");
00052                 this._strCaption = XPathAPI.selectSingleNode(imgNode,"/item/description");
00053                 this._aRenditions = XPathAPI.selectNodeList(imgNode,"/item/renditions/rendition");
00054                 this._iBorderWidth = borderWidth;
00055                 this._iBorderColor = borderColor;
00056                 this._iBorderAlpha = borderAlpha;
00057                 this.bDropShadows = dropShadows;
00058                 this._strBaseRefUrl = baseRefUrl;
00059                 
00060                 for(var i:Number = 0;i<this._aRenditions.length;i++){
00061                         if(this._aRenditions[i].attributes.size == "thumb"){
00062                                 this.strThumbUrl = this._aRenditions[i].attributes.src;
00063                                 break;
00064                         }
00065                 }
00066                 
00067         }
00068         
00069         //function to load jpeg for the ImageClip obj
00070         public function smartLoadMedia(smartLoader:MovieClip,currImageRendition:String):Void {
00071                 
00072                 this._bAbortFlag = false;
00073                 //create an empty MovieClip for the frame and image
00074                 this._mcPhotoFrame = this.createEmptyMovieClip("frame", _iFrameDepth);
00075                 this._mcPhotoFile = this._mcPhotoFrame.createEmptyMovieClip("photo", _iPhotoDepth);
00076                 this._mcPhotoFile._x = this._mcPhotoFile._y = this._iBorderWidth;
00077                 
00078                         
00079                 this._strCurrImgRendition = currImageRendition;
00080                 for(var i:Number = 0;i<this._aRenditions.length;i++){
00081                         if(this._aRenditions[i].attributes.size == currImageRendition){
00082                                 this._strCurrMediaUrl = this._aRenditions[i].attributes.src;
00083                                 break;
00084                         }
00085                 }
00086         
00087                 //hide the clip until showImage is called
00088                 this._x = -10000;
00089                 this._y = -10000;
00090                 //set the callback for load complete event
00091                 _smartLoaderCallback = smartLoader;
00092                 //create a loader for the jpeg
00093                 this._jpegLoader = new MovieClipLoader();
00094                 //lister for onLoadStart,onLoadProgress,onLoadInit,onloadComplete,onLoadError
00095                 _jpegLoader.addListener(this);
00096                 //load the jpeg into the jpeg movie clip
00097                 this._jpegLoader.loadClip(this._strBaseRefUrl+this._strCurrMediaUrl, this._mcPhotoFile);
00098                 
00099         }
00100         
00101         public function abortLoad():Void {
00102                 this._bAbortFlag = true;
00103         }
00104         
00105         
00106         //called when loading of MediaClip starts
00107         public function onLoadProgress(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
00108                 if (this._bAbortFlag) {
00109                         this._jpegLoader.unloadClip(this._mcPhotoFile);
00110                         this.iPercentLoaded = 0;
00111                 }
00112                 this.iPercentLoaded = (Math.floor(bytesLoaded)/Math.floor(bytesTotal))*100;
00113         }
00114         //called when loading of Jpeg completes
00115         public function onLoadInit(target:MovieClip):Void {
00116                 if (this._bAbortFlag) {
00117                         this.iPercentLoaded = 0;
00118                 }
00119                 else {
00120                         this.iPercentLoaded = 100;
00121                         this.setBorder();
00122                         /*make the image dragable
00123                                 target.onPress = function() {
00124         
00125                                 this.startDrag();
00126                                 };
00127                                 target.onRelease = function() {
00128                                 this.stopDrag();
00129                                 };
00130                         */
00131                         //media load complete; call smartLoader load next object
00132                         _smartLoaderCallback.smartLoader();
00133                 }
00134         }
00135         public function moveMedia(xpos:Number, ypos:Number):Void {
00136                 this._x = xpos;
00137                 this._y = ypos;
00138         }
00139         
00140         public function scaleMedia(scalar:Number):Void {
00141                 this._xscale = this._yscale =  scalar;
00142         }
00143         
00144         public function transitionMedia(xpos:Number, ypos:Number, transitionType:String, dir:String, dur:Number):Void {
00145 
00146                 var whichDir:Number;
00147                 //the transition direction: 0 in, 1 out
00148                 switch (dir) {
00149                 case "in" :
00150                         this._x = xpos;
00151                         this._y = ypos;
00152                         whichDir = 0;
00153                         break;
00154                 case "out" :
00155                         whichDir = 1;
00156                         break;
00157                 }
00158                 
00159                 switch (transitionType) {
00160                         case "blinds" :
00161                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Blinds, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00162                                 break;
00163                         case "fade" :
00164                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Fade, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00165                                 break;
00166                         case "fly" :
00167                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Fly, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00168                                 break;
00169                         case "iris" :
00170                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Iris, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00171                                 break;
00172                         case "photo" :
00173                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Photo, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00174                                 break;
00175                         case "pixDissolve" :
00176                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.PixelDissolve, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00177                                 break;
00178                         case "rotate" :
00179                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Rotate, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00180                                 break;
00181                         case "squeeze" :
00182                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Squeeze, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00183                                 break;
00184                         case "wipe" :
00185                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Wipe, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, startPoint:8});
00186                                 break;
00187                         case "zoom" :
00188                                 TransitionManager.start(this._mcPhotoFrame, {type:mx.transitions.Zoom, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00189                                 break;
00190                         case "keyhole" :
00191                                 TransitionManager.start(this._mcPhotoFrame, {type:amg.Transitions.KeyHole, direction:whichDir, duration:dur, easing:mx.transitions.easing.None.easeNone, xSections:10, ySections:10});
00192                                 break;
00193                         case "cut" :
00194                                 if(dir == "out")
00195                                         this._x = -10000;
00196                                 break;
00197                 }
00198         }
00199                 //function to draw colored border around thumbnail
00200         public function setBorder():Void {
00201                 
00202                 this.clear();
00203                 this._mcPhotoFrame.clear();
00204                 
00205                 this._mcThumbBorderCapTop = this._mcPhotoFrame.attachMovie("mcThumbBorderCapTop","topcap",15);
00206                 this._mcThumbBorderRight = this._mcPhotoFrame.attachMovie("mcThumbBorderRight","right_border",14);
00207                 this._mcThumbBorderBottom = this._mcPhotoFrame.attachMovie("mcThumbBorderBottom","bot_border",13);
00208                 this._mcThumbBorderCapL = this._mcPhotoFrame.attachMovie("mcThumbBorderCapL","leftcap",12);
00209                 this._mcThumbBorderCapR = this._mcPhotoFrame.attachMovie("mcThumbBorderCapR","rightcap",11);
00210                 
00211                 //draw a top border around thumbnail
00212                 this._mcPhotoFrame.beginFill(this._iBorderColor, _iBorderAlpha);
00213                 this._mcPhotoFrame.moveTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y);
00214                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width+this._iBorderWidth, this._mcPhotoFile._y);
00215                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width+this._iBorderWidth, this._mcPhotoFile._y-this._iBorderWidth);
00216                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y-this._iBorderWidth);
00217                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y);
00218                 this._mcPhotoFrame.endFill();
00219                 //bottom border
00220                 this._mcPhotoFrame.beginFill(this._iBorderColor, _iBorderAlpha);
00221                 this._mcPhotoFrame.moveTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y+this._mcPhotoFile._height);
00222                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width+this._iBorderWidth, this._mcPhotoFile._y+this._mcPhotoFile._height);
00223                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width+this._iBorderWidth, this._mcPhotoFile._y+this._mcPhotoFile._height+this._iBorderWidth);
00224                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y+this._mcPhotoFile._height+this._iBorderWidth);
00225                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y+this._mcPhotoFile._height);
00226                 this._mcPhotoFrame.endFill();
00227                 
00228                 //right border
00229                 this._mcPhotoFrame.beginFill(this._iBorderColor, _iBorderAlpha);
00230                 this._mcPhotoFrame.moveTo(this._mcPhotoFile._x+this._mcPhotoFile._width, this._mcPhotoFile._y);
00231                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width+this._iBorderWidth, this._mcPhotoFile._y);
00232                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width+this._iBorderWidth, this._mcPhotoFile._y+this._mcPhotoFile._height);
00233                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width, this._mcPhotoFile._y+this._mcPhotoFile._height);
00234                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x+this._mcPhotoFile._width, this._mcPhotoFile._y);
00235                 this._mcPhotoFrame.endFill();
00236                 
00237                 //left border
00238                 this._mcPhotoFrame.beginFill(this._iBorderColor, _iBorderAlpha);
00239                 this._mcPhotoFrame.moveTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y);
00240                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x, this._mcPhotoFile._y);
00241                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x, this._mcPhotoFile._y+this._mcPhotoFile._height);
00242                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y+this._mcPhotoFile._height);
00243                 this._mcPhotoFrame.lineTo(this._mcPhotoFile._x-this._iBorderWidth, this._mcPhotoFile._y);
00244                 this._mcPhotoFrame.endFill();
00245         
00246                 //ActionScript DropShadows slow down rendering too much so we are going with movieclip approach
00247                 //[distance:Number], [angle:Number], [color:Number], [alpha:Number], [blurX:Number], [blurY:Number], [strength:Number], [quality:Number], [inner:Boolean], [knockout:Boolean], [hideObject:Boolean]
00248                 //var dropShadow:DropShadowFilter = new DropShadowFilter(5, 45, 0x000000, 0.5, 5, 5, 1, 3); 
00249                 //this._mcPhotoFrame.filters = [dropShadow];
00250                 
00251                 if(bDropShadows){
00252                         this._mcThumbBorderCapTop._visible = true;
00253                         this._mcThumbBorderRight._visible = true;
00254                         this._mcThumbBorderBottom._visible = true;
00255                         this._mcThumbBorderCapL._visible = true;
00256                         this._mcThumbBorderCapR._visible = true;
00257                         //set bottom dropshadow 
00258                         var tWidth:Number = this._mcPhotoFile._width+(2*this._iBorderWidth);
00259                         this._mcThumbBorderCapL._x = this._mcPhotoFile._x-this._iBorderWidth;
00260                         this._mcThumbBorderBottom._x = this._mcThumbBorderCapL._x + this._mcThumbBorderCapL._width;
00261                         this._mcThumbBorderBottom._y = this._mcThumbBorderCapL._y = this._mcThumbBorderCapR._y = this._mcPhotoFile._height+this._mcPhotoFile._y+this._iBorderWidth;
00262                         this._mcThumbBorderBottom._width = tWidth - this._mcThumbBorderCapL._width;
00263                         this._mcThumbBorderCapR._x = this._mcThumbBorderBottom._x + this._mcThumbBorderBottom._width;
00264                         
00265                         //right dropshadow
00266                         this._mcThumbBorderCapTop._x = this._mcThumbBorderRight._x = this._mcPhotoFile._x+this._mcPhotoFile._width+this._iBorderWidth;
00267                         this._mcThumbBorderCapTop._y = this._mcPhotoFile._y - this._iBorderWidth;
00268                         this._mcThumbBorderRight._y = this._mcPhotoFile._y - this._iBorderWidth + this._mcThumbBorderCapTop._height;
00269                         this._mcThumbBorderRight._height = this._mcPhotoFile._height + (this._iBorderWidth*2) - this._mcThumbBorderCapR._height;
00270                 }
00271                 else {
00272                         this._mcThumbBorderCapTop._visible = false;
00273                         this._mcThumbBorderRight._visible = false;
00274                         this._mcThumbBorderBottom._visible = false;
00275                         this._mcThumbBorderCapL._visible = false;
00276                         this._mcThumbBorderCapR._visible = false;
00277                 }
00278                 
00279                 
00280 
00281                 
00282         }
00283         //accessors
00284         public function get x():Number {
00285                 return this._mcPhotoFile._x;
00286         }
00287         public function set x(newxpos:Number):Void {
00288                 this._mcPhotoFile._x = newxpos;
00289         }
00290         public function get y():Number {
00291                 return this._mcPhotoFile._y;
00292         }
00293         public function set y(newypos:Number):Void {
00294                 this._mcPhotoFile._y = newypos;
00295         }
00296         public function get width():Number {
00297                 var w:Number = this._mcPhotoFile._width + (this._iBorderWidth*2);
00298                 if(this.bDropShadows)
00299                         w += 4;
00300                 return w; 
00301         }
00302         public function get height():Number {
00303                 var h:Number = this._mcPhotoFile._height + (this._iBorderWidth*2);
00304                 if(this.bDropShadows)
00305                         h += 4;
00306                 return h; 
00307         }
00308 }

Copyright © 2006 Adobe Systems Incorporated.

Use of this website signifies your agreement to the Terms of Use and Online Privacy Policy.