Need a help on loading SWF file in flex project

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Need a help on loading SWF file in flex project

ThshKari
This post has NOT been accepted by the mailing list yet.
This post has NOT been accepted by the mailing list yet.
hi all, i really need a help. i am new to both papervision3d. i am trying to render an SWF file (wich loads a dae file) in a flex project. but it does not load the model.


here is my action script source code

package
{
        import flash.events.Event;
        import flash.events.MouseEvent;
       
        import caurina.transitions.Tweener;
       
        import org.papervision3d.events.FileLoadEvent;
        import org.papervision3d.lights.PointLight3D;
        import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
        import org.papervision3d.objects.DisplayObject3D;
        import org.papervision3d.objects.parsers.DAE;
        import org.papervision3d.view.BasicView;
       
        [SWF (width="550", height="400", backgroundColor="0xffffff", frameRate="30")]
       
        public class ChairNormal extends BasicView
        {
                public var dae:DAE;
                public var light:PointLight3D;
                private var isOribiting:Boolean;
                private var cameraPitch:Number = 90;
                private var cameraYaw:Number = 270;
                private var cameraTarget:DisplayObject3D = DisplayObject3D.ZERO;
                private var previousMouseX:Number;
                private var previousMouseY:Number;
               
                public function ChairNormal()
                {
                        super(550,400,false);
                       
                        dae=new DAE();
                        dae.load("assets/Chair_Red.dae");
                        dae.scale = 85;
                       
                        scene.addChild(dae);
                        camera.fov = 30;
                        camera.z = -200;
                       

                        //a light source
                        light = new PointLight3D(true);
                        light.z = -300;
                        light.x = -200;
                        light.y = 200;
                       
                        scene.addChild(dae);
                       
                        stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
                        stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
                        stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
                       
                        startRendering();
                       
                }
               
                public function onMouseDown(event:MouseEvent):void
                {
                        isOribiting = true;
                        previousMouseX = event.stageX;
                        previousMouseY = event.stageY;
                }
               
                private function onMouseUp(event:MouseEvent):void
                {
                        isOribiting = false;
                }
               
                private function onMouseMove(event:MouseEvent):void
                {
                        var differenceX:Number =  previousMouseX - event.stageX;
                        var differenceY:Number =  previousMouseY - event.stageY;
                       
                        if(isOribiting)
                        {
                                cameraPitch += differenceY;
                                cameraYaw += differenceX;
                               
                                cameraPitch %= 360;
                                cameraYaw %= 360;
                               
                                cameraPitch = cameraPitch > 0 ? cameraPitch : 0.0001;
                                cameraPitch = cameraPitch < 180 ? cameraPitch : 179.9999;

                                previousMouseX = event.stageX;
                                previousMouseY = event.stageY;
                               
                                camera.orbit(cameraPitch, cameraYaw, true, cameraTarget);
                        }
                }
        }
}


it seems these lines, starting with 'stage' causes the problem. once i'm using 'stage.' the model is not loading in flex project and without 'stage' it loads the model, but the movements are not working properly.

stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMouseMove);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);



Here is my flex MXML source code


<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                           xmlns:s="library://ns.adobe.com/flex/spark"
                           xmlns:mx="library://ns.adobe.com/flex/mx"
                           width="500" height="500">

        <fx:Script>
               
<![CDATA[
			
			import flash.net.navigateToURL;
			
			private function newWin(url:String):void {
				var urlRequest:URLRequest = new URLRequest(url);
				navigateToURL(urlRequest);
			}
				
			protected function button_clickHandler(event:MouseEvent):void
			{
				mySWF.source="assets/Chair.swf";
			}
		]]>

        </fx:Script>

        <fx:Declarations>
               
        </fx:Declarations>
       
        <s:BorderContainer x="51" y="62" borderColor="#CCCCCC" borderWeight="4" width="385" height="428">
               
                <mx:SWFLoader id="mySWF" height="380" x="13" y="19" width="352"/>
               
        </s:BorderContainer>
       
        <s:Button id="button" x="208.55" y="15.1" click="button_clickHandler(event)" label="Click me" height="34"/>
       
</s:Application>



Can anyone help me on this. am i missing anything?