You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Alex Harui <ah...@adobe.com> on 2013/02/08 05:18:25 UTC

Re: svn commit: r1443817 - /flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/BitmapImageGate.as

Hi Nick,

Just being picky but...

1) I'd never heard of this one before.  I looked it up on Dan's blog and saw
that Campos said it can be done with ContentCache.  If that's true, why do
we need this one?

2) Why separate assetXXX properties vs using MultiDPIBitmapSource?

3) Also, are you planning to reorganize the code closer to our "standard"?
I noticed that all setters are together and getters are somewhere else, and
for sure, there should be ASDoc before the class that explains what it is.

4) Finally, is there a reason Dan didn't donate this himself?  I'm wondering
if we need some paper trail where Dan gives you permission to do the
donation.  Maybe forward an email from him to the dev list?

Thanks,
-Alex

On 2/7/13 5:32 PM, "quetwo@apache.org" <qu...@apache.org> wrote:

> Author: quetwo
> Date: Fri Feb  8 01:32:25 2013
> New Revision: 1443817
> 
> URL: http://svn.apache.org/r1443817
> Log:
> Refactoring ImageGate, preparing for mustella tests
> 
> Added:
>     
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> mapImageGate.as
> 
> Added: 
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> mapImageGate.as
> URL: 
> http://svn.apache.org/viewvc/flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/
> src/org/apache/components/BitmapImageGate.as?rev=1443817&view=auto
> ==============================================================================
> --- 
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> mapImageGate.as (added)
> +++ 
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> mapImageGate.as Fri Feb  8 01:32:25 2013
> @@ -0,0 +1,301 @@
> +/////////////////////////////////////////////////////////////////////////////
> ///
> +//
> +//  Licensed to the Apache Software Foundation (ASF) under one or more
> +//  contributor license agreements.  See the NOTICE file distributed with
> +//  this work for additional information regarding copyright ownership.
> +//  The ASF licenses this file to You under the Apache License, Version 2.0
> +//  (the "License"); you may not use this file except in compliance with
> +//  the License.  You may obtain a copy of the License at
> +//
> +//      http://www.apache.org/licenses/LICENSE-2.0
> +//
> +//  Unless required by applicable law or agreed to in writing, software
> +//  distributed under the License is distributed on an "AS IS" BASIS,
> +//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> +//  See the License for the specific language governing permissions and
> +//  limitations under the License.
> +//
> +/////////////////////////////////////////////////////////////////////////////
> ///
> +// Original component created by Dan Florio (http://www.polygeek.com), and
> donated
> +// via Nick Kwiatkowski (quetwo) to the Apache Flex Project
> +/////////////////////////////////////////////////////////////////////////////
> ///
> +
> +package org.apache.components
> +{
> +
> + import flash.display.Bitmap;
> + import flash.display.Loader;
> + import flash.events.Event;
> + import flash.events.IOErrorEvent;
> + import flash.filesystem.File;
> + import flash.filesystem.FileMode;
> + import flash.filesystem.FileStream;
> + import flash.net.URLLoader;
> + import flash.net.URLLoaderDataFormat;
> + import flash.net.URLRequest;
> + import flash.system.Capabilities;
> + import flash.utils.ByteArray;
> +
> + import spark.primitives.BitmapImage;
> +
> + public class BitmapImageGate extends BitmapImage
> + {
> +  private var _urlRequest:URLRequest;
> +  private var _urlLoader:URLLoader;
> +  private var _loader:Loader;
> +  private var _fileStream:FileStream;
> +
> +  private var _url:String;
> +  private var _filename:String;
> +  private var _file:File;
> +
> +  private var _assetURLallDPI:String;
> +  private var _assetURL160:String;
> +  private var _assetURL240:String;
> +  private var _assetURL320:String;
> +
> +  private var _cacheFolder:String = "imageCache";
> +
> +  public function BitmapImageGate()
> +  {
> +   super();
> +  }
> +
> +  private function findImage():void
> +  {
> +
> +   /**
> +    *     The _cacheFolder must be set in order to proceed.
> +    */
> +   if (_cacheFolder == null)
> +   {
> +    return;
> +   }
> +
> +   var gotAllMultiScreenURLs:Boolean = false;
> +
> +   if (_assetURL160 != null
> +     && _assetURL240 != null
> +     && _assetURL320 != null)
> +   {
> +
> +    gotAllMultiScreenURLs = true;
> +   }
> +
> +   /**
> +    *     If we don't have either of the _assetURL or all of the
> +    *     multi-screen URLs then we can not proceed.
> +    */
> +   if (_assetURLallDPI == null && !gotAllMultiScreenURLs)
> +   {
> +    return
> +   }
> +
> +   if (_assetURLallDPI == '')
> +   {
> +    return
> +   }
> +
> +   /**
> +    * Check to see what the _url is going to be for this particular image.
> +    *  -If _assetURL != null then use that url.
> +    *  -Otherwise find the correct _url based on the current screen
> resolution.
> +    */
> +
> +   if (_assetURLallDPI != null)
> +   {
> +    _url = _assetURLallDPI;
> +   }
> +   else if (Capabilities.screenDPI >= 280)
> +   {
> +    _url = _assetURL320
> +   }
> +   else if (Capabilities.screenDPI >= 200)
> +   {
> +    _url = _assetURL240
> +   }
> +   else
> +   {
> +    _url = _assetURL160
> +   }
> +
> +   _filename = _url.substring(_url.lastIndexOf('/') + 1);
> +
> +   if (Capabilities.os.toLowerCase().indexOf('iphone') != -1 ||
> Capabilities.os.toLowerCase().indexOf('ipad') != -1 ||
> Capabilities.os.toLowerCase().indexOf('ipod') != -1)
> +   {
> +    // Store the downloaded files in the Cache directory on iOS devices only.
> This is to comply with the
> +    // new AppStore guidelines that are in effect as of iOS 5.1
> +    _file = new File(File.applicationDirectory.nativePath +
> "/\.\./Library/Caches").resolvePath(_cacheFolder + '/' + _filename);
> +   }
> +   else
> +   {
> +    // Store the downloaded files in the applicationStorage Directory.
> +    _file = File.applicationStorageDirectory.resolvePath(_cacheFolder + '/' +
> _filename);
> +   }
> +
> +   if (_file.exists)
> +   {
> +    var byteArray:ByteArray = new ByteArray();
> +    _fileStream = new FileStream();
> +    _fileStream.open(_file, FileMode.READ);
> +    _fileStream.readBytes(byteArray);
> +    _fileStream.close();
> +    _fileStream = null;
> +    _file = null;
> +
> +    _loader = new Loader();
> +    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> onBytesLoaded);
> +    _loader.loadBytes(byteArray);
> +
> +   }
> +   else
> +   {
> +    downloadRemoteFile();
> +   }
> +  }
> +
> +  private function onBytesLoaded(e:Event):void
> +  {
> +   this.source = new Bitmap(e.target.content.bitmapData);
> +   _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,
> onBytesLoaded);
> +
> +   // Cleanup
> +   _loader = null;
> +   _filename = null;
> +  }
> +
> +
> +  private function downloadRemoteFile():void
> +  {
> +   _urlLoader = new URLLoader();
> +   _urlRequest = new URLRequest(_url);
> +   _urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
> +   _urlLoader.addEventListener(Event.COMPLETE, onDownloadComplete);
> +   _urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOerror);
> +   _urlLoader.load(_urlRequest);
> +  }
> +
> +  private function onDownloadComplete(e:Event):void
> +  {
> +   var byteArray:ByteArray = _urlLoader.data;
> +   _fileStream = new FileStream();
> +   _fileStream.open(_file, FileMode.WRITE);
> +   _fileStream.writeBytes(byteArray, 0, byteArray.length);
> +   _fileStream.close();
> +
> +   _loader = new Loader();
> +   _loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBytesLoaded);
> +   _loader.loadBytes(byteArray);
> +
> +   cleanupAfterDownload();
> +  }
> +
> +  private function onIOerror(e:IOErrorEvent):void
> +  {
> +   throw("image download error : " + _url + " : " + _filename);
> +   cleanupAfterDownload();
> +  }
> +
> +  private function cleanupAfterDownload():void
> +  {
> +   _urlLoader.close();
> +   _urlLoader = null;
> +   _fileStream = null;
> +   _urlRequest = null;
> +   _url = null;
> +  }
> +
> +  /* ************************************************************
> +   * Setters
> +   * ************************************************************ */
> +  override public function set source(value:Object):void
> +  {
> +   //super.source = value;
> +   if (_assetURLallDPI != value)
> +   {
> +    _assetURLallDPI = String(value);
> +    findImage();
> +   }
> +  }
> +
> +  public function setMultiDPIsource(value:String, dpi:Number = 0):void
> +  {
> +   if (dpi == 0)
> +   {
> +    source = value;
> +   }
> +   if (dpi > 280)
> +   {
> +    _assetURL160 = value;
> +    findImage();
> +    return;
> +   }
> +   if (dpi > 200)
> +   {
> +    _assetURL240 = value;
> +    findImage();
> +    return;
> +   }
> +   if (dpi <= 200)
> +   {
> +    _assetURL160 = value;
> +    findImage();
> +   }
> +  }
> +
> +  public function set cacheFolder(value:String):void
> +  {
> +   if (_cacheFolder == value)
> +   {
> +    return;
> +   }
> +   _cacheFolder = value;
> +   findImage();
> +  }
> +
> +  /* ************************************************************
> +   * Getters
> +   * ************************************************************ */
> +
> +  public function get cacheFolder():String
> +  {
> +   return _cacheFolder;
> +  }
> +
> +  public function getMultiDPIsource(dpi:Number = 0):String
> +  {
> +   if (dpi == 0)
> +   {
> +    return _assetURLallDPI;
> +   }
> +   if (dpi > 280)
> +   {
> +    return _assetURL320;
> +   }
> +   if (dpi > 200)
> +   {
> +    return _assetURL240;
> +   }
> +   return _assetURL160;
> +  }
> +
> +  [Inspectable(category="General")]
> +  [Bindable("sourceChanged")]
> +  override public function get source():Object
> +  {
> +   if ((Capabilities.screenDPI > 280 )&&(_assetURL320 != null))
> +   {
> +    return _assetURL320;
> +   }
> +   if ((Capabilities.screenDPI > 200 )&&(_assetURL240 != null))
> +   {
> +    return _assetURL240;
> +   }
> +   if ((Capabilities.screenDPI <= 200 )&&(_assetURL160 != null))
> +   {
> +    return _assetURL160;
> +   }
> +   return _assetURLallDPI;
> +  }
> + }
> +}
> 
> 

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: svn commit: r1443817 - /flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/BitmapImageGate.as

