无法使用符号时间轴

时间:2018-04-24 17:17:01

标签: actionscript-3 flash flash-builder flash-cs5

我是编码的新手,我很难找到答案。

基本上,我正在尝试使用ActionScript 3在Flash CS5.5中制作装扮游戏。目前的问题是我试图通过不同的服装使颜色持久(例如:如果你有一个蓝色的T恤,然后换成连衣裙,连衣裙应该是蓝色的。如果你把连衣裙的颜色变成红色,然后换回T恤,那么T恤现在应该是红色的。)

我正在使用我在Photoshop中创建的资源,并且我将所有资源都放在Movie Clip符号中(因此所有T恤都在Symbol T恤内,所有礼服都在Symbol Dress内等) ;最重要的是,我将所有相同颜色的衣服放在各自符号的相同关键帧编号中(所有红色衣服都在关键帧1中,所有蓝色衣服都在关键帧2中,等等。)

我想要做的是在玩家点击颜色按钮时为符号时间轴中的变量分配一个数字,然后在主时间轴中读取变量,将该变量存储在主时间轴中的另一个变量中因此,即使符号发生变化,它仍然存在,然后让另一个符号读取主时间轴上的变量,以应用于告诉它去哪里的函数。

我目前的问题是,我不能为我的生活中的主时间轴上的变量读取符号上的变量,因此不会更新。

以下是代码:

//MAIN SCENE SCRIPT

//STOP EVERYTHING FROM STARTING
stop();

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//DECLARE COLOR VARIABLE IN MAIN TIMELINE AND ASSIGN VALUE FROM SQUARE 
SYMBOL
var color = square.KeyColor;
//MOVE COLOR VARIABLE TO PERMANENT VARIABLE
var KeepColor:int = color;

// change color variable IF THE VALUE IS NOT 1
function ChangeColor () : void
{
  if(KeepColor != 1)
    {
      if (square.KeyColor != 1)
      {
        KeepColor = square.KeyColor;
        trace("color set to square value" )
      }

      else if (pentagon.KeyColor != 1)
      {
        KeepColor = pentagon.KeyColor;
        trace("color set to pentagon value")
      }

      else
      {
        trace ("there is an error")
        //break;
      }

    }
}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//CALL FUNCTION TO GO TO SQUARE SYMBOL AT THE CLICK OF BUTTON 1
btn1.addEventListener(MouseEvent.CLICK, printNumber);

//FUNCTION TO GO TO SQUARE SYMBOL
function printNumber(event:MouseEvent):void
{

    //GO TO FIRST KEYFRAME IN MAIN TIMELINE AND STOP
    gotoAndStop(1)
    //ASSIGN KEYCOLOR VALUE
    square.KeyColor = color;
    //PRINT COLOR CODE
    trace("color is  " + color);

}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//CALL FUNCTION TO GO TO PENTAGON SYMBOL AT THE CLICK OF BUTTON 2
btn2.addEventListener(MouseEvent.CLICK, printNumber2);

//FUNCTION TO GO TO PENTAGON SYMBOL
function printNumber2(event:MouseEvent):void
{

    //GO TO FIRST KEYFRAME IN MAIN TIMELINE AND STOP
    gotoAndStop(2)
    //PRINT COLOR CODE INSIDE OF THE PENTAGON SYMBOL
    trace("color is " + color);

}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//CHECK THAT THE COLOR CODE IN TH MAIN TIMELINE IS THE SAME AS THE COLOR 
FROM THE SQUARE 

//PRINT THE CODE AT THE CLICK OF THIS BUTTON
btnK.addEventListener(MouseEvent.CLICK, checkOtherKey);

//DECLARE FUNCTION TO PRINT KeepColor VARIABLE
function checkOtherKey(event:MouseEvent):void
{
trace("the current color is " + KeepColor);
}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//SQUARE SYMBOL SCRIPT

//STOP EVERYTHING FROM STARTING
stop();

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//DECLARE KEYFRAME CODE FOR COLOR
var KeyColor:int = 1;

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//CALL FUNCTION TO GO TO COLOR 1 AT THE CLICK OF BUTTON 1
btn1.addEventListener(MouseEvent.CLICK, Keynumber);

