<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[ChipMusic.org - Flash actionscript 3.0 help]]></title>
		<link>https://chipmusic.org/forums/topic/269/flash-actionscript-30-help/</link>
		<description><![CDATA[The most recent posts in Flash actionscript 3.0 help.]]></description>
		<lastBuildDate>Tue, 02 Feb 2010 18:43:50 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link>https://chipmusic.org/forums/post/8484/#p8484</link>
			<description><![CDATA[<b><i>xero says:</i></b><p>ok,<br />so lets assume you have a movieclip called &quot;SomeMovieClip&quot;<br />that is 20 frames total. and you want it to play frame 1-10<br />before the click, and 11 = 20 after the click, and you want the<br />click event to toggle the boolean, this code *should* work...<br />(i wrote this in the comment box, so i haven&#039;t tested it)</p><div class="codebox"><pre><code>var clicked:Boolean = false;
var mc:MovieClip = new SomeMovieClip();
mc.x = mc.y = 100;
mc.addEventListener(MouseEvent.CLICK, onClick);
addChild(mc);

this.addEventListener(Event.ENTER_FRAME, loop);

private function onClick(e:MouseEvent):void {
   if (clicked) { 
     clicked = false;
   } else {
     clicked = true;
}

private function loop(e:Event):void {
  if(!clicked) {
     if(mc.currentFrame &gt; 10) {
         mc.nextFrame();
     } else {
         mc.gotoAndStop(1);
     }
  } else {
     if(mc.currentFrame &lt; 21) {
         mc.nextFrame();
     } else {
         mc.gotoAndStop(11);
     }
  }
}</code></pre></div><p>thinking about the code i just posted,<br />yew can actually to the same thing faster<br />and more efficiently with this code...</p><div class="codebox"><pre><code>var clicked:Boolean = false;
var mc:MovieClip = new SomeMovieClip();
mc.x = mc.y = 100;
mc.play();
mc.addEventListener(MouseEvent.CLICK, onClick);
addChild(mc);

addEventListener(Event.ENTER_FRAME, loop);

private function onClick(e:MouseEvent):void {
   //--inline conditionals FTW!
   clicked = (clicked) ? (false) : (true);
}

private function loop(e:Event):void {
  if(!clicked) {
     if(mc.currentFrame == 10) {
         mc.gotoAndPlay(1);
     }
  } else {
     if(mc.currentFrame == 20) {
         mc.gotoAndPlay(11);
     }
  }
}</code></pre></div><p>so what&#039;s the difference? <br />well the onClick function now uses an inline conditional<br />verses the classic if/else statement (a bit faster + less code).<br />also im letting flash handle the animation as opposed to<br />letting our code to the logic. in the first example in the <br />enterframe loop, im checking the movieclips current frame<br />then incrementing or resetting it. while in the second <br />example im just checking the current frame. when the<br />check condition fails THEN i take action, as opposed to<br />taking action on every frame loop. will that make a huge<br />difference? not in this example. but if you were doing this<br />many many times per frame it would start to...</p><p>i hope that helps!</p>]]></description>
			<pubDate>Tue, 02 Feb 2010 18:43:50 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/8484/#p8484</guid>
		</item>
		<item>
			<title><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link>https://chipmusic.org/forums/post/3548/#p3548</link>
			<description><![CDATA[<b><i>DKSTR says:</i></b><p>Hmm..</p><p>I meant </p><p>that you have for example three layers in your animation</p><p>1. a _ _ _ _ _ _ _ _ _ _ _ _ _ _ _<br />2. b u t t o n _ _ _ _ _ _ _ _ _ _<br />3. u r l o o p _ _ _ _ _ _ _ _ _ _ _</p><p>1. your actionscript layer (a marking the first frame where you put your code)<br />2. your invisible button that is equal to the frames of your looping animation (NOTE: make your button as movieclip, it doesnt matter in AS3)<br />3. your animation</p><p>name your button-movieclips instance name as button1 or something and just paste this code:<br /></p><div class="codebox"><pre><code>import flash.events.MouseEvent;

animation1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

function mouseDownHandler(event:MouseEvent):void
{
    animation1.gotoAndPlay(47);
}</code></pre></div><p>And bam, it works. I just tested it in like 5 minutes. Your second piece of code looks really complicated and I dont really understand it. Then again, I&#039;m graphic designer and only do this when I have to:)</p>]]></description>
			<pubDate>Wed, 13 Jan 2010 08:55:54 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/3548/#p3548</guid>
		</item>
		<item>
			<title><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link>https://chipmusic.org/forums/post/3220/#p3220</link>
			<description><![CDATA[<b><i>pixls says:</i></b><p>thanks for your help, but i think i&#039;m totally inept<br />so, naturally i started something completely different!<br />i now have on a layer separate from everything else<br />a big invisible square called &quot;button&quot;<br />and in that layer the following:<br /></p><div class="codebox"><pre><code>import flash.events.MouseEvent;

button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

function get buttonDown():Boolean 
function set buttonDown(value:Boolean):void
{
if (buttonDown) {
    static.gotoAndPlay(47);
}
else {
    gotoAndPlay(1);
}
}</code></pre></div><p>i&#039;m getting and error &quot;1126: Function does not have a body.&quot; for&nbsp; the line</p><p>i might be doing something completely wrong, but i have no idea.</p>]]></description>
			<pubDate>Tue, 12 Jan 2010 18:14:18 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/3220/#p3220</guid>
		</item>
		<item>
			<title><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link>https://chipmusic.org/forums/post/3043/#p3043</link>
			<description><![CDATA[<b><i>DKSTR says:</i></b><div class="quotebox"><cite>pixls wrote:</cite><blockquote><p>so i have a flash animation that i&#039;m working with,<br />and i want to be able to have one section of it loop until i press a key or click the mouse or something<br />i have a <br /></p><div class="codebox"><pre><code>gotoAndPlay(1);</code></pre></div><p>to do the loop, and then I&#039;ve tried several things, right now, in a separate layer from the loop, i have<br /></p><div class="codebox"><pre><code>import flash.events.MouseEvent;

addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

function mouseDownHandler(event:MouseEvent):void
{
    gotoAndPlay(47);
}</code></pre></div><p>to try and make it jump to the next portion</p><p>i don&#039;t really know what i&#039;m doing so any help would be appreciated</p></blockquote></div><p>In AS3 you need to have instance names (bottom left corner on preferences of movieclip) on movieclips.</p><p>So If you have a movieclip with your animation in it and you would name it animation1 or something:</p><div class="codebox"><pre><code>import flash.events.MouseEvent;

animation1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

function mouseDownHandler(event:MouseEvent):void
{
    animation1.gotoAndPlay(47);
}</code></pre></div><p>oh, and put that code on root-level of your .fla, it&#039;s easier to modify it later that way and easier to refer on movieclips inside other movieclips etc:)</p><p>If you dont have your animation on movieclip then you would need to do a invisible button over your animation and refer to the buttons instance name on your code.</p>]]></description>
			<pubDate>Tue, 12 Jan 2010 08:27:39 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/3043/#p3043</guid>
		</item>
		<item>
			<title><![CDATA[Flash actionscript 3.0 help]]></title>
			<link>https://chipmusic.org/forums/post/3019/#p3019</link>
			<description><![CDATA[<b><i>pixls says:</i></b><p>so i have a flash animation that i&#039;m working with,<br />and i want to be able to have one section of it loop until i press a key or click the mouse or something<br />i have a <br /></p><div class="codebox"><pre><code>gotoAndPlay(1);</code></pre></div><p>to do the loop, and then I&#039;ve tried several things, right now, in a separate layer from the loop, i have<br /></p><div class="codebox"><pre><code>import flash.events.MouseEvent;

addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);

function mouseDownHandler(event:MouseEvent):void
{
    gotoAndPlay(47);
}</code></pre></div><p>to try and make it jump to the next portion</p><p>i don&#039;t really know what i&#039;m doing so any help would be appreciated</p>]]></description>
			<pubDate>Tue, 12 Jan 2010 06:58:27 +0000</pubDate>
			<guid>https://chipmusic.org/forums/post/3019/#p3019</guid>
		</item>
	</channel>
</rss>
