Categories
Featured jobs
» More ActionScript, Flash and Flex jobs.
» Advertise a job for free
Our network
Advertisement

 »  Home  »  Tutorials  »  Flash  »  Beginner  »  Tutorial on Creating Following Objects.

Tutorial on Creating Following Objects.

By Pratik. Velani | Published 12/31/1969 | Beginner | Rating:
Lesson 1 : Following Mouse W/O Ease.
    Creating a movie clip :
    Create new flash document.


    Draw a circle using the oval tool.


   

    Select the circle using double click. Press F8 to convert to symbol.


    Part 1 :
   
       Click on the circle and Press F9. Actionscript Panel will open. Insert the following actionscript.

onClipEvent(enterFrame){
    diffx = _root._xmouse - this._x ;
    diffy = _root._ymouse - this._y ;
    _x += diffx ;
    _y += diffy ;
}



    Explanation about the code

_xmouse :   returns the x coordinate of the mouse.
_ymouse :  
returns the y coordinate of the mouse.
_x            :  
An integer that sets / stores the x coordinate of an object.
_y            :  
An integer that sets / stores the y coordinate of an object.

    variable diffx & diffy is used to store the distance between mouse's x & cordinate and object's x & y cordinate respectively.
     _x += diffx ;
    Assigns _x , the value of _x + diffx .
    _y += diffy ;
    Assigns _y , the value of _y + diffy .



    Part 2 :

replace

_x += diffx ;


_y += diffy ;


with

_x += diffx / 5 ;

_y += diffy / 5 ;


Explanation of code :

_x += diffx / 5 ;
    Assign _x , the value of _x + diffx / 5 ;( dividing the diffrence with a number decreases the speed of movment. Higher the number lower the speed. )
_y += diffy / 5 ;
    Assign _y , the value of _y + diffy / 5 ;( dividing the diffrence with a number decreases the speed of movment. Higher the number lower the speed. )




Spread The Word / Bookmark this content

Clesto Digg it! Reddit Furl del.icio.us Spurl Yahoo!

Comments
  • Comment #1 (Posted by an unknown user)
    Rating
    Trailing portion does not work in Flash 8
     
Submit Comment



Search Entire Site
Add to Google
Advertisements
Article Options
Latest New Articles
Set up a simple IIS Server for Flash
by Peter McBride

Day 1 at FITC Toronto 2008
by Anthony Pace

Simple reflection effect with AS2
by Jean André Mas

ActionScript.org Meets Josh Tynjala (aka dr_zeus)
by ActionScript.org Staff

Rapidly Create Online Flash Movies to Help Users Market, Sell and Support Software and Hardware
by Sabrina F

mailing list
Enter your email address:
mailing list
Subscribe Unsubscribe
© 2000-2007 actionscript.org! All Rights Reserved.
Read our Privacy Statement and Terms of Use...
Our dedicated server is hosted and managed by WebScorpion Webhosting.