Posted by Alex Harui <ah...@adobe.com>.


On 2/7/13 9:13 PM, "Nicholas Kwiatkowski" <ni...@spoon.as> wrote:

> On Thu, Feb 7, 2013 at 11:18 PM, Alex Harui <ah...@adobe.com> wrote:
> 
>> Hi Nick,
>> 
>> Just being picky but...
>> 
>> 1) I'd never heard of this one before.  I looked it up on Dan's blog and
>> saw
>> that Campos said it can be done with ContentCache.  If that's true, why do
>> we need this one?
>> 
> 
> ContentCache and ImageGate have slightly different purposes (and can be
> used together).  ContentCache will cache items in memory once they've been
> loaded from the network or disk.  ImageGate will cache items from the
> network on disk so you don't have to rely on the network to get them after
> the first time.  This is mostly useful for mobile applications (in fact,
> Dan's orgional implementation was mobile specific), where you load images
> from a remote server.  I'm in the process of making it much more generic.
>  I've also enhanced the component a bit to actually store the cached items
> to disk in the proper directory on iOS so that Apple won't reject any apps
> made with it.
Isn't ContentCache replaceable?  Then you could create an alternate
ContentCache that stores images locally instead of needing a whole new
component?  Sometimes I think these components get created because Adobe
didn't document something properly.
> 
> 
>> 
>> 2) Why separate assetXXX properties vs using MultiDPIBitmapSource?
>> 
> 
> I'm still working on it -- and will probably go that direction.  My thought
> was to make this a direct drop-in replacement for BitmapImage or Image
> (depending on the use case).  MultiDPIBitmapSouce requires multiple DPIs to
> be specified, which I'd like to make optional.
MultiDPIBS has some fallback logic if the URL for a DPI is unspecified.
> 
> 
>> 4) Finally, is there a reason Dan didn't donate this himself?  I'm
>> wondering
>> if we need some paper trail where Dan gives you permission to do the
>> donation.  Maybe forward an email from him to the dev list?
>> 
>> 
> I believe a copy was sent in back in September when I first committed it to
> my whiteboard.  He wasn't interested in committing it himself, but did
> release the code as a compatible license.
Even if the license is compatible, Apache generally doesn't want to take
stuff w/o permission.  We need to understand if his copyright needs to go in
NOTICES or not.  I'll try to remember to look for the email tomorrow.
September is archived on another computer.

