开发者

ActionScript 2 character selection

开发者 https://www.devze.com 2023-03-22 05:51 出处:网络
I haven\'t been able to make a character selection in ActionScript 2 so开发者_开发技巧 what is an example that, if I click on this button, a movieclip comes out in this frame?Frame 1:

I haven't been able to make a character selection in ActionScript 2 so开发者_开发技巧 what is an example that, if I click on this button, a movieclip comes out in this frame?


Frame 1:

movieClip1.alpha = 0;
movieClip1.stop();
movieClip2.alpha = 0;
movieClip2.stop();
movieClip3.alpha = 0;
movieClip3.stop();
button1.onPress = function() {
movieClip1.alpha = 100;
movieClip1.play();
}
button2.onPress = function() {
movieClip2.alpha = 100;
movieClip2.play();
}
button3.onPress = function() {
movieClip3.alpha = 100;
movieClip3.play();
}


try something like the below. I haven;t tested this so it prob won;t compile but it'll be very close. Basically put this on a single empty frame on the main timeline. make sure you have button and character movieclips all with export settings and linkage identifiers set. Modify code below and see what happens.

var numButtons:Number = 10; //number of buttons you want
var buttonMovieClipName:String = "button"; //linkage identifier of button
var startX:Number = 10; //start x position
var startY:Number = 500;  //start y position
var dist:Number = 10; //distance between buttons
var characters:Array = {"A","B","C","D"};  //linkage names of your characters
var currentChar:MovieClip = null;

for(var i:Number = 0; i < numButtons; i++)
{
   this.attachMovie("button", "button"+i, this.getNextHighestDepth());
   this["button"+i]._x = startX + (i*(dist+this["button"+i]._width]));        
   this["button"+i]._y = startY;
   this["button"+i].character = characters[i];
   this["button"+i].onPress = displayCharacter; 
}

function displayCharacter():void
{
   var par = this._parent;

   //remove previous character on stage
   if(currentChar != null)
   {
       removeMovieClip(par[currentChar]);
   }

   par.attachMovie(this.character, this.character, par.getNextHighestDepth()); //atach character
   par[this.character]._x = 400;  //set to whatever
   par[this.character]._y = 300;  //set to whatever
   currentChar = this.character; //set current character to this
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号