Flex4

var container:UIComponent = new UIComponent();
addElement(container);
// addChild(container); // Flex3
 
まずは、UIComponentオブジェクトをaddElement()で貼り付けます。(Flex3だとaddChild())


var canvas:Sprite = new Sprite();
canvas.graphics.beginFill(0xED1A3D);
canvas.graphics.drawRect(0, 0, 100, 100);
canvas.graphics.endFill();
container.addChild(canvas);
 
後は貼り付けたいDisplayObject(を継承している子孫)をUIComponentオブジェクトに貼り付けるだけです。


flash on 2010-8-23 - wonderfl build flash online




検証用コード
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="application1_applicationCompleteHandler(event)">
	<fx:Script>
		<![CDATA[        
			import mx.core.UIComponent;
			import mx.events.FlexEvent;
 
			protected function application1_applicationCompleteHandler(event:FlexEvent):void
			{
				var container:UIComponent = new UIComponent();
				addElement(container);
 
				var canvas:Sprite = new Sprite();
				canvas.graphics.beginFill(0xED1A3D);
				canvas.graphics.drawRect(0, 0, 100, 100);
				canvas.graphics.endFill();
				container.addChild(canvas);
			}
		]]>
	</fx:Script>
</s:Application>
 

|新しいページ|検索|ページ一覧|RSS|@ウィキご利用ガイド | 管理者にお問合せ
|ログイン|