Return to Snippet

Revision: 16958
at August 19, 2009 09:20 by alexaivars


Initial Code
package {
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	
	import gs.plugins.SetSizePlugin;
	import gs.plugins.TweenPlugin;

	public class Main extends Sprite
	{
		private var m_body:Sprite;
		
		public function Main()
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			TweenPlugin.activate([SetSizePlugin]);
			
			var image:LoadedImage = new LoadedImage("http://farm1.static.flickr.com/12/14705113_15f2172f03.jpg");
			
			addChild(image);
		}

	}
}

import flash.display.Sprite;
import flash.display.Loader;
import flash.events.Event;
import flash.display.Bitmap;
import de.popforge.audio.processor.fl909.voices.Voice;
import flash.net.URLRequest;
import flash.events.MouseEvent;
import gs.TweenLite;
internal class LoadedImage extends Sprite
{
	private var m_loader:Loader
	private var m_bitmap:Bitmap;
	private var m_overlay:Sprite;
	private var m_mask:Sprite;
	private var m_source:String;
	
	public function LoadedImage(a_url:String)
	{
		m_source = a_url;
		initialize();
		load();
	}
	
	private function initialize():void
	{
		m_loader = new Loader();
		m_overlay = new Sprite();
		m_mask = new Sprite();
		
		addChild(m_mask);
		addChild(m_overlay);
		
		mask = m_mask;
		mouseChildren = false;
		buttonMode = true;
		
		m_overlay.alpha = 0;
		
		initializeListeners();
	}
	
	private function initializeListeners():void
	{
		addEventListener(MouseEvent.ROLL_OVER,mouseOverHandler,false,0,true);
		addEventListener(MouseEvent.ROLL_OUT,mouseOutHandler,false,0,true);
		addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler,false,0,true);
	}
	
	private function mouseOverHandler(a_event:MouseEvent):void
	{
		TweenLite.to( m_overlay,0.15,{alpha:1});
	}

	private function mouseOutHandler(a_event:MouseEvent):void
	{
		TweenLite.to( m_overlay,0.15,{alpha:0});
		
	}

	private function mouseDownHandler(a_event:MouseEvent):void
	{
		stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler,false,0,true);
		startDrag();
	}

	private function mouseUpHandler(a_event:MouseEvent):void
	{
		stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
		stopDrag();
	}

	private function load():void
	{
		m_loader.load( new URLRequest(m_source) );
		addLoaderListners();
	}
	
	private function draw():void
	{
		if(!m_bitmap) return;
		addChildAt(m_bitmap,0);
		
		with(m_overlay.graphics)
		{
			clear();
			beginFill(0xFF0000,0.5);
			drawRect(0,0,m_bitmap.width,m_bitmap.height);
			endFill();			
		}	

		with(m_mask.graphics)
		{
			clear();
			beginFill(0x00FF00,1);
			drawRect(0,m_bitmap.height*.25,m_bitmap.width,m_bitmap.height*.5);
			endFill();			
		}	

	}
	
	private function addLoaderListners():void
	{
		m_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderCompleteHandler);
	}	

	private function removeLoaderListners():void
	{
		m_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loaderCompleteHandler);
	}	

	private function loaderCompleteHandler(a_event:Event):void
	{
		removeLoaderListners();
		m_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,loaderCompleteHandler);
		m_bitmap = m_loader.content as Bitmap;
		draw();
		
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Load And Drag Image

Initial Tags

                                

Initial Language
ActionScript 3