转载的代码,本人也是刚刚入门,所以添加不上解释,望有高手可以添加一下注释以供学习。
- <?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>