-- 
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui


Re: svn commit: r1443817 - /flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/BitmapImageGate.as

Posted by Nicholas Kwiatkowski <ni...@spoon.as>.
On Thu, Feb 7, 2013 at 11:18 PM, Alex Harui <ah...@adobe.com> wrote:

> Hi Nick,
>
> Just being picky but...
>
> 1) I'd never heard of this one before.  I looked it up on Dan's blog and
> saw
> that Campos said it can be done with ContentCache.  If that's true, why do
> we need this one?
>

ContentCache and ImageGate have slightly different purposes (and can be
used together).  ContentCache will cache items in memory once they've been
loaded from the network or disk.  ImageGate will cache items from the
network on disk so you don't have to rely on the network to get them after
the first time.  This is mostly useful for mobile applications (in fact,
Dan's orgional implementation was mobile specific), where you load images
from a remote server.  I'm in the process of making it much more generic.
 I've also enhanced the component a bit to actually store the cached items
to disk in the proper directory on iOS so that Apple won't reject any apps
made with it.


>
> 2) Why separate assetXXX properties vs using MultiDPIBitmapSource?
>

I'm still working on it -- and will probably go that direction.  My thought
was to make this a direct drop-in replacement for BitmapImage or Image
(depending on the use case).  MultiDPIBitmapSouce requires multiple DPIs to
be specified, which I'd like to make optional.


