A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Falling Elements

  1. #1
    Junior Member
    Join Date
    Nov 2003
    Location
    England >> Whitchurch
    Posts
    24

    Falling Elements

    Hi

    How can i make an element fall and when it hits another element called the ground, the falling element goes back up to the top at a random x location?

    Thanks
    Mousie

  2. #2
    \/\/EB/\/\ASTER lukesquall's Avatar
    Join Date
    May 2003
    Location
    Solitude
    Posts
    683
    code:
    onClipEvent(enterFrame){
    this._y += 3;
    if(this.hitTest(_root.ground)){
    reset(); }
    function reset(){
    this._y = 0;
    this._x = random(); }}


  3. #3
    Junior Member
    Join Date
    Nov 2003
    Location
    England >> Whitchurch
    Posts
    24

    falling elements

    I could not get that to work i tried:

    var rain = element("rain")
    onClipEvent(enterFrame){
    >>>>>>>>rain._y += 3;
    >>>>>>>>if(rain.hitTest(_root.ground)){
    >>>>>>>>>>>>>>>>reset(); }
    >>>>>>>>function reset(){
    >>>>>>>>>>>>>>>>rain._y = 0;
    >>>>>>>>>>>>>>>>rain._x = random(640); }}

    i used the >'s to show indentation
    Last edited by mousie_kebabs; 11-20-2003 at 01:09 PM.

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    first create a movie clip of the symbol you want to move down the stage. next select this clip and press F9 to open the actions panel and then enter the following,

    code:

    onClipEvent(load) {
    function reset() {
    this._x = Math.round(Math.random() * 500); // set a random x position between 0 and 500 (where 500 is the width of your movie)
    this._y = -5; // reset to be just off the top of the stage
    this.speed = Math.ceil(Math.random() * 5) + 1; // a random speed the clip should descend by (between 2 and 6)
    }
    this.reset();
    }
    onClipEvent(enterFrame) {
    if (this._y > 400) { // where 400 is the height of your movie
    this.reset(); // start again from the top
    }
    this._y += this.speed;
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center