这是我使用AS3的编码:
import flash.events.MouseEvent;
import flash.display.MovieClip;
var btts:Array = [red,yellow,blue];
var set_colors:Object = {'red':0xff0000,'yellow':0xffff00,'blue':0x0000ff};
var obj_color:ColorTransform = new ColorTransform();
for(var i:int=0; i<btts.length; i++) {
obj_color.color = set_colors[btts[i].name];
btts[i].transform.colorTransform = obj_color;
btts[i].addEventListener(MouseEvent.CLICK, changeColor);
}
function changeColor(evt:Event):void
{
var b_name = evt.target.name;
obj_color.color = set_colors[b_name];
rec.transform.colorTransform = obj_color;
}
go.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_6);
function fl_ClickToGoToScene_6(event:MouseEvent):void
{
if(obj_color.color == set_colors[red])
{
gotoAndPlay(1, "Scene 2");
}
}
stop();
希望有人可以帮我修复这段代码。这段代码显示当我点击所有颜色按钮时它将转到场景2,但在我的情况下,我只想要一个选择按钮转到场景2。
答案 0 :(得分:0)
这可以帮助您处理背景颜色和Stage.Resize,但是您需要调整颜色更改的代码......
包com { import flash.display.Graphics; import flash.display.MovieClip; import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageQuality; import flash.display.StageScaleMode; import flash.events.Event; import flash.text.TextField;
public class Main extends MovieClip
{
private static const ORANGE:int = 0xff9900;
var bg:MovieClip;
var bg_mask:MovieClip;
var marginx:int = 10;
var marginy:int = 10;
var display:MovieClip;
var displayTextField:TextField;
var ellipseWidth:int = 90;
var ellipseHeight:int = 90;
public function Main()
{
super();
bg = new MovieClip();
bg_mask = new MovieClip();
display = new MovieClip();
displayTextField = new TextField();
this.addChild(bg);
this.addChild(bg_mask);
this.addChild(display);
this.display.addChild(displayTextField);
displayTextField.text = "";
displayTextField.x = ellipseWidth/Math.PI;
displayTextField.y = ellipseHeight/Math.PI;
stage.align = StageAlign.TOP_LEFT; // or StageAlign.TOP
stage.scaleMode = StageScaleMode.NO_SCALE;
drawBackground();
display.mask = bg_mask;
addListeners();
}
private function drawBackground(thickness:int=1,lineColor:int=0x000000,lineAlpha:Number=0.5,fillColor:int=ORANGE,fillAlpha:Number=0.5):void{
var g:Graphics = bg.graphics;
g.clear();
g.lineStyle(thickness,lineColor,lineAlpha);
g.beginFill(fillColor,fillAlpha);
g.drawRoundRect(marginx,marginy,this.stage.stageWidth-marginx*2,this.stage.stageHeight-marginy*2,ellipseWidth,ellipseHeight);
g.endFill();
}
private function drawMask():void{
var g:Graphics = bg_mask.graphics;
g.clear();
g.lineStyle(1,0x000000,0.3);
g.beginFill(0xcccccc,0.1);
g.drawRoundRect(marginx,marginy,this.stage.stageWidth-marginx*2,this.stage.stageHeight-marginy*2,90,90);
g.endFill();
}
private function addListeners():void{
stage.addEventListener(Event.ADDED,updateLabel);
stage.addEventListener(Event.RESIZE,updateLabel);
}
private function updateLabel(e:Event):void{
updateDisplay();
drawBackground();
drawMask();
}
private function updateDisplay():void{
var tf:TextField = displayTextField;
tf.text = ("{" + this.stage.stageWidth + ";" + this.stage.stageHeight + "}");
}
}
}
只需添加一个更改颜色的功能,但这是一种简单的方法......
在drawBackground方法中,只需添加你想要的颜色......
只需在drawBackground方法中编辑fillColor即可... 这与http://tatactic.be/stackOverflow/ChangeBG/StageResizeSimple.swf上的相同 但你也可以轻松改变颜色。
[编辑]
此处您可以添加一个可以改变您的BG颜色的功能 所以这应该是小菜一碟......;)
[/编辑]
祝你好运。 尼古拉斯。