flex:将 id 分配给基元

发布于 2024-11-02 11:24:14 字数 361 浏览 9 评论 0原文

我通过动作脚本在屏幕上创建了一些 Flex 原语。现在,根据业务逻辑,我需要对其中一些原语进行更改,例如:更改厚度、箭头方向等。

一种想法是在构建这些原语时为其分配 id - 我该怎么做?

例如,我得到一条如下所示的线

var myShape:Shape=new Shape();    
myShape.graphics.lineStyle(thickness,color);    
myShape.graphics.moveTo(XFrom,YFrom);    
myShape.graphics.lineTo(XTo,YTo);

如果根据某些条件,我想更改上面的颜色/厚度,我如何引用上面的这条线?

I have created a few flex primitives on screen via action script. Now based on business logic, I need to make changes to some of these primitives such as: changing thickness, direction of arrowhead etc

One thought was to assign id's to these primitives as they are built- how do I do that?

e.g. I get a line built as below

var myShape:Shape=new Shape();    
myShape.graphics.lineStyle(thickness,color);    
myShape.graphics.moveTo(XFrom,YFrom);    
myShape.graphics.lineTo(XTo,YTo);

If, based on some condition, I want to change the color/ thickness of above, how do i reference this line above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

茶底世界 2024-11-09 11:24:14

它可以想象这是在某种组件内完成的。所有 UIComponent 都有一个您想要的 生命周期坚持。您可以重写多个函数以获得您想要的功能类型。像这样:

private var _shape:Shape;

override protected function createChildren():void
{
   super.createChildren();
   if(!this._shape)
   {
      this._shape = new Shape();
      addChild(this._shape);
   }

}

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
   super.updateDisplayList(unscaledWidth, unscaledHeight);

   this._shape.graphics.lineStyle(thickness,color);    
   this._shape.graphics.moveTo(XFrom,YFrom);    
   this._shape.graphics.lineTo(XTo,YTo);
}

如果您希望它在数据更改时运行,您应该查看 invalidateDisplayList ,您将在任何数据更改后调用它,并且它将在下一帧上运行 updateDisplayList 函数。

It'd imagine this is done within a component of some sort. All UIComponents have a lifecycle which you want to adhere to. You can override several functions to get the kind of functionality you want. Like this:

private var _shape:Shape;

override protected function createChildren():void
{
   super.createChildren();
   if(!this._shape)
   {
      this._shape = new Shape();
      addChild(this._shape);
   }

}

override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
   super.updateDisplayList(unscaledWidth, unscaledHeight);

   this._shape.graphics.lineStyle(thickness,color);    
   this._shape.graphics.moveTo(XFrom,YFrom);    
   this._shape.graphics.lineTo(XTo,YTo);
}

And if you want it to run when you data changes, you should look into invalidateDisplayList which you would call after whatever data has changed and it would run the updateDisplayList function on the next frame.

往昔成烟 2024-11-09 11:24:14

我想出了一个更简单的方法

基本上不是直接绘制图元,而是将绘制分配给一个形状函数,该函数将返回一个 Shape 对象。

现在,原始线有一个简单的处理程序来更改属性。如果您需要有关如何实现此目标的更多具体细节,请告诉我

I came up with a more easier approach

Basically instead of drawing the primitives directly, assigned the draw to a shape function which will return a Shape object.

Now the primitive line has a easy handler to change properties. let me know if you need more specific details on how to achieve this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文