This is an effective way to load papervison into Flex.
In application include a UIComponent instance
<box:PaperVisionBoxid=”ppv“/>
This is the UIComponent instance. Here we are getting feedback from mc to know the dimensions of its papervision content and in order to resize this UIComponent. In this way the application gets noticed of the new dimensions and pushes down or left depending of its layout.
//PaperVisionBox
<<?xml version=”1.0″ encoding=”utf-8″?>
<mx:UIComponentxmlns:mx=”http://www.adobe.com/2006/mxml” xmlns:box=”com.juandevelops.ppv.box.*“
preinitialize=”this.onFlexEvent( event );”
addedToStage=”this.onFlexEvent(event);”
resize=”this.onFlexEvent(event);”>
<mx:Script>
<![CDATA[
import com.juandevelops.flesh.stage.StageEvent;
import com.juandevelops.flesh.stage.StageListener;
import com.juandevelops.ppv.cube.MotherCube;
import mx.events.FlexEvent;
private var mc:MotherCube
private function onFlexEvent( event:Event ):void
{
if( event.type == FlexEvent.PREINITIALIZE )
{
mc =new MotherCube();
this.addChild( mc );
}
else
if( event.type == Event.ADDED_TO_STAGE || event.type == Event.RESIZE )
{
this.invalidateSize();
}
}
override protected function measure():void
{
super.measure();
if( mc )
{
this.measuredWidth = mc.width;
this.measuredHeight = mc.height;
}
}
]]>
</mx:Script>
</mx:UIComponent>
Now it’s time to see the work done in MotherCube which is an instance os Sprite and is loading papervision, and in papervision we include a cube.
We can ignore most of the code and just pay attention to getters width and height.
Also important, not to include any other content but just papervision.
//MotherCube
package icom.juandevelops.ppv.cube
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
import org.papervision3d.cameras.CameraType;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.view.BasicView;
publicclass MotherCube extends Sprite
{
privatevar view:BasicView;
privatevar _cube:Cube;
privatevar list:MaterialsList;
privatevar cm:ClipMaterial;
privatevar mm:MovieMaterial;
publicfunction MotherCube()
{
view = new BasicView(600, 600, false, false, CameraType.FREE);
view.renderer = new BasicRenderEngine(); addChild(view);
view.viewport.interactive = true;
view.camera.z = -540;
list = new MaterialsList();
list.addMaterial( new ColorMaterial( 0xFFFFFF, “back” );
list.addMaterial( new ColorMaterial( 0×0099FF, 1, false ), “front” );
list.addMaterial( new ColorMaterial( 0xFF0000, 1, false ), “left” );
list.addMaterial( new ColorMaterial( 0xFFCC00, 1, false ), “right” );
list.addMaterial( new ColorMaterial( 0×93A070, 1, false ), “top” );
list.addMaterial( new ColorMaterial( 0×999999, 1, false ), “bottom” );
_cube = new Cube( list, 400, 400, 400 );
view.scene.addChild( _cube );
this.addEventListener( Event.ENTER_FRAME, onRenderViewport);
}
privatefunction onRenderViewport(e:Event): void
{
view.singleRender();
}
overridepublicfunctiongetwidth():Number
{
if( view )
return view.viewport.viewportWidth;
return 0;
}
overridepublicfunctionget height():Number
{
if( view )
return view.viewport.viewportWidth;
return 0;
}
publicfunctionget cube():Cube
{
returnthis._cube;
}
}
}
In my appliation I included the box below having the scrollers, and they are pushed down as the content in PaperVisionBox found out the dimensions of MotherCube

I Hope this helps, please let me know.. I am try to share my work knowledge and I never get any comments.




