0

Greetings to all.

I'm very new to AS3 (and Flash CS4) and i'm having a problem. I have this project where a user draws dynamically her signature with the mouse on an area and then, on another frame and after the signature is drawn, he can changes the color of the signature by clicking some buttons, each with a different color.

I'm using this to capture the signature to another frame:

  1. The Button that triggers the capture event:

    //targetMC is an MC to where the signature will be copied
    
    function buttonClick(event:MouseEvent):void{
        capture(drawingBoard_mc, _targetMC);
        drawGraphics.clear();
        gotoAndStop(5);
    };
    
  2. The function

    function capture(target:DisplayObject, _target:MovieClip):void {
        var relative:DisplayObject = target.parent;
        var rect:Rectangle = target.getBounds(relative);
        var bitmapData:BitmapData = new BitmapData(rect.width + PIXEL_BUFFER * 2, rect.height + PIXEL_BUFFER * 2);
        bitmapData.draw(relative, new Matrix(1, 0, 0, 1, -rect.x + PIXEL_BUFFER, -rect.y + PIXEL_BUFFER));
    
        var byteArray:ByteArray;
        var jpgEncoder:JPGEncoder = new JPGEncoder(JPG_QUALITY_DEFAULT);
        byteArray = jpgEncoder.encode(bitmapData);
        var ldr:Loader = new Loader();
        ldr.name = "signature";
        ldr.loadBytes(byteArray);
        //target is target mc where the signature will be copied into
        _target.addChild(ldr as DisplayObject);
    }
    

It copies the signature perfectly.

The problem is on target 5 where i have 2 buttons to change the color:

//Color 1
line_bt1.buttonMode = true;
line_bt1.mouseChildren = false;
line_bt1.addEventListener(MouseEvent.MOUSE_DOWN, line_bt1Over);

//Color 2
line_bt2.buttonMode = true;
line_bt2.mouseChildren = false;
line_bt2.addEventListener(MouseEvent.MOUSE_DOWN, line_bt2Over);

function line_bt1Over(e:Event){
    var myMC:DisplayObject = DisplayObject(_targetMC.getChildByName("signature") as DisplayObject);
    changeColor(myMC, 0xCCCCCC);
    changeColor(myMC, 0xCCCCCC);
}

function line_bt2Over(e:Event){
    var myMC:DisplayObject = DisplayObject(_targetMC.getChildByName("signature") as DisplayObject);
    changeColor(myMC, 0x000000);
    changeColor(myMC, 0x000000);
}

function changeColor(object:DisplayObject, color:Number){
     var colorchange:ColorTransform = new ColorTransform();
     colorchange.color = color;
     object.transform.colorTransform = colorchange;
}

My problem is the _targetMC and the signature child all change color, and i just want the child/signature. :(

I'm using var myMC:DisplayObject = DisplayObject(_targetMC.getChildByName("signature") as DisplayObject); to access the signature child, but the container mc (_targetMC) also changes color... What i'm i doing wrong?

Thanks in advance.

4

1 回答 1

0
  1. 每个人打一个电话就changeColor足够了。

  2. 您可以重用对象自己的colorTransform

    function changeColor(object:DisplayObject, color:Number){
        var colorchange:ColorTransform = object.transform.colorTransform;
        colorchange.color = color;
        object.transform.colorTransform = colorchange;
    }
    
  3. 您可以省略所有类型转换为 DisplayObject - 所有 Sprite 和 MovieClips 和 Loaders 都是 DisplayObject 的子类,因此它们应该可以在需要 DisplayObject 的任何地方正常工作:

    var myMC:DisplayObject = _targetMC.getChildByName("signature"); 
    // getChildByName always returns a DisplayObject
    

    var ldr:Loader = new Loader();
    ldr.name = "signature";
    ldr.loadBytes(byteArray);
    _target.addChild(ldr); // Loader extends DisplayObject
    
  4. 您的colorChange功能应该按预期工作。一定有其他问题。我不能完全确定,但我猜你的问题要么与你所有的 target(_mc) 对象的混合有关:

    • 函数“捕获”的参数“目标”
    • 函数“capture”的参数“_target”
    • 成员变量“_targetMC”

    或者,它可能与每次调用时在同一个_targetMC中添加一个名为“signature”的新Loader有关capture(),但从不删除旧的:第二次点击后,会有多个名为“signature”的剪辑,这可能会导致问题。

于 2011-02-15T18:53:56.293 回答