Quick Image Viewer
Thursday, November 26th, 2009 | Author: dehash
Made a quick image displayer with zoom and pan in just a few lines of code using BumpSlide and MinimalComps which can be viewed here. The main source code is below and the image is The Starry Night by Van Gogh from here
-
/**
-
* v0.1 code by dehash.com 2009
-
* based on example code at :
-
* http://bumpslide.googlecode.com/svn/trunk/as3/examples/zoom/ZoomDemo_01.as
-
* Released as open source under the BSD License
-
* http://www.opensource.org/licenses/bsd-license.php
-
*/
-
-
package {
-
-
import com.bit101.components.HBox;
-
import com.bit101.components.HSlider;
-
import com.bit101.components.Label;
-
import com.bit101.components.PushButton;
-
-
import com.bumpslide.ui.Applet;
-
import com.bumpslide.ui.ZoomPanel;
-
import net.stevensacks.utils.Web;
-
-
import flash.display.Bitmap;
-
import flash.display.Loader;
-
import flash.events.Event;
-
import flash.events.MouseEvent;
-
import flash.net.URLRequest;
-
-
public class ImageDisplayer extends Applet {
-
-
static private const CONTENT_URL:String = "starrynight1280.jpg";
-
private var zoomPanel:ZoomPanel;
-
private var image:Loader;
-
private var myZoomSlider:HSlider;
-
private var controls:HBox;
-
private var credits:HBox;
-
private var offset:uint = 50;
-
private var label:Label;
-
-
override protected function addChildren():void {
-
-
// load image with smoothing not applied
-
image = new Loader();
-
image.contentLoaderInfo.addEventListener(Event.INIT, function(e:Event):void {
-
(image.content as Bitmap).smoothing = false;
-
});
-
image.load(new URLRequest(CONTENT_URL));
-
-
// create zoom panel with image as content
-
zoomPanel = new ZoomPanel();
-
zoomPanel.content = image;
-
addChild(zoomPanel);
-
-
// create HBox to hold controls
-
controls = new HBox(this);
-
-
// create controls
-
new PushButton(controls, 0, 0, "Home", function():void {
-
zoomPanel.panTo(0, 0);
-
});
-
new PushButton(controls, 0, 0, "<<--", function():void {
-
zoomPanel.panLeft();
-
});
-
new PushButton(controls, 0, 0, "-->>", function():void {
-
zoomPanel.panRight();
-
});
-
new PushButton(controls, 0, 0, "/\\", function():void {
-
zoomPanel.panUp();
-
});
-
new PushButton(controls, 0, 0, "\\/", function():void {
-
zoomPanel.panDown();
-
});
-
myZoomSlider = new HSlider(controls, 0, 5, doZoom);
-
myZoomSlider.tick = 0.25;
-
myZoomSlider.minimum = 0.25;
-
myZoomSlider.maximum = 7;
-
myZoomSlider.value = 1;
-
-
addChild(controls);
-
-
zoomPanel.dragZoomControl.minZoom = .25;
-
zoomPanel.dragZoomControl.maxZoom = 7;
-
-
zoomPanel.zoomContent.cacheAsBitmap = true;
-
-
// create HBox to hold credits
-
credits = new HBox(this);
-
-
// create credits
-
var labelText:String = "Van Gogh - Starry Night - 1889 -";
-
labelText += "(source http://www.flickr.com/photos/financialaidpodcast/3956763480/)";
-
label = new Label(credits, 0, 0, labelText);
-
-
new PushButton(credits, 0, 0, "Image Source", getSource);
-
-
}
-
-
private function getSource(e:MouseEvent):void {
-
var link:String = "http://www.flickr.com/photos/financialaidpodcast/3956763480/";
-
Web.getURL(link, "_blank");
-
}
-
-
private function doZoom(event:Event):void {
-
zoomPanel.zoom = myZoomSlider.value;
-
}
-
-
/**
-
* Applets are resized when stage size changes, so re-center content during redraw
-
*/
-
override protected function draw():void {
-
zoomPanel.move(offset, offset);
-
zoomPanel.setSize(width * .85, height * .85);
-
controls.x = offset;
-
controls.y = offset / 2;
-
credits.x = offset;
-
credits.y = height * .95;
-
}
-
}
-
}
Category: Code Examples, Flash | One Comment















