Adding a BasicView to a Flex UIComponent

Saturday, November 29th, 2008 | snippets

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: ,

  • Well, that's great! Thanks for letting me know more about it. I would love to learn technical and programming related things.. 
    Nice to find the similar post.
    Thanks!
  • I think I got it.
    Tell me if this is right, but I am now using an enterframe event.
  • how can I/is there a way to have a onRenderTick function this way?
  • Jianwen
    Good example, but it raises me another problem that how to display a flex UIcomponent in pv3d scene3D? Such as, adding a flex panel with a Button into the pv3d scene, how to do that?
    Thanks~
  • camden_kid
    There seems to be something odd with this.
    The BasicView acts like it's a child of the Application rather than the Panel, even though it is assigned as a child of the Panel.
    The position of elements inside the BasicView are based relative to the Application coordinates instead of those of the Panel. This can be seen, for example, if the Application width and height are made greater than those of the panel.
  • camden_kid
    Thanks for this.

    Just what I need to start adding PV3D to Flex.
  • Kyle Burke
    I'm one of the many Java developers who decided to snoop around Flex, and I'm just getting off the ground with PV3, so any examples of Flex integration are GREATLY appreciated.

    Thanks again!
  • John Lindquist
    If you want the pv3d scene to scale well with the rest of the flex framework, you'll need to make a custom component that updates the BasicView width and height in Flex's updateDisplayList.

    I think there are a couple examples out there on google. I'll try and throw something together next week.
  • karul
    Miraculous works!

    this one behaves weird when Sphere dimensions are more than the application dimensions, or while application resizing or when
    basicView.opaqueBackground = true;
    advice pls!?!
    -karul, flex newbie
blog comments powered by Disqus

Search

Recommended Books

Speaking at FITC Toronto

 

November 2008
M T W T F S S
    Dec »
 12
3456789
10111213141516
17181920212223
24252627282930

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 ...