【问题标题】:How to add/get Sprite to/from UIComponent如何在 UIComponent 中添加/获取 Sprite
【发布时间】:2012-06-05 22:36:38
【问题描述】:

如何将Sprite添加到BorderContainer(UIComponent)?

var sprite:Sprite = new Sprite();
sprite.graphics.lineStyle(10,0);
sprite.graphics.moveTo(40,40);
sprite.graphics.lineTo(60,60);          

mybordercontainer.addChild(sprite);   
//mybrodercontainer is id of BorderContainer created in mxml

此代码不起作用。我在 BorderContainer 上看不到 Sprite。如何在 UIComponents 上添加 Sprite,以便我可以看到它们?我试过这个,它有点工作:

var comp:UIComponent = new UIComponent();
comp.addChild(sprite);
myborderconteiner.addElement(comp); 

但我不认为这是将 Sprites 添加到 UIComponents 的正确方法。有没有其他方法可以做到这一点?


第二个问题:

当我的 UIComponent(线条/圆圈/图像或其他)添加了少量 Sprite 时,我如何从该 UIComponent 接收对象 Sprite,其中包含之前添加到该 UIComponent 的所有 Sprite?

我需要从那个 Sprite 创建位图并做一些事情。

我希望我说清楚

【问题讨论】:

    标签: actionscript-3 apache-flex flex4 sprite


    【解决方案1】:

    使用SpriteVisualElement 作为容器。这应该可以很好地用作容器或 Sprite 替代品。您也可以在 UIComponent 本身中进行绘制。

    【讨论】:

    • 感谢您的快速答复。我用 SpriteVisualElement 替换了我的 BorderContainer,它完全符合我的要求。我可以轻松地将它们转换为位图。谢谢
    猜你喜欢
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-07
    • 2021-11-23
    • 2011-02-05
    • 1970-01-01
    相关资源
    最近更新 更多