<?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>ByPixels</title>
	<atom:link href="http://bypixels.ro/feed/" rel="self" type="application/rss+xml" />
	<link>http://bypixels.ro</link>
	<description>Razvan Dumitrescu</description>
	<lastBuildDate>Tue, 21 Feb 2012 09:46:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Simple scroller for flash textboxes</title>
		<link>http://bypixels.ro/blog/simple-scroller-for-flash-textboxes/</link>
		<comments>http://bypixels.ro/blog/simple-scroller-for-flash-textboxes/#comments</comments>
		<pubDate>Wed, 19 Oct 2011 20:54:00 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[buttons]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=354</guid>
		<description><![CDATA[In Flash, textboxes are of 3 types namely &#8211; Static, Dynamic &#38; Input. The size of Dynamic/Input text varies depending on the source file/user input and hence may require the ...]]></description>
			<content:encoded><![CDATA[<p>In Flash, textboxes are of 3 types namely &#8211; Static, Dynamic &amp; Input. The size of Dynamic/Input text varies depending on the source file/user input and hence may require the use of scrollers.<span id="more-354"></span></p>
<p>Create a Dynamic textbox with Multiline property selected using the Properties panel, name the variable and the instance as &#8216;addr&#8217; and &#8216;scrtxt&#8217; respectively.</p>
<p>Create 2 buttons for Upward and Downward scrolling and write the following Actionscript code:</p>
<p>Upward Button<br />
on(press)<br />
{<br />
scrtxt.scroll=scrtxt.scroll-1;<br />
}</p>
<p>Downward Button<br />
on(press)<br />
{<br />
scrtxt.scroll=scrtxt.scroll+1;<br />
}</p>
<p>Save your work and test the Movie (Ctrl + Enter). That&#8217;s it you have learnt how to create simple scrollers for textboxes in Flash using Actionscript.</p>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/simple-scroller-for-flash-textboxes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a simple content slider (AS2 )</title>
		<link>http://bypixels.ro/blog/creating-a-simple-content-slider-as2/</link>
		<comments>http://bypixels.ro/blog/creating-a-simple-content-slider-as2/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 08:10:19 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[carousel]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=236</guid>
		<description><![CDATA[I used this technique to create a simple video interface, with thumbnails for each video which had to slide horizontally. I also needed to stop my carousel movieclip to exit ...]]></description>
			<content:encoded><![CDATA[<p>I used this technique to create a simple video interface, with thumbnails for each video which had to slide horizontally.</p>
<p>I also needed to stop my carousel movieclip to exit the stage.</p>
<p><span id="more-236"></span></p>
<p>First of all I created a movieclip with all my thumbnails inside it and i named the movieclip &#8220;carousel&#8221;.</p>
<p>I created a mask on that movieclip, to control the visible area of it and on the left and right  I  created two buttons, which will move left and right my &#8220;carousel&#8221; movieclip, named &#8220;left_btn&#8221; and &#8220;right_btn&#8221;.</p>
<p>All is set now, we&#8217;ll create one new layer for the actionscript which controls the buttons and the movieclip.</p>
<p>In previous mentioned frame paste the following actionscript code:</p>
<p>&nbsp;</p>
<p>right_btn.onRollOver = function() {<br />
carousel.onEnterFrame = function() {<br />
this._x += 10;<br />
if(carousel._x &gt;= 40){<br />
trace(&#8220;edge reached&#8221;);<br />
delete carousel.onEnterFrame;<br />
//right_btn._visible = false;<br />
}<br />
};<br />
};<br />
right_btn.onRollOut = function() {<br />
delete carousel.onEnterFrame;<br />
};</p>
<p>left_btn.onRollOver = function() {<br />
carousel.onEnterFrame = function() {<br />
this._x -= 10;<br />
if((carousel._x + carousel._width) &lt;= Stage.width-40){<br />
trace(&#8220;edge reached&#8221;);<br />
delete carousel.onEnterFrame;<br />
//left_btn._visible = false;<br />
}<br />
};<br />
};<br />
left_btn.onRollOut = function() {<br />
delete carousel.onEnterFrame;<br />
};</p>
<p>&nbsp;</p>
<p>If something is not clear, please write a comment and you will get further assistance.</p>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/creating-a-simple-content-slider-as2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get a button to stay down in Flash, AS2</title>
		<link>http://bypixels.ro/blog/how-to-get-a-button-to-stay-down-in-flash-as2/</link>
		<comments>http://bypixels.ro/blog/how-to-get-a-button-to-stay-down-in-flash-as2/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 12:38:24 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[buttons]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=229</guid>
		<description><![CDATA[Rollover buttons have become a standard in web pages because they provide an interactive way to guide the users through the website. For example, a website can remind the user ...]]></description>
			<content:encoded><![CDATA[<p>Rollover buttons have become a standard in web pages because they provide an interactive way to guide the users through the website. For example, a website can remind the user of the current page simply by leaving a button in the same state as when it was pressed. When you convert an image to a button symbol in Flash CS3, Flash automatically provides rollover frames for the up, over, down and hit stages of buttons. Unfortunately, Flash assumes that you want the button to return to its original state after the button has been pressed. You can still create this effect by converting the button to a movie clip symbol rather than a button symbol. By entering a few simple codes from Actionscript 2.0, your button will remain in the down state informing the user of the current page.</p>
<p><span id="more-229"></span></p>
<ol id="intelliTxt">
<li id="jsArticleStep1">Draw the button shape. Select the rectangle tool and draw the shape of your button on the stage. If you want rounded corners, press the down arrow key as you draw the rectangle.</li>
<li id="jsArticleStep2">
<div>Step 2</div>
<p>Convert the shape to a movie clip. Select the shape; if the shape has a stroke, you will need to double-click on the shape. Select “Modify&gt;Convert to Symbol.” Name the symbol “btn_mc” and select “Movie Clip.” Click “OK.” Type “btn_mc” in the “Instance Name” box in the “Properties” panel.</li>
<li id="jsArticleStep3">
<div>Step 3</div>
<p>Create the button for the top state. Double-click on the movie clip to edit the movie clip. Change the name of “layer 1? to “Buttons.” Select the “Text Tool” and type the text for the button. Position the text on the button. Add additional effects to the button as desired.</li>
<li id="jsArticleStep4">
<div>Step 4</div>
<p>Convert the button to a button symbol. Select the entire button and select “Modify&gt;Convert to Symbol.” Name the symbol “button” and select “Button.” Click “OK.”</li>
<li id="jsArticleStep5">
<div>Step 5</div>
<p>Create the button for the down state. Select the frame where you want the button in the down state to begin. Select “Insert&gt;Timeline&gt;Keyframe.” Adjust the button for the down state. For example, if you want to have the button faded, adjust “Brightness” in the “Color” drop-down menu in the “Properties” panel.</li>
<li id="jsArticleStep6">
<div>Step 6</div>
<p>Label the frames. Insert a new layer called “Labels.” Insert a new keyframe for the frame that contains the top button and the frame that contains the down button. Select the keyframe for the top button. In the “Properties” palette, enter “_top” in the “Frames” box. Select the keyframe for the down button. In the “Properties” palette, enter “_down” in the “Frames” box.</li>
<li id="jsArticleStep7">
<div>Step 7</div>
<p>Add actions to the button states. Insert a layer called “Actions,” and insert a new keyframe for the frame that contains the top button and the frame that contains the down button. Select “Windows&gt;Actions” to display the Actions panel. Enter “stop();” in both keyframes.</li>
<li id="jsArticleStep8">
<div>Step 8</div>
<p>Add actions to the movie. Press the “Back ” button next to “Scene1? to return to the button shape. Click on “btn_mc.” The actions panel should say “Actions-Movie Clip” in the left hand corner. Enter the following code:</p>
<p>on (press)_root.mc_btn.gotoAndStop(“_down”);<br />
}<br />
on (release) {<br />
_root.mc_btn.gotoAndStop(“_down”);<br />
}</li>
</ol>
<div id="jsTips">
<div>Tips &amp; Warnings</div>
<div>
<ul>
<li>If you do not want to change the text with the button, place the text on a new layer called “text.”</li>
</ul>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/how-to-get-a-button-to-stay-down-in-flash-as2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Run an external executable file (.exe) from your flash</title>
		<link>http://bypixels.ro/blog/run-an-external-executable-file-exe-from-your-flash/</link>
		<comments>http://bypixels.ro/blog/run-an-external-executable-file-exe-from-your-flash/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 08:16:08 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[executables]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=225</guid>
		<description><![CDATA[Ok, so you have a folder with a flash file in it plus another totally independent .exe file.  How do you create a script that will run the exe file ...]]></description>
			<content:encoded><![CDATA[<p>Ok, so you have a folder with a flash file in it plus another totally independent .exe file.  How do you create a script that will run the exe file when you press a button inside the flash movie?</p>
<p><span id="more-225"></span></p>
<p>You should  have the button already to go and you  just need it to run the .exe file.</p>
<p>So, on that button you paste the following actionscript code:</p>
<p>&nbsp;</p>
<p>on(release){<br />
fscommand(&#8220;exec&#8221;, &#8220;your_app_name.exe&#8221;);<br />
}</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/run-an-external-executable-file-exe-from-your-flash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Close flash window button</title>
		<link>http://bypixels.ro/blog/close-flash-window-button/</link>
		<comments>http://bypixels.ro/blog/close-flash-window-button/#comments</comments>
		<pubDate>Wed, 13 Oct 2010 08:06:27 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[buttons]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=221</guid>
		<description><![CDATA[This should be useful when you publish your work as an executable file and, in some point you want the window to close. The code is very simple. On a ...]]></description>
			<content:encoded><![CDATA[<p>This should be useful when you publish your work as an executable file and, in some point you want the window to close.<span id="more-221"></span></p>
<p>The code is very simple.</p>
<p>On a button&#8217;s actionscript insert the following code:</p>
<p>&nbsp;</p>
<p>on (release) {<br />
getURL (&#8220;javascript:window.close()&#8221;);<br />
}</p>
<p>&nbsp;</p>
<p>Export your work and test it.</p>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/close-flash-window-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Manage depth with ActionScript 3</title>
		<link>http://bypixels.ro/blog/manage-depth-with-actionscript-3/</link>
		<comments>http://bypixels.ro/blog/manage-depth-with-actionscript-3/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 11:42:59 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[depth]]></category>
		<category><![CDATA[movieclips]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=215</guid>
		<description><![CDATA[Really quick and easy tutorial to see how to manage depth with actionscript 3. 1. Create a new flash file (Actionscript 3.0) and save it as cards.fla. 2. Rename “layer1&#8243; ...]]></description>
			<content:encoded><![CDATA[<p>Really quick and easy tutorial to see how to manage depth with actionscript 3.<span id="more-215"></span></p>
<p>1. Create a new flash file (Actionscript 3.0) and save it as cards.fla.</p>
<p>2. Rename “layer1&#8243; to “cards”. On this layer, with the rectangle tool selected, draw 4 rectangles of different colors and convert each to a movie clip. Give them instance names of “card1&#8243;, “card2&#8243;, “card3&#8243; and “card4&#8243;. Rotate and place them like cards in the hand, the cards must overlap.</p>
<p>3. Create a new “actions” layer. With its first frame selected, open the actions panel.<br />
First we store the cards in an array :<br />
var cards : Array = [card1, card2, card3,card4];</p>
<p>&nbsp;</p>
<p>Then we loop through this array to add to each card a Mouse_DOWN event listener and set its buttonMode to true do display a hand cursor:<br />
for (var i:int = 0; i&lt; cards.length; i++){<br />
cards[i].addEventListener(MouseEvent.MOUSE_DOWN,bringToFront);<br />
cards[i].buttonMode = true;<br />
}<br />
4. Finally we need to write the bringToFront function.</p>
<p>In actionscript 3 all children of a container are placed from depth 0, 1 , 2 … to the highest one which is obtained with the numChildren property of the container minus one. ( minus one because depth begins with 0).<br />
If 2 movieclips overlap, the one with the greater depth comes in front of the other.</p>
<p>That explained, let’s write the function. We use the setChildIndex method to change the depth. We access the card that has processed the event by calling the currentTarget property of the event and cast it as a DisplayObjectContainer :</p>
<p>function bringToFront(e:MouseEvent) {<br />
setChildIndex(DisplayObjectContainer(e.currentTarget),numChildren &#8211; 1);<br />
}</p>
<p>&nbsp;</p>
<p>5. Here’s the final code, test the movie to see it in action.</p>
<p>&nbsp;</p>
<p>var cards : Array = [card1, card2, card3,card4];</p>
<p>for (var i:int = 0; i&lt; cards.length; i++){<br />
cards[i].addEventListener(MouseEvent.MOUSE_DOWN,bringToFront);<br />
cards[i].buttonMode = true;<br />
}</p>
<p>function bringToFront(e:MouseEvent) {<br />
setChildIndex(DisplayObjectContainer(e.currentTarget),numChildren &#8211; 1);<br />
}</p>
<p>&nbsp;</p>
<p>Final result:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="500" height="400" align="center">
      <param name="movie" value="http://bypixels.ro/wp-content/uploads/2010/10/cards.swf" />
      <param name="align" value="center" />
      <param name="wmode" value="opaque" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://bypixels.ro/wp-content/uploads/2010/10/cards.swf" width="500" height="400" align="center" wmode="opaque">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/manage-depth-with-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect collision between two objects</title>
		<link>http://bypixels.ro/blog/detect-collision-between-two-objects/</link>
		<comments>http://bypixels.ro/blog/detect-collision-between-two-objects/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 13:35:04 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[collision]]></category>
		<category><![CDATA[objects]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=208</guid>
		<description><![CDATA[Few lines of code that cover the technique on how you can detect collision between two objects with ActionScript 3. 1. First watch the demo to see what we are ...]]></description>
			<content:encoded><![CDATA[<p>Few lines of code that cover the technique on how you can detect collision between two objects with ActionScript 3.</p>
<p><span id="more-208"></span></p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="500" height="300" align="center">
      <param name="movie" value="http://bypixels.ro/wp-content/uploads/2010/10/detect_collision.swf" />
      <param name="align" value="center" />
      <param name="wmode" value="opaque" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://bypixels.ro/wp-content/uploads/2010/10/detect_collision.swf" width="500" height="300" align="center" wmode="opaque">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p>1. First watch the demo to see what we are going to create.<br />
Create a new flash file (Actionscript 3.0) and save it as detect_collision.fla.</p>
<p>2. On the stage create 2 movie clips, one for the car and one for the line. Set their instance name to respectively car_mc and line_mc.</p>
<p>3. Create a new layer named ‘actions’ and with its first frame selected open the actions panel.<br />
Paste the following code:</p>
<p>stage.addEventListener(KeyboardEvent.KEY_DOWN,moveCar);</p>
<p>function moveCar(evt:KeyboardEvent) {<br />
if (evt.keyCode == Keyboard.LEFT)  {<br />
car_mc.x -=8;<br />
if (car_mc.hitTestObject(line_mc)) {<br />
stage.removeEventListener(KeyboardEvent.KEY_DOWN,moveCar);<br />
}<br />
}<br />
}</p>
<p>4. Explainations We add a KeyboardEvent listener to the stage that call the moveCar function when the KEY_DOWN event is dispatched. In the moveCar function we check if the left arrow of the keyboard is down and if so we decrement the x property of the car. Next we call the hitTestObject method to evaluate if the car overlaps with the line. If so, we remove the KEY_DOWN event listener from the stage so that the car can’t be moved.</p>
<p>5. Test your movie to see it in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/detect-collision-between-two-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Endless scrolling background in AS3</title>
		<link>http://bypixels.ro/blog/endless-scrolling-background-in-as3/</link>
		<comments>http://bypixels.ro/blog/endless-scrolling-background-in-as3/#comments</comments>
		<pubDate>Tue, 05 Oct 2010 13:05:01 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[scroll]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=202</guid>
		<description><![CDATA[In this tutorial you will learn how to create an endless scrolling background in Actionscript 3 where an image will continue looping. I have used an image of some buildings ...]]></description>
			<content:encoded><![CDATA[<p>In this tutorial you will learn how to create an endless scrolling background in Actionscript 3 where an image will continue looping. I have used an image of some buildings for this tutorial, but any image will work.</p>
<p><span id="more-202"></span>Here&#8217;s the final preview:</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="400" height="300" align="center">
      <param name="movie" value="http://bypixels.ro/wp-content/uploads/2010/10/endless-scrolling.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://bypixels.ro/wp-content/uploads/2010/10/endless-scrolling.swf" width="400" height="300" align="center">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<p><strong>Step 1 </strong></p>
<p>Open a new AS3 file and import your image onto the stage by selecting <strong>File &gt; Import &gt; Import to Stage</strong>.</p>
<p><strong>Step 2</strong></p>
<p>Convert your image into a movie clip (F8). Then give an appropriate name, select the top left registration point. And click the ‘Export for Actionscript’ checkbox and give the class name: ScrollBg. Once you have create the movie clip delete it from the stage.</p>
<p><strong>Step 3</strong></p>
<p>Add the following code in the Actions panel.</p>
<p>&nbsp;</p>
<p>//The speed of the scroll movement.<br />
var scrollSpeed:uint = 2;</p>
<p>//This adds two instances of the movie clip onto the stage.<br />
var s1:ScrollBg = new ScrollBg();<br />
var s2:ScrollBg = new ScrollBg();<br />
addChild(s1);<br />
addChild(s2);</p>
<p>//This positions the second movieclip next to the first one.<br />
s1.x = 0;<br />
s2.x = s1.width;</p>
<p>//Adds an event listener to the stage.<br />
stage.addEventListener(Event.ENTER_FRAME, moveScroll);</p>
<p>//This function moves both the images to left. If the first and second<br />
//images goes pass the left stage boundary then it gets moved to<br />
//the other side of the stage.<br />
function moveScroll(e:Event):void{<br />
s1.x -= scrollSpeed;<br />
s2.x -= scrollSpeed;</p>
<p>if(s1.x &lt; -s1.width){<br />
s1.x = s1.width;<br />
}else if(s2.x &lt; -s2.width){<br />
s2.x = s2.width;<br />
}</p>
<p>}</p>
<p>&nbsp;</p>
<p><strong>Step 4</strong></p>
<p>Test your movie clip Ctrl + Enter.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">In this tutorial you will learn how to create an endless scrolling background in Actionscript 3 where an image will continue looping. I have used an image of some building for this tutorial, but any image will work.</div>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/endless-scrolling-background-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Specifying a Document Class</title>
		<link>http://bypixels.ro/blog/specifying-a-document-class/</link>
		<comments>http://bypixels.ro/blog/specifying-a-document-class/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 15:17:38 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[classes]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=110</guid>
		<description><![CDATA[In general, it is a good idea to keep all of your code away from the timeline in Flash. To put it differently, it is a bad idea to write ...]]></description>
			<content:encoded><![CDATA[<p>In general, it is a good idea to keep all of your code away from the timeline in Flash. To put it differently, it is a bad idea to write code on the timeline unless you really cannot avoid it. The main reason to avoid the timeline for code is that it is cleaner to separate your code from the more visual/animation-centric content that your timeline is really designed for.</p>
<p><span id="more-110"></span>Ever since you could keep your code in separate AS files, you were almost able to avoid placing any code on the timeline unless you really had to. I mention &#8220;almost&#8221; because, you always had to have some code somewhere in your Flash application to give your code in a separate AS file a jumpstart before it started running:</p>
<p><img class="aligncenter size-full wp-image-111" title="fla_dependency" src="http://bypixels.ro/wp-content/uploads/2010/10/fla_dependency.png" alt="" width="381" height="297" /></p>
<p>For example, the code that is associated with the dotted red line may have lived on the first frame of your timeline and looked something like this:</p>
<p>[cc lang="actionscript"]<br />
function start() {</p>
<p>var mainClass:ClassC = new ClassC();<br />
mainClass.goNuts();</p>
<p>}<br />
start();</p>
<p>[/cc]</p>
<p>Code like this seems pretty harmless. All I am doing is instantiating a class and calling a method in it &#8211; that&#8217;s it. The downside is that this adds a certain dependency to the main timeline that makes maintainance and editing more difficult.</p>
<p>Fortunately, one of the features introduced since Flash CS3 for ActionScript 3 projects is the ability to associate a particular class with your main Flash document. This means that you can now have a class file (dubbed the Document Class) instantiated and called automatically when your application is run without you having to do anything extra, and this tutorial will show you how!</p>
<p>Associating a New Class with a Document<br />
First, go ahead and launch Flash. I&#8217;m using Flash CS5, but the instructions should be similar for Flash CS3 onwards. Once you have launched Flash, create new ActionScript 3.0 project.</p>
<p>In the Properties panel, find the Class property:</p>
<p><img class="aligncenter size-full wp-image-112" title="classFieldProperties" src="http://bypixels.ro/wp-content/uploads/2010/10/classFieldProperties.png" alt="" width="284" height="290" /></p>
<p>In the textbox right next to it, enter the name of the class you want associated with this particular document. I’m going to go with the name MainDocument:</p>
<p><img class="aligncenter size-full wp-image-113" title="mainDocumentAppearance" src="http://bypixels.ro/wp-content/uploads/2010/10/mainDocumentAppearance.png" alt="" width="281" height="110" /></p>
<p>That&#8217;s all there is to it if you just wanted is a class to get created for you automatically when you run your application. We don&#8217;t want that for this case, because&#8230;well, what’s the fun in that? We want to see the code and make modifications to it!</p>
<p>To explicitly see your class so you can make changes to it, click on the pencil icon aka the Edit class definition button found right next to the textbox:</p>
<p><img class="aligncenter size-full wp-image-114" title="editButtonClassDefinition" src="http://bypixels.ro/wp-content/uploads/2010/10/editButtonClassDefinition.png" alt="" width="282" height="164" />Once you have clicked that button, you will see the AS code that makes up your MainDocument class appearing in the background. Click OK to close this dialog and be allowed to edit the code file that you see behind you:</p>
<p><img class="aligncenter size-full wp-image-115" title="codeFile_documentClass" src="http://bypixels.ro/wp-content/uploads/2010/10/codeFile_documentClass.png" alt="" width="454" height="307" />Before you call it a day and test your application, make sure both your FLA and this AS file are saved in the same folder on disk. By default, the ActionScript file that would have been created for you will be unsaved and unnamed.</p>
<p>Once you have saved both your FLA and AS file, you can test everything works by adding a small trace statement to your MainDocument constructor:</p>
<p>[cc lang="actionscript"]</p>
<p>package {</p>
<p>import flash.display.MovieClip;</p>
<p>public class MainDocument extends MovieClip {</p>
<p>public function MainDocument() {</p>
<p>// constructor code<br />
trace(&#8220;hello&#8221;);</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>[/cc]</p>
<p>If you test your application by pressing Ctrl + Enter, you’ll see that the trace statement defined in your class file gets invoked:</p>
<p><img class="aligncenter size-full wp-image-116" title="helloTextOutputWindow" src="http://bypixels.ro/wp-content/uploads/2010/10/helloTextOutputWindow.png" alt="" width="349" height="179" />What you have just done is designated a class file as your Document class. As Borat would say, &#8220;High five!&#8221;</p>
<p>Associating an Existing Class to the Document<br />
In the previous section, we looked at how you create a new class and have it be associated with your Flash document. In some cases, you may already have the class file you want to use already created. To associate an existing class file with your document, the steps are largely similar.</p>
<p>In the Class property, enter the name of the class file that you already created and want to use:</p>
<p><img class="aligncenter size-full wp-image-117" title="existingCLass" src="http://bypixels.ro/wp-content/uploads/2010/10/existingCLass.png" alt="" width="283" height="95" />Because you are associating a MovieClip (your main document) to the class, make sure your class extends the MovieClip type as shown earlier. Once you have done that, the constructor in your class will fire and everything will run from there.</p>
<p>Your class, though, may be in a different folder than the root of your FLA document. In these cases, you have to invoke the advanced ActionScript settings dialog. To do that, from the Properties panel, click the Edit button found next to ActionScript settings:</p>
<p><img class="aligncenter size-full wp-image-118" title="editButtonAdvancedSettings" src="http://bypixels.ro/wp-content/uploads/2010/10/editButtonAdvancedSettings.png" alt="" width="282" height="208" />Once you click that Edit button, the Advanced ActionScript 3.0 Settings dialog will appear. From this dialog, make sure the Source path tab is selected:</p>
<p><img class="aligncenter size-full wp-image-119" title="sourcePath" src="http://bypixels.ro/wp-content/uploads/2010/10/sourcePath.png" alt="" width="338" height="109" />This path by default shows the location of your FLA file. When you build your application, any class file references you make are resolved in this location. If your class file lives in another location, you can hit the plus button to add a new location, or you can simply hit the Browse to Path button and change the currently selected path:</p>
<p><img class="aligncenter size-full wp-image-120" title="pathManipulators" src="http://bypixels.ro/wp-content/uploads/2010/10/pathManipulators.png" alt="" width="338" height="109" /></p>
<p>As long as your referenced class file lives in one of the  					known Source path locations and contains a class that  					extends MovieClip, you are golden&#8230;like a retriever!</p>
<p><strong>Conclusion</strong><br />
If you all you  					are doing on the timeline is writing code to call another  					class file where all of your application&#8217;s logic lives,  					strongly consider associating a class file with your Flash  					Document and have any relevant code there instead of in the  					timeline.</p>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/specifying-a-document-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pause a movieclip in AS2</title>
		<link>http://bypixels.ro/blog/pause-a-movieclip-in-as2/</link>
		<comments>http://bypixels.ro/blog/pause-a-movieclip-in-as2/#comments</comments>
		<pubDate>Fri, 01 Oct 2010 13:43:44 +0000</pubDate>
		<dc:creator>Razvan</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[as2]]></category>
		<category><![CDATA[movieclips]]></category>

		<guid isPermaLink="false">http://bypixels.ro/?p=79</guid>
		<description><![CDATA[The easiest way to pause a movieclip inside your flash without affecting the rest of the stage is written few rows below. You just have to enter your movieclip (double ...]]></description>
			<content:encoded><![CDATA[<p>The easiest way to pause a movieclip inside your flash without affecting the rest of the stage is written few rows below.</p>
<p>You just have to enter your movieclip (double click it), create a new layer called &#8220;actions&#8221; or whatever you like to name it and paste the code on the frame you want your movieclip to pause.</p>
<p><span id="more-79"></span></p>
<p>&nbsp;</p>
<p>stop();</p>
<p>setTimeout(this,&#8221;play&#8221;,2000)</p>
<p>&nbsp;</p>
<p>You have the option to control how long the movieclip should pause simply by changing the value &#8220;2000&#8243; (in ms = 2s) to your desired value.</p>
]]></content:encoded>
			<wfw:commentRss>http://bypixels.ro/blog/pause-a-movieclip-in-as2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

