<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[ChipMusic.org - Flash actionscript 3.0 help]]></title>
	<link rel="self" href="https://chipmusic.org:80/forums/feed/atom/topic/269/"/>
	<updated>2010-02-02T18:43:50Z</updated>
	<generator>PunBB</generator>
	<id>https://chipmusic.org/forums/topic/269/flash-actionscript-30-help/</id>
		<entry>
			<title type="html"><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/8484/#p8484"/>
			<content type="html"><![CDATA[<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>]]></content>
			<author>
				<name><![CDATA[xero]]></name>
				<uri>https://chipmusic.org/xero</uri>
			</author>
			<updated>2010-02-02T18:43:50Z</updated>
			<id>https://chipmusic.org/forums/post/8484/#p8484</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/3548/#p3548"/>
			<content type="html"><![CDATA[<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>]]></content>
			<author>
				<name><![CDATA[DKSTR]]></name>
				<uri>https://chipmusic.org/DKSTR</uri>
			</author>
			<updated>2010-01-13T08:55:54Z</updated>
			<id>https://chipmusic.org/forums/post/3548/#p3548</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/3220/#p3220"/>
			<content type="html"><![CDATA[<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>]]></content>
			<author>
				<name><![CDATA[pixls]]></name>
				<uri>https://chipmusic.org/pixls</uri>
			</author>
			<updated>2010-01-12T18:14:18Z</updated>
			<id>https://chipmusic.org/forums/post/3220/#p3220</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Flash actionscript 3.0 help]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/3043/#p3043"/>
			<content type="html"><![CDATA[<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>]]></content>
			<author>
				<name><![CDATA[DKSTR]]></name>
				<uri>https://chipmusic.org/DKSTR</uri>
			</author>
			<updated>2010-01-12T08:27:39Z</updated>
			<id>https://chipmusic.org/forums/post/3043/#p3043</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Flash actionscript 3.0 help]]></title>
			<link rel="alternate" href="https://chipmusic.org/forums/post/3019/#p3019"/>
			<content type="html"><![CDATA[<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>]]></content>
			<author>
				<name><![CDATA[pixls]]></name>
				<uri>https://chipmusic.org/pixls</uri>
			</author>
			<updated>2010-01-12T06:58:27Z</updated>
			<id>https://chipmusic.org/forums/post/3019/#p3019</id>
		</entry>
</feed>
