1. 3D as实现类,同ActionScript Project一致
package
{
import away3dlite.materials.*;
import away3dlite.primitives.*;
import away3dlite.templates.*;
[SWF(backgroundColor="#000000", frameRate="30", quality="MEDIUM", width="800", height="600")]
public class ExSphere extends FastTemplate
{
override protected function onPreRender():void
{
// 将targetCamera.zoom的数据绑定到flex场景中sliderZoom组件
targetCamera.zoom = mx.core.Application.application.sliderZoom.value;
mesh.rotationY += 0.5;
}
}
}
2. "SpriteUIComponent.as" 3D内容container,继承自UIComponent
FastTemplate 继承自 Sprite ,但是Sprite不能 直接addChild到Flex场景 中去,需要转化 成UIComponent ,下面的类就是一个转化类。
或者可以在mxml中使用“this.rawChildren .addChild(new ExSphere());”。
package
{
import flash.display.Sprite;
import mx.core.UIComponent;
public class SpriteUIComponent extends UIComponent
{
public function SpriteUIComponent(sprite:Sprite)
{
super ();
explicitHeight = sprite.height;
explicitWidth = sprite.width;
addChild (sprite);
}
}
}
3. mxml中addChild到主场景
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
applicationComplete="appComplete()"
width="600"
height="400">
<mx:Script>
<![CDATA[
private function appComplete():void
{
this.addChild(new SpriteUIComponent(new ExSphere()));
}
]]>
</mx:Script>
</mx:Application>
本文介绍如何在ActionScript 3中创建并渲染一个旋转的3D球体,并将其作为子元素添加到Flex UI组件中。通过SpriteUIComponent类桥接Sprite与UIComponent,实现了3D内容与Flex应用的完美融合。

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



