<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.mattiasnorell.com &#187; Tutorial</title>
	<atom:link href="http://blog.mattiasnorell.com/category/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mattiasnorell.com</link>
	<description>Och jobbet går bra...?</description>
	<lastBuildDate>Tue, 07 Sep 2010 17:11:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Pure ActionScript 3 inverted mask 2.0</title>
		<link>http://blog.mattiasnorell.com/2010/08/21/pure-actionscript-3-inverted-mask-2/</link>
		<comments>http://blog.mattiasnorell.com/2010/08/21/pure-actionscript-3-inverted-mask-2/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 00:00:05 +0000</pubDate>
		<dc:creator>Mattias</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[In english]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[inverted mask]]></category>

		<guid isPermaLink="false">http://blog.mattiasnorell.com/?p=972</guid>
		<description><![CDATA[About ten months ago I wrote a little as3-class that took care of something I think Adobe should have implemented in the FlashPlayer a long time ago, the inverted mask. As time went by I&#8217;ve added some features I found &#8230; <a href="http://blog.mattiasnorell.com/2010/08/21/pure-actionscript-3-inverted-mask-2/">Läs mer <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>About ten months ago I wrote a little as3-class that took care of something I think Adobe should have implemented in the FlashPlayer a long time ago, the inverted mask. As time went by I&#8217;ve added some features I found useful while working on projects at work. In this version you can swap between inverted and normal masks, hide/show the mask and remove it from memory.</p>
<p>Finally I just want to say: Adobe, I love Flash but I still think this is way to complicated. A simple <em>DisplayObject.invertedMask = theMask;</em> would be just fine. I know it&#8217;s easy to say &#8221;just do it&#8221; but this is a feature a lot of developers would find useful.</p>
<h3><a href="http://static.mattiasnorell.com/blog/2010/08/Main.swf" rel="shadowbox[post-972];width=640;height=385;" onclick="pageTracker._trackPageview('/outgoing/static.mattiasnorell.com/blog/2010/08/Main.swf?referer=');">Demo</a></h3>
<h3>The InvertedMask.as-class</h3>
<pre class="brush: actionscript3; font-size: 50%">package com.mattiasnorell.bitmap
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.DisplayObject;
import flash.display.Sprite;

/**
* Inverted Mask
* Version 2.0
*
* ...
* Original author:    Rachel Diesel
*                     http://dieselation.com/2009/04/11/inverting-a-mask-in-actionscript-3/
*
* Pure AS3 code    Mattias Norell
*                     http://blog.mattiasnorell.com/2010/08/21/pure-actionscript-3-inverted-mask-2/
*
*/

public class InvertedMask extends Sprite{

private var inverted:Sprite;
private var dup:BitmapData;
private var newAlpha:Bitmap;
private var isInverted:Boolean;

public function InvertedMask($parent:DisplayObject,$mask:DisplayObject,$maskPos:Object):void {
inverted = new Sprite();
inverted.x = $parent.x;
inverted.y = $parent.y;

dup = new BitmapData($mask.width, $mask.height, true, 0xffffff);
dup.draw($mask);

newAlpha = new Bitmap(dup, "auto", false);
newAlpha.x = $maskPos.x;
newAlpha.y = $maskPos.y;
newAlpha.blendMode = BlendMode.ERASE;

$mask.parent.removeChild($mask);

$parent.x=$parent.y = 0;

inverted.addChild($parent);
inverted.addChild(newAlpha);

inverted.blendMode = BlendMode.LAYER;

addChild(inverted);

isInverted = true;
}

public function moveMask($target:Object,$maskPos:Object):void {
$target.getChildAt(0).getChildAt(1).x  = $maskPos.x;
$target.getChildAt(0).getChildAt(1).y  = $maskPos.y;
}

public function Show():void{
inverted.blendMode = BlendMode.LAYER;
}

public function Hide():void{
inverted.blendMode = BlendMode.NORMAL;
}

public function autoShowHide():void{
(inverted.blendMode == BlendMode.LAYER) ? Hide() : Show();
}

public function swapMaskType($type:String = "auto"):void{
if($type == 'auto'){
$type = (isInverted == true) ? 'normal' : 'inverted';
}

if($type == 'inverted'){
Show();
inverted.mask = null;
isInverted = true;
}else if($type == 'normal'){
Hide();
inverted.mask = newAlpha;
isInverted = false;
}else{
trace("You must use either 'inverted','normal' or 'auto'.");
}
}

public function remove():void{
inverted.mask = null;
inverted.blendMode = BlendMode.NORMAL;

newAlpha.bitmapData.dispose();
newAlpha = null;
dup.dispose();
dup = null;
}
}
}
</pre>
<h3>Source for the demo swf</h3>
<p>When I code I use Flash Develop, hence the [Embed]-code below. If you use the Flash IDE just remove those two rows and import the image from the library.</p>
<pre class="brush: actionscript3; font-size: 50%">package{
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	public class Main extends Sprite{

		[Embed(source="image.jpg")]
		public var imgCls:Class;

		public function Main():void{
			var img:Sprite = new Sprite();
			img.addChild(new imgCls());
			addChild(img);

			var mask:Sprite = new Sprite();
			mask.graphics.beginFill(0xFF0000,1);
			mask.graphics.drawRect(0,0,30,30);
			mask.graphics.endFill();
			addChild(mask);

			var newMask:InvertedMask = new InvertedMask(img, mask, { x:0, y:0 } );
			addChild(newMask);

			newMask.addEventListener(MouseEvent.MOUSE_MOVE, moveMask);
			newMask.addEventListener(MouseEvent.CLICK, swap);
		}

		private function swap(e:MouseEvent):void {
			e.currentTarget.swapMaskType();
		}

		private function moveMask(e:MouseEvent):void {
			e.currentTarget.moveMask(e.currentTarget, { x:mouseX-10, y:mouseY-10 } );
		}
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattiasnorell.com/2010/08/21/pure-actionscript-3-inverted-mask-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nedgradera en iPhone 3G från iOS4 till 3.1.3</title>
		<link>http://blog.mattiasnorell.com/2010/08/13/nedgradera-en-iphone-3g-fran-ios4-till-3-1-3/</link>
		<comments>http://blog.mattiasnorell.com/2010/08/13/nedgradera-en-iphone-3g-fran-ios4-till-3-1-3/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 07:56:52 +0000</pubDate>
		<dc:creator>Mattias</dc:creator>
				<category><![CDATA[Apple]]></category>
		<category><![CDATA[Jailbreak]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.mattiasnorell.com/?p=919</guid>
		<description><![CDATA[När jag uppgraderade till iOS4 var jag nöjd i ungefär två sekunder. Inte nog med att uppgraderingsprocessen var en pina, de följande veckorna var ingen höjdare heller. Det jag tyckte var värst var egentligen inte att iPhonen gick ruskigt långsamt &#8230; <a href="http://blog.mattiasnorell.com/2010/08/13/nedgradera-en-iphone-3g-fran-ios4-till-3-1-3/">Läs mer <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>När jag uppgraderade till iOS4 var jag nöjd i ungefär två sekunder. Inte nog med att <a href="http://blog.mattiasnorell.com/2010/06/23/detta-standiga-krangel-hur-jag-uppdaterade-till-ios-4-0/" target="_blank">uppgraderingsprocessen var en pina</a>, de <a href="http://blog.mattiasnorell.com/2010/07/20/how-i-managed-to-restore-my-iphone-and-live-to-tell-about-it/" target="_blank">följande veckorna var ingen höjdare</a> heller.</p>
<p>Det jag tyckte var värst var egentligen inte att iPhonen gick ruskigt långsamt utan att jag förlorade alla jailbreakprogram som gav mig alla de &#8221;förbättringar&#8221; iOS4 skulle ge. Fast på ett sätt så att det faktiskt gick att använda telefonen. Program som <a href="http://cydia.saurik.com/package/backgrounder" target="_blank" onclick="pageTracker._trackPageview('/outgoing/cydia.saurik.com/package/backgrounder?referer=');">Backgrounder</a>, <a href="http://modmyi.com/cydia/package.php?id=11546" target="_blank" onclick="pageTracker._trackPageview('/outgoing/modmyi.com/cydia/package.php?id=11546&amp;referer=');">Kirikae</a>, <a href="http://modmyi.com/cydia/package.php?id=3187" target="_blank" onclick="pageTracker._trackPageview('/outgoing/modmyi.com/cydia/package.php?id=3187&amp;referer=');">SB Settings</a>, <a href="http://cydia.saurik.com/package/com.yllier.firewall" target="_blank" onclick="pageTracker._trackPageview('/outgoing/cydia.saurik.com/package/com.yllier.firewall?referer=');">FiP</a>, <a href="http://cydia.saurik.com/package/openssh" target="_blank" onclick="pageTracker._trackPageview('/outgoing/cydia.saurik.com/package/openssh?referer=');">openSSH</a> gjorde iPhonelivet både roligare och enklare.</p>
<h2>Hur man gör</h2>
<p>Jag utgick från en <a href="http://www.websitetology.com/?p=711" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.websitetology.com/?p=711&amp;referer=');">guide på websitetology</a> med några små förändringar. Detta skall också fungera på 3GS:er men jag låter detta vara osagt då jag bara testat det på min 3G. Jag behöver väl inte påpeka att saker och ting görs på egen risk? Bra. Tänkte väl det.</p>
<ol>
<li>Starta om din iPhone i DFU-läge. Detta gör du genom att koppla in telefonen via USB-sladden till datorn sedan stänga av iPhonen.
<p>Sätt på den genom att hålla ner både på- och hemknappen i tio sekunder. Efter tio sekunder släpper du på-knappen och fortsätter hålla hemknappen nedtryckt tills iTunes upptäcker en iPhone i återställningsläge. Skärmen skall nu vara helt svart och inte visa en bild på iTunesloggan samt en USB-sladd.</li>
<li>I iTunes, klicka på &#8221;Återställ&#8221;-knappen samtidigt som du håller altknappen intryckt om du kör Mac och shift om du kör Windows. iTunes kommer nu be dig välja vilken firmware du vill använda. <a href="http://theiphonewiki.com/wiki/index.php?title=Firmware" target="_blank" onclick="pageTracker._trackPageview('/outgoing/theiphonewiki.com/wiki/index.php?title=Firmware&amp;referer=');">Firmwares finns att ladda ner här.</a></li>
<li>Nu kommer iTunes försöka återställa din iPhone. När processen är färdig kommer du få ett felmeddelande med kod 1015. Det ska vara så. Kort och gott.</li>
<li>iPhonen är nu fast i recoveryläge och kommer inte starta. Vi använder RecBoot för tvinga den ur recoveryläget och när telefonen startat om är den nedgraderad och klar. <a href="http://www.sebby.net/443-recboot-final-release/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.sebby.net/443-recboot-final-release/?referer=');">Ladda ner RebBoot här</a></li>
<li>Vill man jailbreaka den så kör man redsn0w version 0.9.4 tillsammans med firmware 3.1.2.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattiasnorell.com/2010/08/13/nedgradera-en-iphone-3g-fran-ios4-till-3-1-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Open a jQuery LightBox from Flash</title>
		<link>http://blog.mattiasnorell.com/2010/05/07/open-a-jquery-lightbox-from-flash/</link>
		<comments>http://blog.mattiasnorell.com/2010/05/07/open-a-jquery-lightbox-from-flash/#comments</comments>
		<pubDate>Fri, 07 May 2010 12:39:45 +0000</pubDate>
		<dc:creator>Mattias</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[In english]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[lightbox]]></category>

		<guid isPermaLink="false">http://blog.mattiasnorell.com/?p=562</guid>
		<description><![CDATA[The idea behind this plugin is to let Flash call a jQuery-function that will open up a LightBox. Nothing fancy, just a lightbox. But before we begin I have two things to say: 1. This is a work in progress. &#8230; <a href="http://blog.mattiasnorell.com/2010/05/07/open-a-jquery-lightbox-from-flash/">Läs mer <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The idea behind this plugin is to let Flash call a jQuery-function that will open up a LightBox. Nothing fancy, just a lightbox. But before we begin I have two things to say:</p>
<p>1. This is a work in progress. As of now it only lets you display one image, no text or navigation and so on. I plan to rewrite most of the plugin sometime in the future to make it more like &#8221;the real lightbox&#8221;.</p>
<p>2. This jQuery plugin was inspired and based on jQuery lightBox by Leandro Vieira Pinho  &#8211; <a href="http://leandrovieira.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/leandrovieira.com?referer=');">http://leandrovieira.com</a>. In other words, I stole pretty much everything and rewrote some of the code.</p>
<p>Demo can be found <a href="http://dev.mattiasnorell.com/as3lightbox/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/dev.mattiasnorell.com/as3lightbox/?referer=');">here</a>.<br />
And a developmentversion of the plugin <a href="http://dev.mattiasnorell.com/as3lightbox/js/jquery.flashlightbox-0.1.js" target="_blank" onclick="pageTracker._trackPageview('/outgoing/dev.mattiasnorell.com/as3lightbox/js/jquery.flashlightbox-0.1.js?referer=');">here</a>. (You need to copy/paste right now, sorry.)<br />
﻿﻿<br />
Include the following in your html-file:<br />
ALWAYS add &#8221;id&#8221; as an attribute in your embedcode if you want IE7 to do what you want.</p>
<pre class="brush: js; font-size: 50%">&lt;link rel="stylesheet" type="text/css" href="JavaScript/flashlightbox/jquery.lightbox-0.5.css" media="screen" /&gt;
&lt;script type="text/javascript" src="JavaScript/flashlightbox/jquery.flashlightbox-0.1.js"&gt;&lt;/script&gt;
<script src="js/swfobject.js" type="text/javascript"><!--mce:0--></script>
&lt;script type="text/javascript"&gt;

$(document).ready(function() {
$('body').append('&lt;div id="flashLightbox"&gt;&lt;/div&gt;');
});

function flashLightbox(val) {
$('#flashLightbox').flashLightBox({
image: val,
imageLoading:'lightbox-ico-loading.gif',
imageBlank:'lightbox-blank.gif'});
}

&lt;/script&gt;

<script type="text/javascript"><!--mce:1--></script>
</pre>
<p>The code for the demoswf (I use FlashDevelop, FlexSDK 3.5 and Flash Player 9):</p>
<pre class="brush: actionscript3; font-size: 50%">package
{

// Import stuff
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.IOErrorEvent;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.external.ExternalInterface;
import flash.events.IOErrorEvent;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;

/**
* ...
* @author Mano
*/

public class Main extends Sprite
{

// Setup vars used later on
private var imgUrl:String;
private var imgLoader:Loader = new Loader;

public function Main():void
{

// It's hammertime!
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
// Always remove eventlisteners you dont use
removeEventListener(Event.ADDED_TO_STAGE, init);

//
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

// Set the var image Url.
if (this.loaderInfo.parameters.imgUrl) {
imgUrl = this.loaderInfo.parameters.imgUrl;
}else {
imgUrl = '2648636603_c65d0ecc9c_b.jpg';
}

// Load the image
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete,false,0,true);
imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onError,false,0,true);

var request:URLRequest = new URLRequest(imgUrl);
imgLoader.load(request);
}

private function zoom(e:MouseEvent):void {
// If the swf is allowed to use ExternalInterface we call the javascript-function 'flashLightbox'.
// Remeber to always test ExternalInterface on a server and not localy.
if (ExternalInterface.available) {
ExternalInterface.call("flashLightbox", imgUrl);
}else {
trace("ExternalInterface not available");
}
}

private function onComplete(e:Event):void {
/*
Next we resize the image so that we can load a huge image, which we probably will since we want to zoom it and it might not fit.
We create a bitmap and load the loadercontent into the bitmap.
*/

var image:Bitmap = Bitmap(imgLoader.content);
var imageHeigth:int = 200;

var newWidth:int = image.width/image.height * imageHeigth;
image.height = imageHeigth;
image.width = newWidth;
image.smoothing = true;

imgLoader.unload();

/*
* Since we are going to add a MouseEvent we need to create a holder in which we place the bitmap
* because bitmaps are not InteractiveObjects and don't have a clue how to fire events.
*/

var holder:Sprite = new Sprite();

// Some graphic mumbojumbo.
holder.graphics.beginFill(0xcccccc, 1);
holder.graphics.drawRoundRect(0, 0, image.width+40, image.height+40, 20);
holder.graphics.endFill();

// Add eventlistener
holder.addEventListener(MouseEvent.CLICK, zoom);

image.x = 20;
image.y = 20;

holder.addChild(image);

// Position the sprite in the center of the stage
holder.x = (stage.stageWidth - holder.width) / 2;
holder.y = (stage.stageHeight - holder.height) / 2;

addChild(holder);

trace('Image loaded. URL: ' + imgUrl);
}

private function onError(e:IOErrorEvent):void {
trace('Image not found. URL: ' + imgUrl);
}

}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattiasnorell.com/2010/05/07/open-a-jquery-lightbox-from-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic AS3 mask using BitmapData</title>
		<link>http://blog.mattiasnorell.com/2010/04/16/dynamic-as3-mask-using-bitmapdata/</link>
		<comments>http://blog.mattiasnorell.com/2010/04/16/dynamic-as3-mask-using-bitmapdata/#comments</comments>
		<pubDate>Fri, 16 Apr 2010 14:41:46 +0000</pubDate>
		<dc:creator>Mattias</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[In english]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[tweenlite]]></category>

		<guid isPermaLink="false">http://blog.mattiasnorell.com/?p=541</guid>
		<description><![CDATA[A while ago I got a question about how you mask displayobjects using a dynamic mask that &#8221;record&#8221; movement. As always, you can do this in about a million different ways but this is the one I use most frequently. &#8230; <a href="http://blog.mattiasnorell.com/2010/04/16/dynamic-as3-mask-using-bitmapdata/">Läs mer <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A while ago I got a question about how you mask displayobjects using a dynamic mask that &#8221;record&#8221; movement. As always, you can do this in about a million different ways but this is the one I use most frequently. I&#8217;ve added some comments in the code if you are unsure of what some things do but it&#8217;s all basic AS3-stuff I use apart from the tweening library <a href="http://www.greensock.com/tweenlite/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.greensock.com/tweenlite/?referer=');">TweenLite</a>, a library I use almost every day so if you havn&#8217;t tried it, do it. The delayedCall-function alone is a sweet sweet piece of nerdlove.</p>
<p>And I use FlashDevelop and the FlexSDK, so if you use the Flash IDE you need to remove the embedcode on row 24-25 and import the image from the library.</p>
<p><a rel="shadowbox;height=600;width=600;backgroundColor=#fff" href="http://static.mattiasnorell.com/blog/2010/04/MovingMask.swf" onclick="pageTracker._trackPageview('/outgoing/static.mattiasnorell.com/blog/2010/04/MovingMask.swf?referer=');">Demo</a></p>
<pre class="brush: actionscript3; font-size: 50%">package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import com.greensock.TweenLite;

	/**
	 * ...
	 * @author Mano
	 */
	public class Main extends Sprite
	{

		// Setup a few variables
		private var background:Sprite = new Sprite();
		private var ballHolder:Sprite = new Sprite();
		private var ball:Sprite = new Sprite();
		private var maskBPD:BitmapData;
		private var maskBMP:Bitmap = new Bitmap();

		// Embed the image "the Flex SDK"-way
		[Embed(source="key.jpg")]
		public var imgCls:Class;

		public function Main():void
		{
			// Makesure the stage is ready
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}

		private function init(e:Event = null):void
		{
			// Remove the eventlistener. ALWAYS remove unnecessary listeners.
			removeEventListener(Event.ADDED_TO_STAGE, init);

			// Create the BitmapData. Use tranceparancy or it will mask everything.
			maskBPD = new BitmapData(stage.stageWidth, stage.stageHeight, true,0xffffff);

			// And a ball to play with
			ball.graphics.beginFill(0xFF00FF, 1);
			ball.graphics.drawCircle(0, 0, 30);
			ball.graphics.endFill();

			// Add the background image to the stage
			background.addChild(new imgCls());
			addChild(background);

			// ...somthing to hold our ball
			addChild(ballHolder);
			ballHolder.addChild(ball);

			// ...and the mask
			addChild(maskBMP);

			// ...and set the the bitmap as a mask for "background".
			background.mask = maskBMP;

			// Add a listener that will call the function updateBallPosition everytime the event EnterFrame is fired.
			stage.addEventListener(Event.ENTER_FRAME, updateBallPosition);
		}

		private function updateBallPosition(e:Event):void {
			// To make stuff a little easier we use the excellent TweenLite
			// First we kill all of our balltweens
			TweenLite.killTweensOf(ball, false);
			// ...and tell our ball to move to the same position as the mousepointer.
			TweenLite.to(ball, 1, { x:mouseX, y:mouseY } );

			// Draw the clip "ballHolder" to the bitmapdata
			maskBPD.draw(ballHolder);
			// And update the Bitmapimage
			maskBMP.bitmapData = maskBPD;

			// This is really important, we need to cache both the background and the mask as bitmaps otherwise the mask won't work.
			background.cacheAsBitmap = true;
			maskBMP.cacheAsBitmap = true;
		}
	}
}</pre>
<p>We could add a lot of balls or what ever object we want to play around with and change the way the move but you get the idea. So, run along now kids and play with you own balls, or what ever object you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattiasnorell.com/2010/04/16/dynamic-as3-mask-using-bitmapdata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic mask using ActionScript</title>
		<link>http://blog.mattiasnorell.com/2010/01/15/dynamic-mask-using-actionscript/</link>
		<comments>http://blog.mattiasnorell.com/2010/01/15/dynamic-mask-using-actionscript/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 23:18:29 +0000</pubDate>
		<dc:creator>Mattias</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Air]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[In english]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[mask]]></category>

		<guid isPermaLink="false">http://blog.mattiasnorell.com/?p=399</guid>
		<description><![CDATA[I was asked if is possible to use my inverted mask-class with a dynamic mask. The answer right now is &#8221;not yet&#8221;. But it got me thinking and if you ask me again in a few days the answer might &#8230; <a href="http://blog.mattiasnorell.com/2010/01/15/dynamic-mask-using-actionscript/">Läs mer <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was asked if is possible to use my <a href="http://blog.mattiasnorell.com/2009/10/21/pure-actionscript-3-inverted-mask/" target="_blank">inverted mask-class </a>with a dynamic mask. The answer right now is &#8221;not yet&#8221;. But it got me thinking and if you ask me again in a few days the answer might be &#8221;of course, it always has&#8221;. So I Googled some stuff about dynamic masks and found that almost none suited what I wanted. I wanted the user to be able to double click somewhere inside the swf, add as many anchorpoints they want, be able to move them around and if they so choose, delete them.</p>
<p>Not as much <a href="http://www.urbandictionary.com/define.php?term=Frankencode" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.urbandictionary.com/define.php?term=Frankencode&amp;referer=');">Frankencode</a> as I was affraid it would be but someone might find it useful so I thought I´d share it. The code is commented if you are new to AS3 and want to know what is going on.</p>
<p><a rel="shadowbox;height=480;width=640;backgroundColor=#cccccc" href="http://static.mattiasnorell.com/blog/2010/01/dynamicmask.swf" onclick="pageTracker._trackPageview('/outgoing/static.mattiasnorell.com/blog/2010/01/dynamicmask.swf?referer=');">And here is a demo of the little thing</a>. Doubleclick inside the swf to add anchorpoints and doubleclick the handles to remove them.</p>
<pre class="brush: actionscript3; font-size: 50%">package{
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.Event;

public class Main extends Sprite{

//Setup a some stuff
public var maskBG:Sprite = new Sprite();
public var cord:Array = [];

public function Main():void{

// The image that will appear thru the mask
var lemmyImage:Sprite = new Sprite();
lemmyImage.addChild(new Lemmy());
addChild(lemmyImage);

// An invisible sprite that tracks where the user click
var clickMe:Sprite = new Sprite();
clickMe.graphics.beginFill(0xFF0000,0);
clickMe.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
clickMe.graphics.endFill();
addChild(clickMe);

// Some eventhandlers to see where the user click and to update the mask
clickMe.doubleClickEnabled = true;
clickMe.addEventListener(MouseEvent.DOUBLE_CLICK,addCord);
stage.addEventListener(Event.ENTER_FRAME,updateMask);

addChild(maskBG);

// Set the mask layer to cover the image
lemmyImage.mask = maskBG;

}

private function moveStart(e:MouseEvent):void{
e.currentTarget.startDrag();
e.currentTarget.addEventListener(MouseEvent.MOUSE_MOVE, moveUpdate);
}

private function moveStop(e:MouseEvent):void{
e.currentTarget.stopDrag();
e.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE, moveUpdate);
}

private function moveUpdate(e:MouseEvent):void{
// Get the location in the array for the handler
var id:int = getHandleId(e.currentTarget.name);

// Update the array with the new values
cord[id] = {id:e.currentTarget.name,x:e.currentTarget.parent.mouseX,y:e.currentTarget.parent.mouseY};
}

private function removeHandle(e:MouseEvent):void{
// Get the location in the array for the handler
var id:int = getHandleId(e.currentTarget.name);

// Remove the part of the array by splicing it.
// Save the splica in a temporaryarray so that it is possible
// to merge the stuff after out deletedpart with the array again.
var a:Array = cord.splice(id,cord.length);
for(var i:int = 1;i&lt;a.length;++i){
cord.push(a[i]);
}

e.currentTarget.parent.removeChild(e.currentTarget);
}

private function updateMask(e:Event):void{
// Clear the masklayer
maskBG.graphics.clear();
maskBG.graphics.lineStyle(2,0xffffff);
maskBG.graphics.beginFill(0xFF0000,1);

// If the value of i is 0 then we want to move to the locatino.
// If we use lineTo it will draw a line from the top left corner.
for(var i:int=0;i&lt;cord.length;++i){
if(i==0){
maskBG.graphics.moveTo(cord[i].x,cord[i].y);
}else{
maskBG.graphics.lineTo(cord[i].x,cord[i].y);
}
}

maskBG.graphics.endFill();
}

private function getHandleId(val:String):int{
// Hack to find the location of the coordinate in the array
for(var i:int=0;i&lt;cord.length;++i){
if(cord[i].id == val){
var id:int = i;
}
}

return id;
}

private function addCord(e:MouseEvent):void{

//Add handle
var handle:Sprite = new Sprite();
handle.graphics.beginFill(0xff0000,1);
handle.graphics.drawRect(0,0,10,10);
handle.graphics.endFill();
handle.x = e.currentTarget.mouseX-5;
handle.y = e.currentTarget.mouseY-5;

// I use the datemethod just cause it easy to get a uniquevalue.
// It's not close to perfect so you should rewrite this part.
// It was late when I did this, sorry  I guess =)
var now:Date = new Date();
handle.name = String(now.getUTCMinutes()+now.getMilliseconds()*Math.random());

// Set up the listeners for the handler
handle.doubleClickEnabled = true;
handle.addEventListener(MouseEvent.MOUSE_DOWN, moveStart);
handle.addEventListener(MouseEvent.MOUSE_DOWN, updateMask);
handle.addEventListener(MouseEvent.MOUSE_UP, moveStop);
handle.addEventListener(MouseEvent.DOUBLE_CLICK, removeHandle);
handle.addEventListener(Event.ADDED_TO_STAGE,updateMask);
addChild(handle);

// Push the coordinate into the array
cord.push({id:handle.name,x:e.currentTarget.mouseX,y:e.currentTarget.mouseY});
}
}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattiasnorell.com/2010/01/15/dynamic-mask-using-actionscript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Brightcove plugin, custom mutebutton</title>
		<link>http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/</link>
		<comments>http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 21:02:07 +0000</pubDate>
		<dc:creator>Mattias</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[In english]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[brightcove]]></category>
		<category><![CDATA[flashdevelop]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://blog.mattiasnorell.com/?p=257</guid>
		<description><![CDATA[I think Brightcove is a great service. I&#8217;ve been building videoplayers using their API for the past months and I must say it&#8217;s super sweet. The API take a while to get your head around but once you do you &#8230; <a href="http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/">Läs mer <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I think <a href="http://www.brightcove.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.brightcove.com?referer=');">Brightcove</a> is a great service. I&#8217;ve been building videoplayers using their API for the past months and I must say it&#8217;s super sweet. The API take a while to get your head around but once you do you can do a lot, even if you are just using their own markup-language BEML (Brightcove Experience Markup Language).</p>
<p>But this is&#8217;nt a post about how great Brightcove is. I know by experience that you can find a lot of stuff on the internet but not that many tutorials about Brightcoveplayers and that is a problem if you are just getting started and need a push in the right direction.</p>
<h3>Before I start.</h3>
<p>I do assume that you have used the Brightcove Studio, you know how to create playertemplates using BEML and know some basic ActionScript 3.</p>
<h3>Some background.</h3>
<p>The client I&#8217;ve done most of my Brightcoveprojects for wanted a chromeless player with nothing more than a mutebutton. They didn&#8217;t want to use the default controllers so I needed to write a custom plugin. Doing so is pretty straight forward but if you know a thing or two about the Player API you might understand how things work a little more.</p>
<h3>It all began in&#8230; the template</h3>
<p>The first thing you need to do is <a href="#" target="_blank">download the API SWC from Brightcove</a>.</p>
<p>Then you need to create a playertemplate inside the Brightcove studio. The player on which I based this tutorial got no controls beside the &#8221;play&#8221;-button that appear when you click on the moviearea.</p>
<p>A Brightcove plugins is nothing more than a SWF that you tell the template to import using the SWFLoader. So in the template we add a VideoPlayer-object and a SWFLoader-object. Since we use a VideoPlayer-object we can&#8217;t add a playlist to the player and therefore we don&#8217;t need to tell it which playlist or video to play since it will get that ID thru the embedcode. Moving on to the SWFLoader. The most important thing is the source, here you tell the template from where you want to load the plugin. Then set the X and Y-position of the plugin to what ever you want.</p>
<p>And that is pretty much all we have to do inside the Brightcove Studio. The last thing you need to do is to create the player itself and enable the &#8221;Enable ActionScript/JavaScript APIs&#8221;-option otherwise you will bash your head bloody against the screen since nothing you do will work.</p>
<pre class="brush: xml; font-size: 50%">&lt;Runtime&gt;
&lt;Layout style="background-color:#000000" width="600" height="200"&gt;
&lt;VideoDisplay id="videoPlayer"/&gt;
&lt;SWFLoader depth="2" y="10" x="10" source="YOUR_DOMAIN_URL_HERE/swfname.swf"/&gt;
&lt;/Layout&gt;
&lt;/Runtime&gt;</pre>
<h3>The plugin</h3>
<p>When I code I use FlashDevelop or Flex Builder. As long as the IDE you use can import SWC-files your safe, if not i suggest you download the free IDE <a href="http://www.flashdevelop.org" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.flashdevelop.org?referer=');">FlashDevelop</a> and the <a href="http://www.adobe.com/products/flex/flexdownloads/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.adobe.com/products/flex/flexdownloads/?referer=');">Flex SDK</a>.</p>
<p>Fire up your IDE and create a new project. The only thing that matters is that you use AS3. Now include the Player API SWC in the project and we can start to write some code. *jay* You can read more about SWCs <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_30.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/livedocs.adobe.com/flex/3/html/help.html?content=compilers_30.html&amp;referer=');">here</a> and how to include them into your FlashDevelop-project <a href="http://www.flashdevelop.org/community/viewtopic.php?p=22197#p22197" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.flashdevelop.org/community/viewtopic.php?p=22197_p22197&amp;referer=');">here</a>.</p>
<p>When I write plugins I do it in two different ways. The first one is to hook the VideoPlayer-module yourself. That requires you to write a lot of extra code but saves you a few kb in the end and gives you more control. The other way is to let your mainclass extend the CostumeModule. The CostumModule-class will take care of all the API-stuff at the cost of a few extra kb but in the end it will save you some work. It&#8217;s all comes down to if you want to re-invent the wheel or not.</p>
<p>Since I wanted the mutebutton to have an on and off-state I created two MovieClips with the classname &#8221;muteOn&#8221; and &#8221;muteOff&#8221; in Flash, exported the graphics as a SWC and included it in my FlashDevelop-project.</p>
<p>We begin by importing everything we need. The Sprite and MouseEvent are standard AS3-stuff so nothing new there so we move on to the three Brightcove-classes. <a href="http://docs.brightcove.com/en/player/com/brightcove/api/modules/APIModule.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.brightcove.com/en/player/com/brightcove/api/modules/APIModule.html?referer=');">APIModules</a>, <a href="http://docs.brightcove.com/en/player/com/brightcove/api/CustomModule.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.brightcove.com/en/player/com/brightcove/api/CustomModule.html?referer=');">CustomModule</a> and <a href="http://docs.brightcove.com/en/player/com/brightcove/api/modules/VideoPlayerModule.html" target="_blank" onclick="pageTracker._trackPageview('/outgoing/docs.brightcove.com/en/player/com/brightcove/api/modules/VideoPlayerModule.html?referer=');">VideoPlayerModule</a>. If you want more in depth knowledge about what they do just follow the links. Now we create all the stuff we want to use. The only thing that might be new is the datatype for the _playerModule, VideoPlayerModule. This will allow us to use all the stuff the videoplayer can, like mute, but before we can do that we must link _playerModule and the actual videoplayer together. We do that by overriding the initialize-function in the CostumModule-class, or at least I think it&#8217;s in that class. But it works.</p>
<p>In the Main-function we set up the graphics and the mouseevent. The variable muted is just to keep track of whether the player is muted or not. You might be able to ask the videoplayer if it&#8217;s muted or not, it&#8217;s not pretty but for this plugin I think this solution does the job.</p>
<p>When the user click the button the MouseEvent will call the mute-function and set the visibility for both icons to false and then let the if-statement check whether the player is muted. If not, the visibility of &#8221;muteOnGfx&#8221; is set to true and the mute-function within the videoplayer-object fires. When we call the mute-function we have to pass a booelan parameter, True if we want the sound off and false if we want it on. And that is it. Mute away now kids!</p>
<h3>The code in one piece</h3>
<pre class="brush: actionscript3; font-size: 50%">package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
import com.brightcove.api.APIModules;
import com.brightcove.api.CustomModule;
import com.brightcove.api.modules.VideoPlayerModule;

public class Main extends CustomModule{
private var button:Sprite = new Sprite();
private var _playerModule:VideoPlayerModule;
private var muted:Boolean = false;
private var muteOnGfx:muteOn = new muteOn();
private var muteOffGfx:muteOff = new muteOff();

override protected function initialize():void {
_playerModule = player.getModule(APIModules.VIDEO_PLAYER) as VideoPlayerModule;
}

public function Main():void {
button.addChild(muteOnGfx);
button.addChild(muteOffGfx);

if (muted == false) {
muteOnGfx.visible = false;
}else {
muteOffGfx.visible = false;
}

button.buttonMode = true;
addChild(button);

button.addEventListener(MouseEvent.CLICK, mute);
}

private function mute(e:MouseEvent):void {
muteOnGfx.visible = false;
muteOffGfx.visible = false;

if (muted == false) {
_playerModule.mute(true);
muteOnGfx.visible = true;
muted = true;
}else {
_playerModule.mute(false);
muteOffGfx.visible = true;
muted = false;
}
}
}
}</pre>
<h3>Conclusion</h3>
<p>This plugin could of course be modified to control almost everything like play-, pause-, stopbuttons etc. But this is a start and I plan to write some more tutorials about how to make the Brightcoveplayer do what you want. The first step is the hardest, right?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mattiasnorell.com/2009/12/17/brightcove-plugin-custom-mutebutton/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>