Flex 4中如何通过addChild()函数在list中显示一个Sprite的例子
By Minidxer | November 23, 2009
接下来的例子演示了Flex 4中如何通过Spark SpriteVisualElement对象和addChild()函数,在list中显示一个Sprite。
下面是main.mxml:
- <?xml version="1.0" encoding="utf-8"?>
- <s:Application name="Spark_SpriteVisualElement_addChild_test"
- xmlns:fx="http://ns.adobe.com/mxml/2009"
- xmlns:s="library://ns.adobe.com/flex/spark"
- xmlns:mx="library://ns.adobe.com/flex/halo"
- initialize="init();">
- <fx:Script>
- <![CDATA[
- private const spr1:Sprite = new Sprite();
- private const spr2:Sprite = new Sprite();
- private function init():void {
- spr1.graphics.beginFill(0xFF0000, 0.5);
- spr1.graphics.drawRect(10, 10, 100, 80);
- spr1.graphics.endFill();
- con.addChild(spr1);
- spr2.graphics.beginFill(0x0000FF, 0.3);
- spr2.graphics.drawRect(20, 20, 80, 100);
- spr2.graphics.endFill();
- con.addChild(spr2);
- }
- ]]>
- </fx:Script>
- <s:SpriteVisualElement id="con" />
- </s:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
List |
1 Comment » |
Tags: AddChild, Gumbo
大侠:自己已建好”A.mxml”,想通过addChild()方式添加到“B.mxml”中的其中一容器中,要怎么导入? 可以给我示例代码吗?本人是新手。先谢谢了!