-
following a path in as3
I've looked and looked but i cannot find any way of using as3 scipt to make a movieclip follow a path. ANY help on this topic would be incredibly useful.
thanks
-
Senior Member
Create a guideline and make it a MovieClip. Give it the identifier mc. Then create a Movieclip for the object you want to move. Give it the identifier cr. Get the rgb value from the line, in particular red, which I used here. In my case it is 248. Then add this script and test movie.
PHP Code:
var moveArray:Array = new Array();
var cr:Circle;
var counter:int = 0;
var bmp:BitmapData = new BitmapData(mc.width,mc.height);
bmp.draw (mc);
for (var i:int = 0; i < mc.width; i++)
{
for (var j:int = 1; j < mc.height - 1; j++)
{
//var pixelValueString:String = bmp.getPixel32(i,j).toString(16);
var pixelValue:uint = bmp.getPixel32(i,j);
var red:uint = pixelValue >> 16 & 0xFF;
if (red == 248)
{
moveArray.push ({xpos:i,ypos:j});
}
}
}
var intervalId:uint = setTimeout(myDelayedFunction,100);
function myDelayedFunction ():void
{
cr = new Circle();
cr.x = moveArray[0].xpos;
cr.y = moveArray[0].ypos;
addChild (cr);
moveObject (moveArray);
}
function moveObject (mArray):void
{
var moveArray:Array = mArray;
var myTimer:Timer = new Timer(10,moveArray.length);
myTimer.addEventListener (TimerEvent.TIMER, timerFunction);
myTimer.start ();
function timerFunction (e:TimerEvent):void
{
cr.x = moveArray[counter].xpos + mc.x;
cr.y = moveArray[counter].ypos + mc.y;
counter++;
}
}
- The right of the People to create Flash movies shall not be infringed. -
-
thanks alot i like your way of doing it im gonna have a try and build this in
-
I think this is exactl what I need, and I can get it to work if I remove the fact that it's a circle,and just a path with only distinct X values.. and many Y values..
I get an error when I compile this..
1046: Type was not found or was not a compile-time constant: Circle
1180: Call to a possibly undefined method Circle..
I tried in AS2, and other errors popped up...
and,I tried to do a :
import flash.display.Shape;
but, that didn't do it eithere..
any help? or thoughts?/
Manson
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|