# Problem Creating a Background

**URL:** <https://forum.kirupa.com/t/problem-creating-a-background/330626>\
**Category:** flash\
**Created:** [February 19, 2013, 10:12pm UTC](https://forum.kirupa.com/t/problem-creating-a-background/330626 "2013-02-19T22:12:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Blablob](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@Blablob](https://forum.kirupa.com/u/Blablob)\
**Post date:** [February 19, 2013, 10:12pm UTC](https://forum.kirupa.com/t/problem-creating-a-background/330626/1 "2013-02-19T22:12:25Z")

</div>

Hi everyone. I’m working in FlashDevelop and I have a question about an issue I’ve run into. (I posted this question in the FlashDevelop community and they recommended I bring the discussion over here).

I’m trying to design a space-like background in which particles fly down the screen. I have created a Background class and I’m using sprites to generate the particles. When they fly off-screen (say, when y \> 420) I want them to disappear, but I can’t seem to figure out how. Here is the code for the Background class:

```auto
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.display.MovieClip;
    
    public class Background extends Sprite
    {
        private var background:Sprite = new Sprite;
        private var speed:int = 2;
        private var _root:Object;
        
        public function Background():void
        {
            _root = MovieClip(root);
            addEventListener(Event.ADDED, create);
            addEventListener(Event.ENTER_FRAME, move);
        }
        
        private function create(e:Event):void
        {
            var size:int = Math.random() * 10;
            var position:int = Math.random() * 600;
            background.graphics.drawRect(0, 0, size,size);
            background.graphics.beginFill(0xFFED09, 1);
            background.x = position;
            background.y = -20;
            addChild(background);
        }
        
        private function move(e:Event):void
        {
            this.y += speed;
            if (this.y > 120)
            {
                removeEventListener(Event.ENTER_FRAME, move);
                _root.removeChild(this);
            }
        }
    }
}

```

The program will crash when y\>120. (I’ve set 120 for ease of testing.)
