---
title: "Away3D 4.0 Alpha 发布 – “Broomstick”-一个神奇的魔法世界开始了"
author: "chinaloft"
date: "2011-03-19T15:48:08Z"
tags: []
categories: ["Web前端"]
slug: "away3d-4-0-alpha-broomstick"
draft: false
lastmod: "2011-03-19T17:17:49Z"
id: 967614
url: "https://bvu.iteye.com/blog/967614"
---

Away3D 4.0 Alpha release – “Broomstick”
正式发布，下面我们一起走进这功能强大的世界，支持硬件加速是一个重大的突破，原来不能实现的很多东西，现在都能一一如愿。

Away3D 4.0 Alpha基本上还是保持原来的风格和开发思路。
保持一贯简洁明了的思路和高效的执行方法，感谢Away3D开发者无私的奉献。

![](http://dl.iteye.com/upload/attachment/440818/6d039c21-c2e1-3576-b642-f0d633596489.jpg)

我们是基于flex开发的，首先我们要解决的把view（属于sprite）加入到flex的UIComponent中去。
选择File -> New -> MXML Component.生成新的组件，继承自 UIComponent，我们可以给这个组件起名为：AwayView。

![](http://dl.iteye.com/upload/attachment/440816/78eab41d-a627-3594-aadf-e393c0a2e62e.jpg)

编辑好代码
整个AwayView.mxml文件如下：


```java
<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%">
    <mx:Script>
        <![cdata[
            import away3d.core.clip.rectangleclipping;
            import away3d.containers.view3d;
            
            public var view:view3d;
            
            override protected function createchildren():void
            {
                super.createchildren();
                view = new View3D();
                addChild( view );
                view.addEventListener(Event.ADDED_TO_STAGE, update); // Make sure the first frame is rendered
            }
            
            override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
            {
                super.updateDisplayList(unscaledWidth, unscaledHeight);
                update();
            }
            private function update(e:* = null):void
            {
                if(view.stage){
                    view.x = unscaledWidth/2;
                    view.y = unscaledHeight/2;
                    view.clipping = new RectangleClipping({minX:-unscaledWidth/2,minY:-unscaledHeight/2,maxX:unscaledWidth/2,maxY:unscaledHeight/2});
                    view.render();
                }
            }
        ]]>
    </mx:Script>
</mx:UIComponent>
```