//DECLARE FUNCTION  FOR CHANGING KEYFRAME
function Keynumber(event:MouseEvent):void
{

    //GO TO FIRST KEYFRAME IN SQUARE TIMELINE AND STOP
    gotoAndStop(1);
    //SET COLOR CODE TO 1
    KeyColor = 1;
    //PRINT COLOR CODE OF FIRST COLOR
    trace("SQUARE" + KeyColor);
    //change root color number
    MovieClip(root).color = KeyColor;

}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//CALL FUNCTION TO GO TO COLOR 2 AT THE CLICK OF BUTTON 2
btn2.addEventListener(MouseEvent.CLICK, Keynumber2);

//DECLARE FUNCTION  FOR CHANGING KEYFRAME
function Keynumber2(event:MouseEvent):void
{
    //GO TO FIRST KEYFRAME IN SQUARE TIMELINE AND STOP
    gotoAndStop(2);
    //SET COLOR CODE TO 2
    KeyColor = 2;
    //PRINT COLOR CODE OF SECOND COLOR
    trace("SQUARE" + KeyColor);
    MovieClip(root).color = KeyColor;

}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

 // PENTAGON SYMBOL SCRIPT


//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//STOP EVERYTHING FROM STARTING
stop()

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//DECLARE KEYFRAME CODE FOR COLOR
var KeyColor:int;

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//CALL FUNCTION TO GO TO COLOR 1 AT THE CLICK OF BUTTON 1
btn1.addEventListener(MouseEvent.CLICK, Keynumber);

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//DECLARE FUNCTION  FOR CHANGING KEYFRAME
function Keynumber(event:MouseEvent):void
{
    //GO TO FIRST KEYFRAME IN PENTAGON TIMELINE AND STOP
    gotoAndStop(1);
    //SET COLOR CODE TO 1
    KeyColor = 1;
    //PRINT COLOR CODE OF FIRST COLOR
    trace ("PENTAGON" + KeyColor);

}

//-----------------------------------------------------------------------
//-----------------------------------------------------------------------

//CALL FUNCTION TO GO TO COLOR 2 AT THE CLICK OF BUTTON 2
btn2.addEventListener(MouseEvent.CLICK, Keynumber2);

//DECLARE FUNCTION  FOR CHANGING KEYFRAME
function Keynumber2(event:MouseEvent):void
{
    //GO TO SECOND KEYFRAME IN PENTAGON TIMELINE AND STOP
    gotoAndStop(2);
    //SET COLOR CODE TO 2
    KeyColor = 2;
    //PRINT COLOR CODE OF SECOND COLOR
    trace("PENTAGON" + KeyColor);

}

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您可以保存每种类型布料的帧编号,在更改颜色时始终更新,并在更换布料时使用它,方法是使用影片剪辑的.currentFrame属性。

//Reference to the current shirt or dress:
var shirt:MovieClip = basicShirt; //update this when you change shirt to dress etc

//Variables for colors (frames)
var shirtColor:int = 1;

//Changing shirt color:
shirtColorButton.addEventListener(MouseEvent.CLICK, changeShirtColor);

function changeShirtColor(evt:MouseEvent):void{
    //Other handy property for you might be .totalFrames:
    if(shirt.currentFrame < shirt.totalFrames){
        shirtColor++;
    }else{
        shirtColor = 1;
    }
    shirt.gotoAndStop(shirtColor);
}

所以现在如果你把衬衫换成连衣裙,你可以简单地从舞台上取下衬衫,在舞台上添加连衣裙,并且:

//function that creates the shirt:
shirt = basicDress;
shirt.gotoAndStop(shirtColor);

如果你真的需要颜色名称,你可以使用框架标签,或者只是将颜色名称存储到数组中,因为顺序总是相同的,例如:

var colorNames:Array = ["Blue","Red","Green"];
...
trace("Shirt color is "+colorNames[shirtColor - 1]);