문제

MXML 클래스를 사용하고 있었지만 시공 시간에 몇 가지 속성을 전달해야하므로 쉽게 AS3 코드로 변환합니다.

클래스는 직사각형이며 사각형을 그립니다.

원래 MXML 작업

<?xml version="1.0" encoding="utf-8"?>
<BaseShape name="rectangle"
    xmlns="org.edorado.edoboard.view.components.shapes.*" 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:degrafa="http://www.degrafa.com/2007"
    xmlns:objecthandles="com.roguedevelopment.objecthandles.*">

    <mx:Script>
        <![CDATA[

            import org.edorado.edoboard.view.components.shapes.IShape;
            import mx.events.FlexEvent;

            override public function drag(movePt:Point):void {
                this.width = movePt.x - this.x; 
                this.height = movePt.y - this.y; 
            }

            override public function updateFillColor(color:int):void {
                solidFill.color = color;
            }

        ]]>
    </mx:Script>

    <degrafa:Surface >
        <degrafa:GeometryGroup id="geo">
            <degrafa:fills>
                <degrafa:SolidFill id="solidFill" color="white" alpha="0.3"/>
            </degrafa:fills>

            <degrafa:strokes>
                <degrafa:SolidStroke id="stroke1" color="white"/>
            </degrafa:strokes>

            <degrafa:RegularRectangle 
                id="rect" 
                fill = "{solidFill}"
                width="{width}" 
                height="{height}"
                stroke="{stroke1}" />
        </degrafa:GeometryGroup>        
    </degrafa:Surface>
</BaseShape>

AS3에 대한 나의 시도

패키지 org.edorado.edoboard.view.components.shapes {import com.degrafa.geometry.regularRectangle; com.degrafa.paint.solidfill 가져 오기; com.degrafa.paint.solidstroke 가져 오기; com.degrafa.geometrygroup import; com.degrafa.surface 가져 오기; import flash.geom.point;

public class RectangleShape extends BaseShape 
{
    public var surface:Surface = new Surface(); 
    public var geoGroup:GeometryGroup = new GeometryGroup();
    public var solidFill:SolidFill = new SolidFill("white");
    public var solidStroke:SolidStroke = new SolidStroke("black");
    public var rect:RegularRectangle = new RegularRectangle(); 

    public static const name:String = "rectangle";

    public function RectangleShape() {
        addChild(surface);
        //surface.addChild(geoGroup);
        surface.graphicsCollection.addItem(geoGroup); 

        solidFill.alpha = 0.3;
        rect.fill = solidFill;
        rect.stroke = solidStroke;
        rect.width = this.width;
        rect.height = this.height;
        geoGroup.geometry = [rect];
        geoGroup.draw(null, null); 
    }

    override public function drag(movePt:Point):void {

        this.width = movePt.x - this.x; 
        this.height = movePt.y - this.y; 
        trace('dragging ', this.width, this.height);
    }

    override public function updateFillColor(color:int):void {
        solidFill.color = color;
    }
}

}

문제는 모양이 더 이상 그리지 않는다는 것입니다. 바서 셰이프 컨테이너가 있고 트레이스 드래그가 작동하지만 더 이상 사각형이 아닌 것을 볼 수 있습니다.

내가 놓친 분명한 것들은 무엇입니까? 감사

도움이 되었습니까?

해결책

BindingUtils 클래스로 바인딩을 설정해보십시오.

예를 들어:

BindingUtils.bindProperty(component, "height", this, "height"); 

다른 팁

나는 문제를 정확히 지적했다고 생각한다. MXML 버전에서 우리가 가진 전에

너비 = "{width}"height = "{height}"

DeGrafa 사각형은 부모에게 자동으로 맞습니다.

그러나 AS 버전은 아닙니다. AS에서 {width} 및 {height}를 재현하려고 노력해야합니다. MXML을 AS로 변환하는 도구가 있습니까?

당신은 당신의 직사각형 샤프를 추가 했습니까?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top