flex

Adding a BasicView to a Flex UIComponent

Saturday, November 29th, 2008 | snippets | Comments

While I would always encourage to separate your code into separate classes to follow best OOP practices, the example below will “get the job done”.

Since the Flex framework is based off UIComponents and you can’t directly add Sprites (or BasicViews) to a UIComponent, you have to dig into the UIComponents rawChildren (meaning Sprites) to add Papervision3D.

source

<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
	width="640"
	height="480"
	xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute" 
	applicationComplete="applicationComplete()">
	<mx:Script>
		<![CDATA[
/*			There are two similar methods:
			1. using rawChildren
			2. using $addChild with the mx_interal namespace
			Method #2 is commented out below
*/	
//			use namespace mx_internal; //method #2
 
			import org.papervision3d.objects.primitives.Sphere;
			import org.papervision3d.view.BasicView;
			private function applicationComplete():void
			{
				var basicView:BasicView = new BasicView();
				var sphere:Sphere = new Sphere();
				basicView.scene.addChild(sphere);
				basicView.startRendering();
				pv3dPanel.rawChildren.addChild(basicView); //method #1
//				pv3dPanel.$addChild(basicView); //method #2
			}
		]]>
	</mx:Script>
	<mx:Panel id="pv3dPanel" title="Papervision3D Panel" width="640" height="480"/>
</mx:Application>

Tags: ,

Search

Recommended Books

Speaking at FITC Toronto

Recent Comments

 

July 2010
M T W T F S S
« May    
 1234
567891011
12131415161718
19202122232425
262728293031  

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...