<?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>ohsomuchwork &#187; ActionScript 3.0</title>
	<atom:link href="http://ohsomodern.org/work/category/actionscript3/feed" rel="self" type="application/rss+xml" />
	<link>http://ohsomodern.org/work</link>
	<description>Code snippets, ActionScript 3.0 and some other tech stuff</description>
	<lastBuildDate>Wed, 25 Apr 2012 08:30:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>GreenSock TweenLite/TimelineLite caching height of textfield</title>
		<link>http://ohsomodern.org/work/actionscript3/greensock-tweenlitetimelinelite-caching-height-of-textfield</link>
		<comments>http://ohsomodern.org/work/actionscript3/greensock-tweenlitetimelinelite-caching-height-of-textfield#comments</comments>
		<pubDate>Fri, 06 Apr 2012 12:48:18 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[greensock]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[TimelineLite]]></category>
		<category><![CDATA[tweening]]></category>
		<category><![CDATA[TweenLite]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=244</guid>
		<description><![CDATA[I was trying to do a smooth animation sequence like this: Tween TextField alpha to 0. Tween background MovieClip to height 0. Change the text. Tween the background MovieClip to height of the changed TextField. Tween TextField alpha back to &#8230; <a href="http://ohsomodern.org/work/actionscript3/greensock-tweenlitetimelinelite-caching-height-of-textfield">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was trying to do a smooth animation sequence like this:</p>
<ol>
<li>Tween TextField alpha to 0.</li>
<li>Tween background MovieClip to height 0.</li>
<li>Change the text.</li>
<li>Tween the background MovieClip to height of the changed TextField.</li>
<li>Tween TextField alpha back to 1.</li>
</ol>
<p>Unfortunately, when creating the timeline sequence the height of the TextField got &#8220;cached&#8221; and was not updated on runtime after the text of the TextField had changed. My workaround on this is to append to the timeline <strong>after</strong> the text has been changed, and not build the whole sequence at once.</p>
<p>Not sure how this would work if there had to be things done after updating the texts, but I assume you can insert at a specific time/label in the Timeline, so that would solve it, I assume.</p>
<p><a href="http://ohsomodern.org/work/wp-content/uploads/2012/04/Textbox.swf">Textbox</a> SWF</p>
<p>Hm, not in the swf but I added code to remove the tweens once they are done, otherwise it keeps appending to the end of the timeline each time the animation is run.</p>
<p>Code:</p>
<pre>
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.MouseEvent;
import flash.text.TextFieldAutoSize;

button_mc.addEventListener(MouseEvent.CLICK, update);
reset_mc.addEventListener(MouseEvent.CLICK, reset);
button_mc.buttonMode = true;
reset_mc.buttonMode = true;
popup_mc.x = 0;
popup_mc.y = 50;

popup_mc.body_txt.autoSize = TextFieldAutoSize.LEFT;

var texts:Array = new Array();
texts.push("Cotton candy sweet roll carrot cake candy. Jelly tart tart icing wafer carrot cake biscuit macaroon. Sweet roll pie faworki marshmallow bonbon bear claw. Chocolate caramels cake sweet roll marzipan. Lemon drops icing wafer soufflé brownie brownie candy canes donut. Muffin pastry gummies sweet roll dragée caramels jelly apple pie. Carrot cake fruitcake marzipan fruitcake dragée biscuit tootsie roll cookie. Marshmallow bonbon oat cake. Pudding cake gummies bonbon dessert caramels sugar plum candy bonbon. Wafer candy canes tiramisu brownie jelly-o. Liquorice pastry pie. Toffee dessert pie. Chocolate cake biscuit lemon drops gummies jelly-o cake cake candy canes sesame snaps.");
texts.push("Jelly beans macaroon brownie dragée. Jelly chocolate cake chupa chups caramels pastry sweet roll marshmallow. Liquorice gummies sweet roll. Tart liquorice chocolate faworki cake cake. Icing pastry marzipan jelly-o bear claw cookie ice cream lemon drops. Jelly-o bear claw tart applicake. Ice cream pie sweet tootsie roll gummi bears dessert cotton candy. Bonbon bear claw bonbon pudding. Gummies jelly-o liquorice candy canes sweet roll. Bonbon apple pie marzipan pastry jelly beans marzipan chocolate bar powder. Cake biscuit candy lemon drops marshmallow chocolate cake applicake. Jelly beans croissant pie applicake apple pie sugar plum lollipop.");
texts.push("Tootsie roll croissant liquorice. Dragée chocolate cake macaroon. Chocolate bar gummi bears ice cream faworki wypas. Bonbon bear claw candy cotton candy gummies dessert. Sesame snaps cotton candy marshmallow soufflé jujubes gingerbread pie pudding. Topping icing tiramisu pie bonbon halvah. Fruitcake wypas tootsie roll wafer icing. Brownie topping sweet roll carrot cake faworki chocolate bar gummies cookie chocolate. Bear claw pudding muffin candy canes. Fruitcake croissant chocolate apple pie donut brownie cotton candy jelly sweet roll. Carrot cake lemon drops caramels icing muffin halvah. Croissant biscuit muffin marshmallow. Candy jelly-o candy canes sweet roll caramels wypas gingerbread danish.");

var tm:TimelineMax = new TimelineMax({onComplete: removeOldTweens});
tm.stop();
tm.appendMultiple([new TweenLite(popup_mc.header_txt, 1, {alpha: 0}), new TweenLite(popup_mc.body_txt, 1, {alpha: 0})]);
tm.appendMultiple([new TweenLite(popup_mc.greenBody_mc, 1, {height: 0}), new TweenLite(popup_mc.greenArrow_mc, 1, {y: popup_mc.greenHeader_mc.y + 25})]);
tm.append(new TweenLite(popup_mc, 1, {x: 50}));
tm.addCallback(changeText, 3);

var headerTween:TweenLite;
var bodyBgTween:TweenLite;
var arrowTween:TweenLite;
var textFieldTween:TweenLite;

function changeText():void {
	popup_mc.header_txt.text = "Another headline on this information box";
	popup_mc.body_txt.text = texts[int(Math.random() * 2)];
	popup_mc.body_txt.width = 290;

	// append to timeline
	headerTween = new TweenLite(popup_mc.header_txt, 1, {alpha: 1});
	bodyBgTween = new TweenLite(popup_mc.greenBody_mc, 1, {height:  popup_mc.body_txt.height+10});
	arrowTween = new TweenLite(popup_mc.greenArrow_mc, 1, {y: popup_mc.body_txt.height+10+25});
	textFieldTween = new TweenLite(popup_mc.body_txt, 1, {alpha: 1});

	tm.append(headerTween);
	tm.appendMultiple([bodyBgTween, arrowTween]);
	tm.append(textFieldTween);
}

function removeOldTweens():void {
	tm.remove(headerTween);
	tm.remove(bodyBgTween);
	tm.remove(arrowTween);
	tm.remove(textFieldTween);

	headerTween = null;
	bodyBgTween = null;
	arrowTween = null;
	textFieldTween = null;
}

function update(e:MouseEvent):void {
	tm.play();
}

function reset(e:MouseEvent):void {
	popup_mc.x = 0;
	popup_mc.y = 50;
	popup_mc.header_txt.text = "Header text!";
	popup_mc.body_txt.text = "Blah blah";
	tm.gotoAndStop(0);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/greensock-tweenlitetimelinelite-caching-height-of-textfield/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smooth scrolling TextField in ActionScript 3.0 with TweenMax from Greensock</title>
		<link>http://ohsomodern.org/work/actionscript3/smooth-scrolling-textfield-in-actionscript-3-0-with-tweenmax-from-greensock</link>
		<comments>http://ohsomodern.org/work/actionscript3/smooth-scrolling-textfield-in-actionscript-3-0-with-tweenmax-from-greensock#comments</comments>
		<pubDate>Tue, 21 Feb 2012 13:34:12 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=241</guid>
		<description><![CDATA[Flash My Mind has a tutorial on how to make a blurred scrollbox in Flash with little help from Greensock/TweenMax. It can be used to scroll TextFields and other content. The tutorial can be found here. In case your content &#8230; <a href="http://ohsomodern.org/work/actionscript3/smooth-scrolling-textfield-in-actionscript-3-0-with-tweenmax-from-greensock">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Flash My Mind has a tutorial on how to make a blurred scrollbox in Flash with little help from Greensock/TweenMax. It can be used to scroll TextFields and other content. The tutorial can be found <a href="http://tutorials.flashmymind.com/2009/02/movieclip-scroller/" target="_blank">here</a>.</p>
<p>In case your content doesn&#8217;t scroll all the way back up, I found that this piece of code helps to work things out:<br />
<code><br />
var target:Number = ((myContent.height * 1.2 - myMask.height) * percentage) - myMask.y;<br />
</code><br />
So, multiply your content&#8217;s height with 20 % or something like that. It gives you a little bit of margin so you might experiment with this number. Then, instead of adding the y position of the mask to the target number, subtract it.</p>
<p>This did the trick for me!</p>
]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/smooth-scrolling-textfield-in-actionscript-3-0-with-tweenmax-from-greensock/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prevent loaded XML caching in ActionScript 3</title>
		<link>http://ohsomodern.org/work/actionscript3/prevent-loaded-xml-caching-in-actionscript-3</link>
		<comments>http://ohsomodern.org/work/actionscript3/prevent-loaded-xml-caching-in-actionscript-3#comments</comments>
		<pubDate>Tue, 10 Jan 2012 11:15:42 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=237</guid>
		<description><![CDATA[Method 1: var loader:URLLoader = new URLLoader(); var req:URLRequest = new URLRequest("thefiletoload.xml"); req.method = URLRequestMethod.POST; req.data = true; loader.load(req); Method 2: var userFilePath:String = "thefiletoload.xml"; if(Capabilities.playerType != "StandAlone" &#124;&#124; Capabilities.playerType != "External") { userFilePath += "?rnd=" + Math.random(); }]]></description>
			<content:encoded><![CDATA[<p>Method 1:</p>
<pre>var loader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest("thefiletoload.xml");
req.method = URLRequestMethod.POST;
req.data = true;
loader.load(req);</pre>
<p>Method 2:</p>
<pre>var userFilePath:String = "thefiletoload.xml";
if(Capabilities.playerType != "StandAlone" || Capabilities.playerType != "External") {
userFilePath += "?rnd=" + Math.random();
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/prevent-loaded-xml-caching-in-actionscript-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Loading variables to ActionScript 3.0 from PHP</title>
		<link>http://ohsomodern.org/work/actionscript3/loading-variables-to-actionscript-3-0-from-php</link>
		<comments>http://ohsomodern.org/work/actionscript3/loading-variables-to-actionscript-3-0-from-php#comments</comments>
		<pubDate>Sun, 08 Jan 2012 22:33:30 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=234</guid>
		<description><![CDATA[Prefix the request with http:// if you get undefined variables. I.e. don&#8217;t do: new URLRequest("myfile.php"); Do: new URLRequest("http://mydomain.com/myfile.php");]]></description>
			<content:encoded><![CDATA[<p>Prefix the request with http:// if you get undefined variables.</p>
<p>I.e. don&#8217;t do:</p>
<p><code>new URLRequest("myfile.php");</code></p>
<p>Do:</p>
<p><code>new URLRequest("http://mydomain.com/myfile.php");</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/loading-variables-to-actionscript-3-0-from-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Export SWF to PDF</title>
		<link>http://ohsomodern.org/work/actionscript3/export-swf-to-pdf</link>
		<comments>http://ohsomodern.org/work/actionscript3/export-swf-to-pdf#comments</comments>
		<pubDate>Sun, 11 Dec 2011 11:54:40 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=227</guid>
		<description><![CDATA[Here&#8217;s some code on how to export an entire image/MovieClip/Sprite to a PDF document, using the AlivePDF library. private function printAsPDF():void {             trace("CREATE PDF");                          var pdf:PDF = new PDF();    &#8230; <a href="http://ohsomodern.org/work/actionscript3/export-swf-to-pdf">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some code on how to export an entire image/MovieClip/Sprite to a PDF document, using the <a href="http://alivepdf.bytearray.org/" target="_blank">AlivePDF</a> library.</p>
<pre>private function printAsPDF():void {
            trace("CREATE PDF");
            
            var pdf:PDF = new PDF();
            var page:Page = new Page(Orientation.LANDSCAPE, Unit.MM, Size.A4);
            pdf.addPage(page);
            pdf.setMargins(0, 0, 0, 0);
            pdf.setDisplayMode(Display.REAL, Layout.SINGLE_PAGE, PageMode.USE_NONE, 1.0);
            // this is the image/movie clip container we're saving to the PDF
            var img:Sprite = Sprite(Canvas.getInstance());
            
            var bmpData:BitmapData = new BitmapData(img.width, img.height, true, 0xFFFFFF);
            var matrix:Matrix = new Matrix();
            matrix.createBox(2, 2, 0, 100, 100);
            bmpData.draw(img, matrix, null, null, null, true);
            
            var res:Resize = new Resize(Mode.FIT_TO_PAGE, Position.CENTERED);
            pdf.addImage(img);
            
            var f:FileReference = new FileReference();
            f.save(pdf.save(Method.LOCAL), "min_pdf.pdf");
        }</pre>
]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/export-swf-to-pdf/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drag and select in ActionScript 3</title>
		<link>http://ohsomodern.org/work/actionscript3/drag-and-select-in-actionscript-3</link>
		<comments>http://ohsomodern.org/work/actionscript3/drag-and-select-in-actionscript-3#comments</comments>
		<pubDate>Thu, 27 Oct 2011 06:14:25 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=208</guid>
		<description><![CDATA[Found this piece of code over at Kirupa that explains how to do a drag-and-select implementation in ActionScript 3.0: import flash.geom.*; var drawingBox:Sprite;/*resized sprite that acts as a selector*/ var stageObjects:Array = createRandomObjects(20);/*array of stage objects that might be selected*/ &#8230; <a href="http://ohsomodern.org/work/actionscript3/drag-and-select-in-actionscript-3">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Found this piece of code over <a href="http://www.kirupa.com/forum/showthread.php?346896-Drag-and-select-multiple-objects" target="_blank">at Kirupa</a> that explains how to do a drag-and-select implementation in ActionScript 3.0:</p>
<pre>import flash.geom.*;

var drawingBox:Sprite;/*resized sprite that acts as a selector*/
var stageObjects:Array = createRandomObjects(20);/*array of stage objects that might be selected*/

var mouseStart:Point;

/*drawing properties of drawingBox*/
var stroke:GraphicsStroke = new GraphicsStroke();
	stroke.thickness=1;
    stroke.fill = new GraphicsSolidFill(0x333399, .5);
var fill:GraphicsSolidFill = new GraphicsSolidFill(0x444444,.5);
var graph:Vector.&lt;IGraphicsData&gt;;
var path:GraphicsPath;

stage.addEventListener(MouseEvent.MOUSE_DOWN,MD,false,0,true);/*start drawing box*/
stage.addEventListener(MouseEvent.MOUSE_UP,MU,false,0,true);/*select objects*/

function createRandomObjects(n:int):Array
{
	var a:Array=new Array();
	for(var i:int=0;i&lt;n;i++)
	{
		var s:Sprite = new Sprite;
		s.graphics.beginFill(Math.random()*0xFFFFFF);
		s.graphics.drawRect(0,0,20,20);
		s.x=Math.random()*stage.stageWidth;
		s.y=Math.random()*stage.stageHeight;
		s.alpha=.5;
		s.name = String(i);
		a.push(s);
		addChild(s);
	}
	return(a);
}

function MD(e:MouseEvent):void
/*MOUSE DOWN - start drawing square*/
{
	// removes previous one
	if(drawingBox!=null)drawingBox.parent.removeChild(drawingBox);
	drawingBox=new Sprite;
	addChild(drawingBox);
	mouseStart=new Point(mouseX,mouseY);
	addEventListener(Event.ENTER_FRAME, EF,false,0,true);

	for(var i:int=0; i&lt;stageObjects.length; i++)
	{
		stageObjects[i].alpha=.5;
		stageObjects[i].rotation=0;
	}
}

function MU(e:MouseEvent):void
/*MOUSE UP - remove square and hit test everything under it*/
{
	removeEventListener(Event.ENTER_FRAME, EF,false);
trace('Selected objects are:');
	/*run a hit test for drawingBox against stageObjects*/
	for(var i:int=0; i&lt;stageObjects.length; i++)
	{
		if(drawingBox.hitTestObject(stageObjects[i]))
		{
			stageObjects[i].alpha=1;
			stageObjects[i].rotation=45;
trace('Hit ' + stageObjects[i].name);
		}
	}
	drawingBox.graphics.clear();
}

function EF(e:Event):void
/*ENTER FRAME - redraws the selction box based on mouse pointer location every frame*/
{
	drawingBox.graphics.clear();
	path = RR(mouseStart.x,mouseStart.y,mouseX,mouseY);
	graph = new Vector.&lt;IGraphicsData&gt;();
	stroke.fill = new GraphicsSolidFill(0xFF0000,1);
	graph.push(stroke, fill, path);
	drawingBox.graphics.drawGraphicsData(graph);
}

function RR(sx:Number, sy:Number, ex:Number, ey:Number):GraphicsPath
/*RETURN RECTANGLE - returns a Graphics path for a rectangle*/
{
	var p:GraphicsPath=new GraphicsPath;
	p.moveTo(sx,sy);
	p.lineTo(ex,sy);
	p.lineTo(ex,ey);
	p.lineTo(sx,ey);
	p.lineTo(sx,sy);
	return(p);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/drag-and-select-in-actionscript-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duplicate loader content in ActionScript 3</title>
		<link>http://ohsomodern.org/work/actionscript3/duplicate-loader-content-in-actionscript-3</link>
		<comments>http://ohsomodern.org/work/actionscript3/duplicate-loader-content-in-actionscript-3#comments</comments>
		<pubDate>Sun, 26 Jun 2011 10:35:36 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[code snippets]]></category>
		<category><![CDATA[loader]]></category>
		<category><![CDATA[sprite]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=149</guid>
		<description><![CDATA[Sometimes you want to display the loaded image file twice. Here&#8217;s how to do it. var loader:Loader = new Loader&#40;&#41;; &#160; var sprite1:Sprite = new Sprite&#40;&#41;; sprite1.addChild&#40;getLoadedBitmap&#40;loader.content&#41;&#41;; &#160; var sprite 2:Sprite = new Sprite&#40;&#41;; sprite2.addChild&#40;getLoadedBitmap&#40;loader.content&#41;&#41;; &#160; function getLoadedBitmap&#40;l:Loader&#41;:Bitmap &#123; return &#8230; <a href="http://ohsomodern.org/work/actionscript3/duplicate-loader-content-in-actionscript-3">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to display the loaded image file twice. Here&#8217;s how to do it.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> sprite1:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
sprite1.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>getLoadedBitmap<span style="color: #66cc66;">&#40;</span>loader.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> sprite <span style="color: #cc66cc;">2</span>:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
sprite2.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>getLoadedBitmap<span style="color: #66cc66;">&#40;</span>loader.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> getLoadedBitmap<span style="color: #66cc66;">&#40;</span>l:Loader<span style="color: #66cc66;">&#41;</span>:Bitmap <span style="color: #66cc66;">&#123;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>Bitmap<span style="color: #66cc66;">&#40;</span>l.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/duplicate-loader-content-in-actionscript-3/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Smooth movement of a TextField with Greensock tweens</title>
		<link>http://ohsomodern.org/work/actionscript3/smooth-movement-of-a-textfield-with-greensock-tweens</link>
		<comments>http://ohsomodern.org/work/actionscript3/smooth-movement-of-a-textfield-with-greensock-tweens#comments</comments>
		<pubDate>Thu, 23 Jun 2011 08:07:43 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[code snippets]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[greensock]]></category>
		<category><![CDATA[smooth movement]]></category>
		<category><![CDATA[tweening]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=145</guid>
		<description><![CDATA[Here is some code on how to get a TextField (or any other display object) to marquee/scroll across the stage smoothly. When it has scrolled out completely of the viewfield, it restarts from the right side of the stage. If &#8230; <a href="http://ohsomodern.org/work/actionscript3/smooth-movement-of-a-textfield-with-greensock-tweens">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here is some code on how to get a TextField (or any other display object) to marquee/scroll across the stage smoothly. When it has scrolled out completely of the viewfield, it restarts from the right side of the stage.</p>
<p>If the animation is rough, try increasing the document&#8217;s FPS to get a smoother movement.</p>
<p>This function calls itself when it&#8217;s complete and passes itself as a variable back to the function, so it repeats continuously.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> movementSpeed:<span style="color: #0066CC;">Number</span> = <span style="color: #cc66cc;">1.5</span>;
<span style="color: #000000; font-weight: bold;">var</span> speed:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">100</span>;
<span style="color: #000000; font-weight: bold;">var</span> stageWidth:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">1920</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> moveMarquee<span style="color: #66cc66;">&#40;</span>obj:DisplayObject<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>obj, movementSpeed, <span style="color: #66cc66;">&#123;</span>x:obj.<span style="color: #006600;">x</span> - speed, ease: Linear.<span style="color: #006600;">easeNone</span>, onComplete:moveMarquee, onCompleteParams:<span style="color: #66cc66;">&#91;</span>obj<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>obj.<span style="color: #006600;">x</span> <span style="color: #66cc66;">&amp;</span>lt; -obj.<span style="color: #0066CC;">width</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		TweenMax.<span style="color: #006600;">killTweensOf</span><span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>;
		obj.<span style="color: #006600;">x</span> = stageWidth;
		TweenMax.<span style="color: #006600;">to</span><span style="color: #66cc66;">&#40;</span>obj, movementSpeed, <span style="color: #66cc66;">&#123;</span>x:obj.<span style="color: #006600;">x</span> - speed, ease: Linear.<span style="color: #006600;">easeNone</span>, onComplete:moveMarquee, onCompleteParams:<span style="color: #66cc66;">&#91;</span>obj<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>To initialize the first start, use this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">moveMarquee<span style="color: #66cc66;">&#40;</span>marqueeText<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>And to kill it, use this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">TweenMax.<span style="color: #006600;">killTweensOf</span><span style="color: #66cc66;">&#40;</span>marqueeText<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/smooth-movement-of-a-textfield-with-greensock-tweens/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving a webcam image to a local shared object</title>
		<link>http://ohsomodern.org/work/actionscript3/saving-a-webcam-image-to-a-local-shared-object</link>
		<comments>http://ohsomodern.org/work/actionscript3/saving-a-webcam-image-to-a-local-shared-object#comments</comments>
		<pubDate>Thu, 16 Jun 2011 12:57:52 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=140</guid>
		<description><![CDATA[Sometimes it seems impossible to find what you are looking for on Google. Here is some code on how to save a webcam captured image to a local shared object. It is very simple and not optimized with compressions and &#8230; <a href="http://ohsomodern.org/work/actionscript3/saving-a-webcam-image-to-a-local-shared-object">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometimes it seems impossible to find what you are looking for on Google. Here is some code on how to save a webcam captured image to a local shared object. It is very simple and not optimized with compressions and encodings, but I just wanted to to do a quick test to see if it works.</p>
<p>Enjoy!</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package  <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">media</span>.<span style="color: #0066CC;">Camera</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">media</span>.<span style="color: #0066CC;">Video</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">MouseEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #0066CC;">text</span>.<span style="color: #0066CC;">TextField</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #0066CC;">SharedObject</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Rectangle</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CameraTest <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">MovieClip</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">camera</span>:<span style="color: #0066CC;">Camera</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">video</span>:<span style="color: #0066CC;">Video</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> bitmap:Bitmap;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> so:<span style="color: #0066CC;">SharedObject</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> ba:ByteArray;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> CameraTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">camera</span> = <span style="color: #0066CC;">Camera</span>.<span style="color: #006600;">getCamera</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// get webcam</span>
			<span style="color: #0066CC;">video</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Video</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// setup video</span>
			<span style="color: #0066CC;">video</span>.<span style="color: #006600;">attachCamera</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">camera</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// attach camera to video</span>
			addChild<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">video</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// add video to stage</span>
&nbsp;
                        <span style="color: #808080; font-style: italic;">// setup bitmap</span>
			bitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">video</span>.<span style="color: #0066CC;">width</span>, <span style="color: #0066CC;">video</span>.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
			bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bitmapData<span style="color: #66cc66;">&#41;</span>;
			bitmap.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">360</span>;
&nbsp;
                        <span style="color: #808080; font-style: italic;">// textfield for capture image button</span>
			<span style="color: #000000; font-weight: bold;">var</span> capture_btn:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			capture_btn.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;CAPTURE&quot;</span>;
&nbsp;
                        <span style="color: #808080; font-style: italic;">// background for capture image button</span>
			<span style="color: #000000; font-weight: bold;">var</span> spr:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			spr.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFF0000<span style="color: #66cc66;">&#41;</span>;
			spr.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
			spr.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			spr.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>capture_btn<span style="color: #66cc66;">&#41;</span>;
			spr.<span style="color: #006600;">mouseChildren</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			addChild<span style="color: #66cc66;">&#40;</span>spr<span style="color: #66cc66;">&#41;</span>;
			spr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, capture<span style="color: #66cc66;">&#41;</span>;
&nbsp;
                        <span style="color: #808080; font-style: italic;">// the local shared object</span>
			so = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #0066CC;">getLocal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;pictureTest&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
                        <span style="color: #808080; font-style: italic;">// retrieve button, yellow, without text</span>
			<span style="color: #000000; font-weight: bold;">var</span> ret:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			ret.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xFFFF00<span style="color: #66cc66;">&#41;</span>;
			ret.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRoundRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">50</span>,<span style="color: #cc66cc;">10</span>,<span style="color: #cc66cc;">10</span><span style="color: #66cc66;">&#41;</span>;
			ret.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			ret.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>MouseEvent.<span style="color: #006600;">CLICK</span>, retrieve<span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>ret<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> capture<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// remove the previous image from stage</span>
			<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>bitmap.<span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
				removeChild<span style="color: #66cc66;">&#40;</span>bitmap<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Captured&quot;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// draw new image</span>
			bitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">video</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// add new image data to shared object</span>
			so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">image</span> = bitmapData.<span style="color: #006600;">getPixels</span><span style="color: #66cc66;">&#40;</span>bitmapData.<span style="color: #006600;">rect</span><span style="color: #66cc66;">&#41;</span>;
			so.<span style="color: #0066CC;">flush</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> retrieve<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			bitmapData.<span style="color: #006600;">setPixels</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Rectangle<span style="color: #66cc66;">&#40;</span>bitmap.<span style="color: #006600;">x</span>, bitmap.<span style="color: #006600;">y</span>, bitmap.<span style="color: #0066CC;">width</span>, bitmap.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>, so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">image</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>bitmap<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/saving-a-webcam-image-to-a-local-shared-object/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A good read for going further</title>
		<link>http://ohsomodern.org/work/actionscript3/a-good-read-for-going-further</link>
		<comments>http://ohsomodern.org/work/actionscript3/a-good-read-for-going-further#comments</comments>
		<pubDate>Tue, 14 Jun 2011 14:47:47 +0000</pubDate>
		<dc:creator>jenni</dc:creator>
				<category><![CDATA[ActionScript 3.0]]></category>
		<category><![CDATA[Elsewhere on the Internet]]></category>

		<guid isPermaLink="false">http://ohsomodern.org/work/?p=138</guid>
		<description><![CDATA[Googling for a marquee text field, I stumbled across an ActionScript blog by Jackson Dunstan, having many interesting articles about code development. http://jacksondunstan.com/]]></description>
			<content:encoded><![CDATA[<p>Googling for a marquee text field, I stumbled across an ActionScript blog by Jackson Dunstan, having many interesting articles about code development.</p>
<p><a href="http://jacksondunstan.com/">http://jacksondunstan.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ohsomodern.org/work/actionscript3/a-good-read-for-going-further/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

