0

我制作了一些对象并用Color Transform. 这是我的代码:

function createColorItems():void
{
    for (var i:int = 0; i < colorLength; i++)
    {
        var myColor:Object = new colorArea  ;
        var colorTrans:ColorTransform = new ColorTransform  ;
        arrColorTrans[i] = myXML.bag.color.item[i];
        arrItem.push(myColor);
        arrItem[i].x = 40 * i + 40;
        arrItem[i].y = 300;
        addChild(arrItem[i]);
        colorTrans.color = Number(arrColorTrans[i]);
        arrItem[i].transform.colorTransform = colorTrans;
        arrItem[i].addEventListener(MouseEvent.CLICK,changeColor);
    }
}

这是我改变颜色的地方。

function changeColor():void
{
    trace(e.target.color);
    myBox.graphics.beginFill(0x000000,0.5);
    myBox.graphics.drawRect(myImg.x,myImg.y,bagImg.width,bagImg.height);
    myBox.graphics.endFill();
    myBox.transform.colorTransform = publicColor;
    addChild(myBox);
}

我想要的是当单击对象时,另一个对象的颜色会发生变化。我追踪它,trace(e.target.color)但它是错误的。我publicColor习惯从 中挑选颜色colorTrans,但我不知道如何挑选颜色?可能吗??

对不起,我的语法不好,请帮助。

4

2 回答 2

0

您可以使用getPixelBitmapData 的方法。是一个文档。使用示例:

import flash.events.MouseEvent;
import flash.display.DisplayObject;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.display.Sprite;

var s0:Sprite = new Sprite();
var s1:Sprite = new Sprite();
var testS:Sprite = new Sprite();
var bmd:BitmapData = new BitmapData(1,1);

s0.graphics.beginFill(0x010FFF);
s0.graphics.drawRect(0, 0, 100, 100);
s0.graphics.endFill();
s0.x = 200;
s0.y = 200;

s1.graphics.beginFill(0x555FFF);
s1.graphics.drawRect(0, 0, 100, 100);
s1.graphics.endFill();
s1.x = 300;
s1.y = 200;

addChild(s0);
addChild(s1);
addChild(testS);
addEventListener(MouseEvent.CLICK, clickHandler);

function clickHandler(event:MouseEvent):void{
    const clicked:DisplayObject = event.target as DisplayObject;

    bmd.fillRect(bmd.rect, 0x000000);
    bmd.draw(clicked, new Matrix(1, 0, 0, 1, clicked.x - mouseX, clicked.y - mouseY));

    const color:uint = bmd.getPixel(0, 0);
    testS.graphics.beginFill(color);
    testS.graphics.drawRect(0, 0, 100, 100);
    testS.graphics.endFill();

    trace("color:" + color);
}
于 2012-08-13T10:35:47.490 回答
0
BitmapData.getPixel(x:int, y:int):uint

或者

BitmapData.getPixel32(x:int, y:int):uint

返回包含 Alpha 通道数据和 RGB 数据的 ARGB 颜色值。

于 2012-08-14T05:37:07.720 回答