A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Little help with addChild

  1. #1
    Junior Member
    Join Date
    Aug 2016
    Posts
    8

    Little help with addChild

    Hello everybody!
    I am trying to make a rain effect (kind of), and i don't know how to set the drops quantity based on a variable.
    This is the code i did so far:

    Code:
    addEventListener(Event.ENTER_FRAME, onEnterFrame);
    function onEnterFrame(event): void {
    	drop[i] = new drop();
    	addChild(drop[i]);
    	//Random position of drop
    	drop[i].y = Math.random() * stage.stageHeight;
    	drop[i].x = Math.random() * stage.stageWidth;
    }
    Maybe the problem here is the enterframe, infact ofcourse it creates more drops if i raise the frames per second of the swf.
    I would like to stay 30 frames per second, but i also would like to choose how many drops are created.

    Another big problem is that i want to remove the drop after a while with a command inside the MC itself, and putting inside that drop MC the line:

    Code:
    this.parent.removeChild(this);
    it does not work

    Any hint for both things please?
    Thanks a lot!

  2. #2
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    putting inside that drop MC the line
    this totally works, I did it myself before.

    drop[i] = new drop();
    this makes no sense.

    I would like to stay 30 frames per second, but i also would like to choose how many drops are created.
    add "for (var i:int = 0; i < 5; i++) { ... }" around your code
    who is this? a word of friendly advice: FFS stop using AS2

  3. #3
    Junior Member
    Join Date
    Aug 2016
    Posts
    8
    Quote Originally Posted by realMakc View Post
    this totally works, I did it myself before.
    ypeError: Error #1009: Cannot access a property or method of a null object reference. at DROP/frame10()

  4. #4
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    927
    maybe you do it twice, e g because your mc timeline loops. put a stop() there, or do if (this.parent != null) check
    who is this? a word of friendly advice: FFS stop using AS2

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