>
> 3) Also, are you planning to reorganize the code closer to our "standard"?
> I noticed that all setters are together and getters are somewhere else, and
> for sure, there should be ASDoc before the class that explains what it is.
>
>
This is why it is still in my whiteboard :)  Haven't gotten that far yet :)



> 4) Finally, is there a reason Dan didn't donate this himself?  I'm
> wondering
> if we need some paper trail where Dan gives you permission to do the
> donation.  Maybe forward an email from him to the dev list?
>
>
I believe a copy was sent in back in September when I first committed it to
my whiteboard.  He wasn't interested in committing it himself, but did
release the code as a compatible license.




> Thanks,
> -Alex
>
> On 2/7/13 5:32 PM, "quetwo@apache.org" <qu...@apache.org> wrote:
>
> > Author: quetwo
> > Date: Fri Feb  8 01:32:25 2013
> > New Revision: 1443817
> >
> > URL: http://svn.apache.org/r1443817
> > Log:
> > Refactoring ImageGate, preparing for mustella tests
> >
> > Added:
> >
> >
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> > mapImageGate.as
> >
> > Added:
> >
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> > mapImageGate.as
> > URL:
> >
> http://svn.apache.org/viewvc/flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/
> > src/org/apache/components/BitmapImageGate.as?rev=1443817&view=auto
> >
> ==============================================================================
> > ---
> >
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> > mapImageGate.as (added)
> > +++
> >
> flex/whiteboard/quetwo/ImageGate/trunk/ImageGate/src/org/apache/components/Bit
> > mapImageGate.as Fri Feb  8 01:32:25 2013
> > @@ -0,0 +1,301 @@
> >
> +/////////////////////////////////////////////////////////////////////////////
> > ///
> > +//
> > +//  Licensed to the Apache Software Foundation (ASF) under one or more
> > +//  contributor license agreements.  See the NOTICE file distributed
> with
> > +//  this work for additional information regarding copyright ownership.
> > +//  The ASF licenses this file to You under the Apache License, Version
> 2.0
> > +//  (the "License"); you may not use this file except in compliance with
> > +//  the License.  You may obtain a copy of the License at
> > +//
> > +//      http://www.apache.org/licenses/LICENSE-2.0
> > +//
> > +//  Unless required by applicable law or agreed to in writing, software
> > +//  distributed under the License is distributed on an "AS IS" BASIS,
> > +//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
> implied.
> > +//  See the License for the specific language governing permissions and
> > +//  limitations under the License.
> > +//
> >
> +/////////////////////////////////////////////////////////////////////////////
> > ///
> > +// Original component created by Dan Florio (http://www.polygeek.com),
> and
> > donated
> > +// via Nick Kwiatkowski (quetwo) to the Apache Flex Project
> >
> +/////////////////////////////////////////////////////////////////////////////
> > ///
> > +
> > +package org.apache.components
> > +{
> > +
> > + import flash.display.Bitmap;
> > + import flash.display.Loader;
> > + import flash.events.Event;
> > + import flash.events.IOErrorEvent;
> > + import flash.filesystem.File;
> > + import flash.filesystem.FileMode;
> > + import flash.filesystem.FileStream;
> > + import flash.net.URLLoader;
> > + import flash.net.URLLoaderDataFormat;
> > + import flash.net.URLRequest;
> > + import flash.system.Capabilities;
> > + import flash.utils.ByteArray;
> > +
> > + import spark.primitives.BitmapImage;
> > +
> > + public class BitmapImageGate extends BitmapImage
> > + {
> > +  private var _urlRequest:URLRequest;
> > +  private var _urlLoader:URLLoader;
> > +  private var _loader:Loader;
> > +  private var _fileStream:FileStream;
> > +
> > +  private var _url:String;
> > +  private var _filename:String;
> > +  private var _file:File;
> > +
> > +  private var _assetURLallDPI:String;
> > +  private var _assetURL160:String;
> > +  private var _assetURL240:String;
> > +  private var _assetURL320:String;
> > +
> > +  private var _cacheFolder:String = "imageCache";
> > +
> > +  public function BitmapImageGate()
> > +  {
> > +   super();
> > +  }
> > +
> > +  private function findImage():void
> > +  {
> > +
> > +   /**
> > +    *     The _cacheFolder must be set in order to proceed.
> > +    */
> > +   if (_cacheFolder == null)
> > +   {
> > +    return;
> > +   }
> > +
> > +   var gotAllMultiScreenURLs:Boolean = false;
> > +
> > +   if (_assetURL160 != null
> > +     && _assetURL240 != null
> > +     && _assetURL320 != null)
> > +   {
> > +
> > +    gotAllMultiScreenURLs = true;
> > +   }
> > +
> > +   /**
> > +    *     If we don't have either of the _assetURL or all of the
> > +    *     multi-screen URLs then we can not proceed.
> > +    */
> > +   if (_assetURLallDPI == null && !gotAllMultiScreenURLs)
> > +   {
> > +    return
> > +   }
> > +
> > +   if (_assetURLallDPI == '')
> > +   {
> > +    return
> > +   }
> > +
> > +   /**
> > +    * Check to see what the _url is going to be for this particular
> image.
> > +    *  -If _assetURL != null then use that url.
> > +    *  -Otherwise find the correct _url based on the current screen
> > resolution.
> > +    */
> > +
> > +   if (_assetURLallDPI != null)
> > +   {
> > +    _url = _assetURLallDPI;
> > +   }
> > +   else if (Capabilities.screenDPI >= 280)
> > +   {
> > +    _url = _assetURL320
> > +   }
> > +   else if (Capabilities.screenDPI >= 200)
> > +   {
> > +    _url = _assetURL240
> > +   }
> > +   else
> > +   {
> > +    _url = _assetURL160
> > +   }
> > +
> > +   _filename = _url.substring(_url.lastIndexOf('/') + 1);
> > +
> > +   if (Capabilities.os.toLowerCase().indexOf('iphone') != -1 ||
> > Capabilities.os.toLowerCase().indexOf('ipad') != -1 ||
> > Capabilities.os.toLowerCase().indexOf('ipod') != -1)
> > +   {
> > +    // Store the downloaded files in the Cache directory on iOS devices
> only.
> > This is to comply with the
> > +    // new AppStore guidelines that are in effect as of iOS 5.1
> > +    _file = new File(File.applicationDirectory.nativePath +
> > "/\.\./Library/Caches").resolvePath(_cacheFolder + '/' + _filename);
> > +   }
> > +   else
> > +   {
> > +    // Store the downloaded files in the applicationStorage Directory.
> > +    _file = File.applicationStorageDirectory.resolvePath(_cacheFolder +
> '/' +
> > _filename);
> > +   }
> > +
> > +   if (_file.exists)
> > +   {
> > +    var byteArray:ByteArray = new ByteArray();
> > +    _fileStream = new FileStream();
> > +    _fileStream.open(_file, FileMode.READ);
> > +    _fileStream.readBytes(byteArray);
> > +    _fileStream.close();
> > +    _fileStream = null;
> > +    _file = null;
> > +
> > +    _loader = new Loader();
> > +    _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> > onBytesLoaded);
> > +    _loader.loadBytes(byteArray);
> > +
> > +   }
> > +   else
> > +   {
> > +    downloadRemoteFile();
> > +   }
> > +  }
> > +
> > +  private function onBytesLoaded(e:Event):void
> > +  {
> > +   this.source = new Bitmap(e.target.content.bitmapData);
> > +   _loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,
> > onBytesLoaded);
> > +
> > +   // Cleanup
> > +   _loader = null;
> > +   _filename = null;
> > +  }
> > +
> > +
> > +  private function downloadRemoteFile():void
> > +  {
> > +   _urlLoader = new URLLoader();
> > +   _urlRequest = new URLRequest(_url);
> > +   _urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
> > +   _urlLoader.addEventListener(Event.COMPLETE, onDownloadComplete);
> > +   _urlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOerror);
> > +   _urlLoader.load(_urlRequest);
> > +  }
> > +
> > +  private function onDownloadComplete(e:Event):void
> > +  {
> > +   var byteArray:ByteArray = _urlLoader.data;
> > +   _fileStream = new FileStream();
> > +   _fileStream.open(_file, FileMode.WRITE);
> > +   _fileStream.writeBytes(byteArray, 0, byteArray.length);
> > +   _fileStream.close();
> > +
> > +   _loader = new Loader();
> > +   _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
> onBytesLoaded);
> > +   _loader.loadBytes(byteArray);
> > +
> > +   cleanupAfterDownload();
> > +  }
> > +
> > +  private function onIOerror(e:IOErrorEvent):void
> > +  {
> > +   throw("image download error : " + _url + " : " + _filename);
> > +   cleanupAfterDownload();
> > +  }
> > +
> > +  private function cleanupAfterDownload():void
> > +  {
> > +   _urlLoader.close();
> > +   _urlLoader = null;
> > +   _fileStream = null;
> > +   _urlRequest = null;
> > +   _url = null;
> > +  }
> > +
> > +  /* ************************************************************
> > +   * Setters
> > +   * ************************************************************ */
> > +  override public function set source(value:Object):void
> > +  {
> > +   //super.source = value;
> > +   if (_assetURLallDPI != value)
> > +   {
> > +    _assetURLallDPI = String(value);
> > +    findImage();
> > +   }
> > +  }
> > +
> > +  public function setMultiDPIsource(value:String, dpi:Number = 0):void
> > +  {
> > +   if (dpi == 0)
> > +   {
> > +    source = value;
> > +   }
> > +   if (dpi > 280)
> > +   {
> > +    _assetURL160 = value;
> > +    findImage();
> > +    return;
> > +   }
> > +   if (dpi > 200)
> > +   {
> > +    _assetURL240 = value;
> > +    findImage();
> > +    return;
> > +   }
> > +   if (dpi <= 200)
> > +   {
> > +    _assetURL160 = value;
> > +    findImage();
> > +   }
> > +  }
> > +
> > +  public function set cacheFolder(value:String):void
> > +  {
> > +   if (_cacheFolder == value)
> > +   {
> > +    return;
> > +   }
> > +   _cacheFolder = value;
> > +   findImage();
> > +  }
> > +
> > +  /* ************************************************************
> > +   * Getters
> > +   * ************************************************************ */
> > +
> > +  public function get cacheFolder():String
> > +  {
> > +   return _cacheFolder;
> > +  }
> > +
> > +  public function getMultiDPIsource(dpi:Number = 0):String
> > +  {
> > +   if (dpi == 0)
> > +   {
> > +    return _assetURLallDPI;
> > +   }
> > +   if (dpi > 280)
> > +   {
> > +    return _assetURL320;
> > +   }
> > +   if (dpi > 200)
> > +   {
> > +    return _assetURL240;
> > +   }
> > +   return _assetURL160;
> > +  }
> > +
> > +  [Inspectable(category="General")]
> > +  [Bindable("sourceChanged")]
> > +  override public function get source():Object
> > +  {
> > +   if ((Capabilities.screenDPI > 280 )&&(_assetURL320 != null))
> > +   {
> > +    return _assetURL320;
> > +   }
> > +   if ((Capabilities.screenDPI > 200 )&&(_assetURL240 != null))
> > +   {
> > +    return _assetURL240;
> > +   }
> > +   if ((Capabilities.screenDPI <= 200 )&&(_assetURL160 != null))
> > +   {
> > +    return _assetURL160;
> > +   }
> > +   return _assetURLallDPI;
> > +  }
> > + }
> > +}
> >
> >
>
> --
> Alex Harui
> Flex SDK Team
> Adobe Systems, Inc.
> http://blogs.adobe.com/aharui
>
>