# Parallaxed Starfield

**URL:** <https://forum.kirupa.com/t/parallaxed-starfield/238099>\
**Category:** flash\
**Created:** [September 7, 2007, 6:34am UTC](https://forum.kirupa.com/t/parallaxed-starfield/238099 "2007-09-07T06:34:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wjaspers](https://avatars.discourse-cdn.com/v4/letter/w/e19b73/32.png) [@wjaspers](https://forum.kirupa.com/u/wjaspers)\
**Post date:** [September 7, 2007, 6:34am UTC](https://forum.kirupa.com/t/parallaxed-starfield/238099/1 "2007-09-07T06:34:05Z")

</div>

Is it possible to generate a starfield that can be parallaxed with the mouse?

if so, can someone help me code this or send me in the right direction. thanks!

NOTE: star is a movieClip in my library which is set to export with actionscript

current code to generate a static starfield

```auto

//import mx. :: I don't recall this exact line of code, but it imports the mx Tween class
import mx.Transitions.*;

var stars:Array = new Array();
var MAX_STARS = 250; // how many stars are allowed on stage at once
var MAX_STAR_SCALE = 4; // the maximum size of a star

for(var i=0; i<MAX_STARS;i++)
{
  // draw a new star on stage 
  newStar = _root.attachMovie( 'star', 'star'+i, i*1000 );

  // adjust the star's position on stage
  newStar._x = Math.ceil(Math.random()*Stage._width);
  newStar._y = Math.ceil(Math.random()*Stage._height);
  
  // resize the star to create false distance
  // our star can be a maximum of 4 times the original star's size
  newStar._width = newStar._width*Math.floor(Math.random()*MAX_STAR_SCALE);
  newStar._height = newStar._height*Math.floor(Math.random()*MAX_STAR_SCALE);

  // fade the star out and in as the mouse falls over it
  newStar.onRollOver = function()
  {
     // create the tween
     t = new Tween( this, "_alpha", Regular.easeIn, 0, 100, 1, true );
     t.continueTo(0, 1); // fade out
     t.continueTo(100, 1); // fade in
  }

  // just for fun, we can make the star explode when clicked
  newStar.onRelease = function()
  {
     // explode the star
     scaleY = new Tween( this, "_height", Bounce.easeIn, 0, 100, 1, true);
     scaleX = new Tween( this, "_width", Bounce.easeIn, 0, 100, 1, true);
     scale = Math.ceil(Math.random()*100);
     scaleY.continueTo( scale * this._height, .5 );
     scaleX.continueTo( scale * this._width, .5 );

     // fade and die
     fade = new Tween( this, "_alpha", Regular.easeOut, 100, 0, 1, true);
     fade.continueTo( 0, 2 );

     // take the star out of memory
     unloadMovie(this);
  }

  // add our new star to a storage container for later use
  stars.push( newStar );
}

```
