1 Replies - 1739 Views - Last Post: 17 July 2008 - 12:28 PM

#1 itdemo  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 16-May 08

Tween in AS 3

Posted 17 July 2008 - 10:15 AM

Hey all,
I have finnaly found a good tut on actionscript 3.0 (yay!!!) and have started learning it. My qusetion is this:
What i want is that when they click on a cloud (instance name: "cloud1_mc") it rotates and goes up the screen.
The way i am thinking of this is with a while statement eg.

cloud1_mc.addEventListener(MouseEvent.CLICK, onclick);

function onclick(event:MouseEvent):void
{
	while (cloud1_mc.y != -90) // -90 is the y posittion when the cloud is off the screen
	{
		// tween code
	}
}

cloud1_mc.buttonMode = true


what i did was i opened up a blank doc and did a motion tween in the timeline and then highlighted the frames and right-clicked copy motion as actionscript but what i got is this

import fl.motion.Animator;
var cloud1_mc_xml:XML = <Motion duration="50" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
	<source>
		<Source frameRate="30" x="141.4" y="103.05" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="mcCloud1">
			<dimensions>
				<geom:Rectangle left="-113.35" top="-98.4" width="226.7" height="196.8"/>
			</dimensions>
			<transformationPoint>
				<geom:Point x="0.5" y="0.5002540650406504"/>
			</transformationPoint>
		</Source>
	</source>

	<Keyframe index="0" tweenSnap="true" tweenSync="true">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="4" tweenSnap="true" tweenSync="true" y="-20" rotation="-6.8">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="9" tweenSnap="true" tweenSync="true" y="-40" scaleX="0.999" scaleY="0.999" rotation="-20.3">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="14" tweenSnap="true" tweenSync="true" y="-60" scaleX="0.998" scaleY="0.998" rotation="-38.6">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="19" tweenSnap="true" tweenSync="true" y="-80" scaleX="1" scaleY="1" rotation="-95.6">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="24" tweenSnap="true" tweenSync="true" y="-100" scaleX="0.999" scaleY="0.999" rotation="-116.3">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="29" tweenSnap="true" tweenSync="true" y="-126" scaleX="1" scaleY="1" rotation="-120">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="34" tweenSnap="true" tweenSync="true" x="0.09999999999999432" y="-145.85" scaleX="0.994" scaleY="0.994" rotation="-156.1">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="39" tweenSnap="true" tweenSync="true" x="0" y="-166" scaleX="1" scaleY="1" rotation="165">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="44" tweenSnap="true" tweenSync="true" y="-186" scaleX="0.999" scaleY="0.999" rotation="111.6">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="49" tweenSync="true" y="-193" rotation="152.7"/>
</Motion>;

var cloud1_mc_animator:Animator = new Animator(cloud1_mc_xml, cloud1_mc);
cloud1_mc_animator.play();



so what i did is i copy and pasted this into where i have written "//tween code" in the first code box and it didn't work (i just got a runtime error)

note i have my fps at 30 and 50 frames in the timeline with 5 frame intervals if you need anymore information just ask.

Thanks,
ITDemo

Is This A Good Question/Topic? 0
  • +

Replies To: Tween in AS 3

#2 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1148
  • View blog
  • Posts: 7,149
  • Joined: 07-September 06

Re: Tween in AS 3

Posted 17 July 2008 - 12:28 PM

So, from what I understand you put th ecode together like so:

import fl.motion.Animator;

cloud1_mc.addEventListener(MouseEvent.CLICK, onclick);

function onclick(event:MouseEvent):void
{
	var cloud1_mc_xml:XML = <Motion duration="50" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
	<source>
		<Source frameRate="30" x="141.4" y="103.05" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="mcCloud1">
			<dimensions>
				<geom:Rectangle left="-113.35" top="-98.4" width="226.7" height="196.8"/>
			</dimensions>
			<transformationPoint>
				<geom:Point x="0.5" y="0.5002540650406504"/>
			</transformationPoint>
		</Source>
	</source>

	<Keyframe index="0" tweenSnap="true" tweenSync="true">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="4" tweenSnap="true" tweenSync="true" y="-20" rotation="-6.8">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="9" tweenSnap="true" tweenSync="true" y="-40" scaleX="0.999" scaleY="0.999" rotation="-20.3">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="14" tweenSnap="true" tweenSync="true" y="-60" scaleX="0.998" scaleY="0.998" rotation="-38.6">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="19" tweenSnap="true" tweenSync="true" y="-80" scaleX="1" scaleY="1" rotation="-95.6">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="24" tweenSnap="true" tweenSync="true" y="-100" scaleX="0.999" scaleY="0.999" rotation="-116.3">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="29" tweenSnap="true" tweenSync="true" y="-126" scaleX="1" scaleY="1" rotation="-120">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="34" tweenSnap="true" tweenSync="true" x="0.09999999999999432" y="-145.85" scaleX="0.994" scaleY="0.994" rotation="-156.1">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="39" tweenSnap="true" tweenSync="true" x="0" y="-166" scaleX="1" scaleY="1" rotation="165">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="44" tweenSnap="true" tweenSync="true" y="-186" scaleX="0.999" scaleY="0.999" rotation="111.6">
		<tweens>
			<SimpleEase ease="0"/>
		</tweens>
	</Keyframe>

	<Keyframe index="49" tweenSync="true" y="-193" rotation="152.7"/>
</Motion>;

var cloud1_mc_animator:Animator = new Animator(cloud1_mc_xml, cloud1_mc);
cloud1_mc_animator.play();
}

cloud1_mc.buttonMode = true


And it didn't work?

Forgive me, I haven't actually used AS 3 at this point (too poor to get Flash CS3), but if that doesn't word you could always try creating a tween path (or whatever they are called) at which point I think it may work out like you are wanting.

Otherwise you could try to do a loop type of thing (but use onEnterFrame insted of while) to make sure that it is updated as it should be. Like so:

cloud1_mc.addEventListener(MouseEvent.CLICK, onclick);

function onclick(event:MouseEvent):void{
   cloud1_mc.onEnterFrame = function():void{
	  if(this._y>-90){
		  this._y--;
	  }
	  else{
		 delete this.onEnterFrame;
	  }
   }
}

cloud1_mc.buttonMode = true


Hopefully you get the jest of that, it is probably closer to AS 2 than 3, but as I said, I don't know AS 3...

Hope that helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1