Tag Archive for flash

Halftone Effect in Actionscript 3 / Flash

package
{
	import flash.display.*;
	import flash.events.*;
	import flash.filters.*;
	import flash.net.*;
	


	public class Halftone extends Sprite
	{

		private var image:Class;
		
		private var loader:URLLoader;
		private var shader:Shader;
		private var filter:ShaderFilter;
		private var im:Bitmap;
		
		public function Halftone():void
		{	
			var myImage = new MyImage(500,333);
			im = new Bitmap(myImage);
			addChild(im);
			loader = new URLLoader();
			loader.dataFormat = URLLoaderDataFormat.BINARY;
			loader.addEventListener(Event.COMPLETE, onComplete);
			loader.load(new URLRequest("Halftone.pbj")); //Download: <a href="http://www.adamcoulombe.info/lab/as3/halftone/Halftone.pbj" >http://www.adamcoulombe.info/lab/as3/halftone/Halftone.pbj</a>
		}
		
		private function onComplete(e:Event):void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoved)

		}
		private function mouseMoved(e):void
		{
			shader = new Shader(loader.data);
			//shader.data.contrast.value = [ 1 ] ;
			shader.data.brightness.value = [ stage.mouseX /stage.stageWidth + 1   ];
			//shader.data.amount.value = [100];
			filter = new ShaderFilter(shader);
			im.filters = [filter];		
		}
	}
}

source

Check for multiple types of clickTag variables

clickable_button.onRelease = function() {
	if(_level0.clickTag!=undefined) {
		getURL(_level0.clickTag, "_blank");
	} else if(_root.clickTAG!=undefined) {
		getURL(_level0.clickTAG, "_blank");
	} else {
		trace("no clickTag or clickTAG specified!");
	}
}

source

flash focus detection

function main():void
{
    stage.addEventListener(Event.DEACTIVATE, windowNotActive);
    stage.addEventListener(Event.ACTIVATE, windowActive);
}
main();

function windowNotActive(e:Event):void
{
    trace("NOT ACTIVE");
}

function windowActive(e:Event):void
{
    trace("ACTIVE");
}

source

XHTML válido para adicionar Flash

<object id="" type="application/x-shockwave-flash" data="file.swf" width="300" height="250">
<param name="movie" value="file.swf" />
<param name="wmode" value="transparent" />
</object>

source

AS2 ComboBox ScrollBar fix

mx.controls.scrollClasses.ScrollThumb.prototype.onRelease = function(Void):Void {
		//this._parent.releaseFocus();
		this.stopDragThumb();
		this.super.onRelease();
	}
	
	mx.controls.scrollClasses.ScrollThumb.prototype.onReleaseOutside = function(Void):Void {
		//this._parent.releaseFocus();
		this.stopDragThumb();
		this.super.onReleaseOutside();
	}
	
	mx.controls.SimpleButton.prototype.onRelease = function(Void):Void {
		//this.releaseFocus();
		this.phase = "rollover";
		if (this.interval != undefined) {
		clearInterval(this.interval);
		delete this.interval;
	}
	
		if (this.getToggle()) {
			this.setState(!getState());
		} else {
			this.refresh();
		}
		this.dispatchEvent({type:"click"});
	}

	mx.controls.SimpleButton.prototype.onReleaseOutside = function(Void):Void {
		//this.releaseFocus();
		this.phase="up";
		if (this.interval != undefined) {
			clearInterval(this.interval);
			delete this.interval;
		}
	}

source

Click wheel fix for mac (safari + firefox)

// *** inside javascript **
function handleWheel(event) {
	var app = document.getElementById('flashSite');
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = -(event.wheelDelta/60); 
	} else if (event.detail) {
		delta = event.detail;
	}
	var o = {
		x: event.screenX,
		y: event.screenY,
		delta: delta,
		ctrlKey: event.ctrlKey,
		altKey: event.altKey,
		shiftKey: event.shiftKey
	};
	if (app && typeof(app.handleWheel) == 'function')
		app.handleWheel(o);
}

// on page onload
if(!(document.attachEvent)) {
	window.addEventListener("DOMMouseScroll", handleWheel, false);
	window.addEventListener('mousewheel', handleWheel, false);
	document.addEventListener('mousewheel', handleWheel, false);
}

// *** inside flash ***
if(ExternalInterface.available){
	ExternalInterface.addCallback("handleWheel", handleWheel);
}

// method that will be accessed from dispatched javascript events
public function handleWheel(event:Object): void {
	var mEvent:MouseEvent = new MouseEvent(MouseEvent.MOUSE_WHEEL, true, false,
		event.x, event.y, this,
		event.ctrlKey, event.altKey, event.shiftKey,
		false, -Number(event.delta));
	this.dispatchEvent(mEvent); // where "this" is the documentClass. Can be "stage" too
}

source

360 Degree View

cam.stop();

var frameTo:Number=0;

addEventListener(Event.ENTER_FRAME,goTo);

function goTo(e:Event):void{

frameTo=int(mouseX/stage.stageWidth*cam.totalFrames)+1;

cam.gotoAndStop(frameTo)

}

source

Top-Most Parent Loader Info

var topParent <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> isplayObject;
var paramObj  :Object = getLoaderInfo(this).parameters;
for(var varName:String in paramObj) {
	trace("varName: " + varName + " Value: " + paramObj[varName]);
}

function getLoaderInfo(dispObj:DisplayObject):LoaderInfo {
	var root:DisplayObject = getRootDisplayObject(dispObj);
	if (root!=null) {
		return root.loaderInfo;
	}
	return null;
}

function getRootDisplayObject(dispObj:DisplayObject):DisplayObject {
	if (topParent == undefined) {
		if (dispObj.parent!=null) {
			return getRootDisplayObject(dispObj.parent);
		}
		else {
			topParent = dispObj;
			return topParent;
		}
	}
	else {
		return topParent;
	}
}

source

Embedding Fonts for Anti Aliasing in Flash AS3

// To use this method you must embed and "Export for AS" the font in the Flash IDE (eg. Flash CS3, Flash CS4).
// You Can do this by clicking the menu on the library panel, then go "New Font"
// Then select "Export for Actionscript, and give your font class name.
// The class name is the name that you will reference on the line directly below this.

var myFont = new MyFontClassName();

var myFormat:TextFormat = new TextFormat();
myFormat.size = 40;
myFormat.font = myFont.fontName;

var myText:TextField = new TextField();
myText.defaultTextFormat = myFormat;
myText.embedFonts = true;
myText.antiAliasType = AntiAliasType.ADVANCED;
myText.autoSize = "left";
myText.text = "Here is some pretty that is anti-aliased!";
addChild(myText);

source

Spotlight Navigation effect using AS3 and Tweenlite

X ,y:startY,alpha:0, onComplete:removeFromDisplayList, onCompleteParams:[spots[clickIndex][i]] });
}
}

function continueTween(obj){
TweenLite.to(obj, 2, {x:clickPoint.x + Math.random() *16-8 ,y:clickPoint.y+ Math.random() *16-8,ease:Sine.easeInOut, onComplete:continueTween, onCompleteParams:[obj] });
}

function removeFromDisplayList(child){
var theParent = child.parent;
theParent.removeChild(child);
}
source