原文转载如下:
Adding a BasicView to a Flex UIComponent
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.
<?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>
============================= //add by sing
以上代码是flex3下可以正常使用,在flex4下要做如下修改:
例如要将basicView添加到Group中。代码如下:
var uicomponent: UIComponent = new UIComponent();
uicomponent.addChild(basicView);
sGroup.addElementAt(uicomponent, 0);
本文介绍如何在Flex UI组件中添加BasicView以实现Papervision3D效果。提供了适用于Flex 3和Flex 4的代码示例,并展示了两种方法:使用rawChildren和mx_internal命名空间的$addChild方法。
173

被折叠的 条评论
为什么被折叠?



