/*
Copyright 2005 by the authors of asapframework
Licensed 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.
*/
// Adobe classes
//import flash.geom.*;
// Still support Flash 7:
import org.asapframework.util.types.*;
// ASAP classes
import org.asapframework.util.loader.*;
import org.asapframework.events.EventDelegate;
import org.asapframework.ui.buttons.SelectableButton;
import org.asapframework.util.actionqueue.*;
import org.asapframework.util.NumberUtils;
import org.asapframework.util.MovieClipUtils;
class ui.ThumbImage extends SelectableButton {
private static var FADE_IN_DURATION:Number = .9;
private var image_mc:MovieClip;
private var border_mc:MovieClip;
private var mLoader:Loader;
private var mSize:Point;
private var mFadeQueue:ActionQueue;
private var mOnLoadEventDelegate:Function;
/**
*/
public function onLoad () {
super.onLoad();
border_mc._visible = false;
}
/**
*/
public function setLoader (inLoader:Loader) : Void {
mLoader = inLoader;
}
/**
*/
public function setSize (inWidth:Number, inHeight:Number) : Void {
mSize = new Point(inWidth, inHeight);
}
/**
*/
public function setPosition (inX:Number, inY:Number) : Void {
_x = inX + mSize.x / 2;
_y = inY + mSize.y / 2;
}
/**
*/
public function loadImage (inUrl:String, inLoader:Loader) : Void {
setLoader(inLoader);
mOnLoadEventDelegate = EventDelegate.create(this, handleThumbLoadDone);
mLoader.addEventListener(LoaderEvent.ON_DONE, mOnLoadEventDelegate);
mLoader.load(image_mc, inUrl, "", false);
}
/**
*/
public function toString () : String {
return "ui.ThumbImage: " + _name;
}
// PRIVATE METHODS
/**
*/
private function init () : Void {
setSendEventOnPress(true);
}
/**
*/
private function drawUpState () : Void {
border_mc._visible = false;
}
/**
*/
private function drawOverState () : Void {
border_mc._visible = true;
}
/**
*/
private function drawSelectedState () : Void {
border_mc._visible = true;
}
/**
*/
private function handleThumbLoadDone (e:LoaderEvent) : Void {
if (e.targetClip != image_mc) {
return;
}
mLoader.removeEventListener(LoaderEvent.ON_DONE, mOnLoadEventDelegate);
delete mOnLoadEventDelegate;
var image:MovieClip = MovieClip(e.targetClip);
// constrain within size
var scale:Number = MovieClipUtils.getNormalizedScale(image, mSize);
image._xscale = image._yscale = scale;
image._x = -image._width / 2;
image._y = -image._height / 2;
image._alpha = 0;
image._visible = true;
update();
mFadeQueue = new ActionQueue();
mFadeQueue.addAction(AQFade.fade, image, FADE_IN_DURATION, null, 100);
mFadeQueue.run();
}
}