فليكس mxml إلى as3, فئة صغيرة هل فاتني شيء ؟
-
11-07-2019 - |
سؤال
لقد كان استخدام mxml الدرجة ولكن منذ أن كنت في حاجة لتمرير بعض الخصائص في وقت البناء ، لجعله أسهل سوف تحويله إلى as3 رمز.
الطبقة RectangleShape وأنه فقط يرسم المستطيل.
الأصلي 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.عرض.مكونات.الأشكال { استيراد com.degrafa.الهندسه.RegularRectangle;استيراد com.degrafa.الطلاء.SolidFill;استيراد com.degrafa.الطلاء.SolidStroke;استيراد com.degrafa.GeometryGroup;استيراد com.degrafa.السطح ؛ استيراد فلاش.geom.النقطة ؛
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;
}
}
}
المشكلة هي أن الشكل ليس الرسم بعد الآن ، BaseShape الحاوية هناك وأنا يمكن أن نرى أثر سحب العمل ولكن ليس المستطيل بعد الآن.
أي الأشياء واضحة فاتني ؟ شكرا
المحلول
حاول إعداد الارتباطات مع BindingUtils الدرجة.
على سبيل المثال:
BindingUtils.bindProperty(component, "height", this, "height");
نصائح أخرى
أعتقد أنني أوضحت المشكلة.قبل في mxml النسخة علينا
width="{عرض}" height="{الطول}"
و degrafa المستطيل تلقائيا تناسب الأم.
ولكن ليس في الإصدار.يجب أن تحاول إعادة إنتاج {عرض} و {الطول} في النحو.أي أداة لتحويل mxml إلى ؟
هل addChild الخاص بك RectangleShape?