# Movieclip button help please (for the desperate and lame)

**URL:** <https://forum.kirupa.com/t/movieclip-button-help-please-for-the-desperate-and-lame/202896>\
**Category:** Uncategorized\
**Created:** [October 5, 2006, 5:39pm UTC](https://forum.kirupa.com/t/movieclip-button-help-please-for-the-desperate-and-lame/202896 "2006-10-05T17:39:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![skellykitten](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@skellykitten](https://forum.kirupa.com/u/skellykitten)\
**Post date:** [October 5, 2006, 5:39pm UTC](https://forum.kirupa.com/t/movieclip-button-help-please-for-the-desperate-and-lame/202896/1 "2006-10-05T17:39:09Z")

</div>

I’m really new to actionscript.I have a problem figuring out where to place code, and how to structure or format it so it works correctly. ANyway I’m making this movie, and it goes like this:  
I have 2 layers on the main time line, one for movie clips and another for actionscript. On the first frame of the movie clips layer I have movieclip of a gradient rectangle.  
On the first frame of the actionscript layer I have this code (which I got off a board somewhere…can’t remember where)

```auto
var numStars:Number = 500;
this.createEmptyMovieClip("starField_mc", 1);
var dice:Number;
for (i=1; i<=numStars; i++) {
    _root.starField_mc.attachMovie("star", "star"+i, i, {_x:Math.random()*Stage.width, _y:Math.random()*Stage.height, _alpha:Math.random()*100});
    _root.starField_mc["star"+i].tranSpeed = Math.round(Math.random()*10+5);
    _root.starField_mc["star"+i].onEnterFrame = function() {
        twinkle(this);
        if (this.tranDir == 0) {
            this._alpha += this.tranSpeed;
            if (this._alpha>100) {
                this.tranDir = 1;
            }
        } else {
            this._alpha -= this.tranSpeed;
            if (this._alpha<60) {
                this.tranDir = 0;
            }
        }
    };
}
function twinkle(clip) {
    //roll a dice 1-500
    //1 in 500 chance of twinkling
    dice = Math.round(Math.random()*500);
    if (dice == 1) {
        clip.play();
    }
}

```

This makes a starry background from some of the movieclips in the library. The only problem here is that it goes over top of anything placed on the stage. I played around with the depth and such for a while, and could fix it, so I started trying other stuff. It ended up I had to use “createEmptyMovieClip” and “this.getNextHighestDepth” to place anything on top of the stars clip, so I started using this code for anything I wanted to put on the stage

```auto
//this puts movie clip on top of stars- requires linkage (Tent animation)
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
this.attachMovie("Tent main", "container", this.getNextHighestDepth(), {_x:350, _y:250});

// movie clips to be Buttons....jpgs loaded externally
this.createEmptyMovieClip("movieholder1", this.getNextHighestDepth());
loadMovie("fatlady_btn.jpg","movieholder1");
    this.movieholder1._x=150;
    this.movieholder1._y=100;
    
    
    this.createEmptyMovieClip("movieholder2", this.getNextHighestDepth());
loadMovie("tattoo_btn.jpg","movieholder2");
    this.movieholder2._x=50;
    this.movieholder2._y=200;
    
    this.createEmptyMovieClip("movieholder3", this.getNextHighestDepth());
loadMovie("2headed_btn.jpg","movieholder3");
    this.movieholder3._x=465;
    this.movieholder3._y=95;
    
    this.createEmptyMovieClip("movieholder4", this.getNextHighestDepth());
loadMovie("alliglady_btn.jpg","movieholder4");
    this.movieholder4._x=550;
    this.movieholder4._y=200;
    

```

movieholder1-4 are suppose to be buttons, which is where I’m having the problems.  
I created another empty movie clip to load external swf’s in

```auto
    this.createEmptyMovieClip("mainmovie",2);
with (mainmovie)
    {
  _x=350;
  _y=200;
  _width = 200;
  _height= 243;
}

```

but whatever code I put on the button/movieclips, it doesn’t work, can anyone help? I think the reason this is giving me so much trouble is because I’m placing the mc’s on stage with actionscript- I know how to make a movieclip a button when I drag it on stage, but like I said dragging things on stage puts it behind the stars.  
I’m a loser and have a hard time understanding code- but I’m really trying to learn. I know I’ve probably made this way more complicated than it needs to be.  
Any help would be appreciated- I’ll put the entirecode here

```auto
var numStars:Number = 500;
this.createEmptyMovieClip("starField_mc", 1);
var dice:Number;
for (i=1; i<=numStars; i++) {
    _root.starField_mc.attachMovie("star", "star"+i, i, {_x:Math.random()*Stage.width, _y:Math.random()*Stage.height, _alpha:Math.random()*100});
    _root.starField_mc["star"+i].tranSpeed = Math.round(Math.random()*10+5);
    _root.starField_mc["star"+i].onEnterFrame = function() {
        twinkle(this);
        if (this.tranDir == 0) {
            this._alpha += this.tranSpeed;
            if (this._alpha>100) {
                this.tranDir = 1;
            }
        } else {
            this._alpha -= this.tranSpeed;
            if (this._alpha<60) {
                this.tranDir = 0;
            }
        }
    };
}
function twinkle(clip) {
    //roll a dice 1-500
    //1 in 500 chance of twinkling
    dice = Math.round(Math.random()*500);
    if (dice == 1) {
        clip.play();
    }
}

//movieholder for slideshow
    this.createEmptyMovieClip("mainmovie",2);
with (mainmovie)
    {
  _x=350;
  _y=200;
  _width = 200;
  _height= 243;
}

//this puts movie clip on top of stars- requires linkage (Tent animation)
var container:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
this.attachMovie("Tent main", "container", this.getNextHighestDepth(), {_x:350, _y:250});

//Buttons....jpgs loaded externally
this.createEmptyMovieClip("movieholder1", this.getNextHighestDepth());
loadMovie("fatlady_btn.jpg","movieholder1");
    this.movieholder1._x=150;
    this.movieholder1._y=100;
    
    
    this.createEmptyMovieClip("movieholder2", this.getNextHighestDepth());
loadMovie("tattoo_btn.jpg","movieholder2");
    this.movieholder2._x=50;
    this.movieholder2._y=200;
    
    this.createEmptyMovieClip("movieholder3", this.getNextHighestDepth());
loadMovie("2headed_btn.jpg","movieholder3");
    this.movieholder3._x=465;
    this.movieholder3._y=95;
    
    this.createEmptyMovieClip("movieholder4", this.getNextHighestDepth());
loadMovie("alliglady_btn.jpg","movieholder4");
    this.movieholder4._x=550;
    this.movieholder4._y=200;        
    

```

Thanks again to whoever can help:)
