A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: problem preloading external Papervision file

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Posts
    6

    Question problem preloading external Papervision file

    Hi there, I'm trying to preload a external SWF file made with AS3 + Papervision, but I'm getting:

    Error #1009: Cannot access a property or method of a null object reference.
    at Papervision2049$iinit()


    Papervision2049 is the name of my Main.fla document class.

    Can anyone please help me?

    I already tried tons of loaders, but they all end up with the same error.

    My current Loader.fla has on the 1st frame:

    Code:
    var l:Loader = new Loader();
    l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
    l.load(new URLRequest("main.swf"));
    
    function done(e:Event):void {
    	addChild(l);
    }

    My Main.fla has a Document Class with:

    Code:
    package {
    	import org.papervision3d.materials.special.CompositeMaterial;
    	import org.papervision3d.materials.WireframeMaterial;
    	import org.papervision3d.materials.ColorMaterial;
    	import org.papervision3d.materials.BitmapFileMaterial;
    	import org.papervision3d.materials.utils.MaterialsList;
    	import org.papervision3d.objects.DisplayObject3D;
    	import org.papervision3d.objects.primitives.*;
    	import org.papervision3d.view.BasicView;
    	import org.papervision3d.materials.special.ParticleMaterial;
    	import org.papervision3d.objects.special.ParticleField;
    	import org.papervision3d.typography.*;
    	import org.papervision3d.events.InteractiveScene3DEvent;
    	import org.papervision3d.materials.special.Letter3DMaterial;
    	import org.papervision3d.typography.fonts.*;
    	import org.papervision3d.objects.parsers.Collada;
    	import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    	import org.papervision3d.lights.PointLight3D;
    
    
    	import caurina.transitions.*;
    	import fl.transitions.Tween;
    	import fl.transitions.easing.*;
    	import flash.events.*;
    	import flash.display.*;
    	import flash.filters.*;
    	import flash.net.URLRequest;
    	import flash.text.*;
    
    //	[SWF(width="940", height="600", backgroundColor="0xFFFFFF")];
    
    	public class Papervision2049 extends BasicView {
    
    		var foiClicado:Boolean = false;
    		private var do3d:DisplayObject3D = new DisplayObject3D();
    		private var logo:Collada;
    		private var myText:TextField = new TextField();
    		private var boxLoading:Loading = new Loading;
    		private var introducao:Intro = new Intro;
    		private var imgClicada:Object;
    		var zump:Zump = new Zump();
    
    		public function Papervision2049(viewportWidth:Number = 940, viewportHeight:Number = 600,
    		scaleToStage:Boolean=true, interactive:Boolean=true, cameraType:String="CAMERA3D") {
    			
    			super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
    
    
    			//CHAMA O MOVIE DE INTRODUCAO
    			stage.addChild(introducao);
    			introducao.iniciar.addEventListener(MouseEvent.CLICK, quandoIniciar);
    
    			function quandoIniciar(e):void {
    				//INCLUI O AMBIENTE 3D NO ARQUIVO
    				scene.addChild(do3d);
    				introducao.visible = false;
    			}
    
    			
    
    
    			
    			//MATERIAIS
    			var compositeMaterial:CompositeMaterial = new CompositeMaterial();
    			compositeMaterial.addMaterial(new WireframeMaterial(0xffffff));
    			compositeMaterial.addMaterial(new ColorMaterial(0xffffff, 1));
    			compositeMaterial.interactive = true;
    
    			var material:BitmapFileMaterial = new BitmapFileMaterial("elizabeth_sm.jpg");
    			material.interactive = true;
    			material.smooth = true;
    			
    			//MATERIAL DA ESFERA DE FUNDO
    			var fundo:BitmapFileMaterial = new BitmapFileMaterial("abstract9.jpg");
    			fundo.doubleSided = true;
    			fundo.interactive = true;
    			fundo.smooth = true;
    			
    			//MATERIAL DO LOGO
    			var mat:CompositeMaterial = new CompositeMaterial();
    			mat.addMaterial(new WireframeMaterial(0xcc0000));
    			mat.addMaterial(new ColorMaterial(0xcc0000, 1));
    			var mp:MaterialsList = new MaterialsList();
    			mp.addMaterial(mat, "ERFlat10");
    
    			//INCLUSAO DE PLANES
    			var plane1:Plane = new Plane(material, 250, 160, 10, 10);
    			plane1.x = -200;
    			plane1.y = 0;
    			plane1.z = 0;
    			plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onMouseOver);
    			plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onMouseOut);
    			plane1.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onMouseClick);
    			do3d.addChild(plane1);
    
    			var plane2:Plane = new Plane(compositeMaterial, 250, 160, 10, 10);
    			plane2.x = 200;
    			plane2.y = 0;
    			plane2.z = 100;
    			plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onMouseOver);
    			plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onMouseOut);
    			plane2.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onMouseClick);
    			do3d.addChild(plane2);
    
    			var plane3:Plane = new Plane(compositeMaterial, 250, 160, 10, 10);
    			plane3.x = 200;
    			plane3.y = 200;
    			plane3.z = -100;
    			plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onMouseOver);
    			plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onMouseOut);
    			plane3.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, onMouseClick);
    			do3d.addChild(plane3);
    
    
    
    			renderer.renderScene(scene, camera, viewport);
    
    			//IMPORTANDO O LOGO
    			logo = new Collada( "logo.dae", mp);
    			logo.moveUp(500);
    			logo.moveRight(1200);
    			logo.scale = 4;
    			do3d.addChild(logo);
    
    			//CRIANDO A ESFERA
    			var sphere:Sphere = new Sphere(fundo, 1350, 20, 20);
    			sphere.z = -300;
    			sphere.rotationX = 0;
    			sphere.rotationY = 0;
    			sphere.rotationZ = 0;
    			do3d.addChild(sphere);
    
    
    			//INCLUSAO DAS TAGS
    			var text3D1:Text3D = new Text3D("CATEGORIA 1", new HelveticaLight(), new Letter3DMaterial(0xcc0000));
    			text3D1.alpha = 0;
    			text3D1.scale = 0.4;
    			text3D1.x = plane1.x -150;
    			text3D1.y = plane1.y -130;
    			text3D1.z = plane1.z -100;
    			do3d.addChild(text3D1);
    
    
    			var text3D2:Text3D = new Text3D("CATEGORIA 2", new HelveticaLight(), new Letter3DMaterial(0xcc0000));
    			text3D2.alpha = 0;
    			text3D2.scale = 0.4;
    			text3D2.x = plane2.x -150;
    			text3D2.y = plane2.y -130;
    			text3D2.z = plane2.z -100;
    			do3d.addChild(text3D2);
    
    
    			var text3D3:Text3D = new Text3D("CATEGORIA 3", new HelveticaLight(), new Letter3DMaterial(0xcc0000));
    			text3D3.alpha = 0;
    			text3D3.scale = 0.4;
    			text3D3.x = plane3.x -150;
    			text3D3.y = plane3.y -130;
    			text3D3.z = plane3.z -100;
    			do3d.addChild(text3D3);
    
    
    			//scene.addChild(do3d);
    			camera.target = do3d;
    
    			startRendering();
    			this.startRendering();
    
    			//GRAVANDO POSICAO DOS PLANES
    			var initPosX1:Number = plane1.x;
    			var initPosX2:Number = plane2.x;
    			var initPosX3:Number = plane3.x;
    			/*var initPosX4:Number = plane4.x;
    			var initPosX5:Number = plane5.x;
    			var initPosX6:Number = plane6.x;
    			var initPosX7:Number = plane7.x;
    			var initPosX8:Number = plane8.x;
    			var initPosX9:Number = plane9.x;
    			*/
    
    			var initPosY1:Number = plane1.y;
    			var initPosY2:Number = plane2.y;
    			var initPosY3:Number = plane3.y;
    			/*var initPosY4:Number = plane4.y;
    			var initPosY5:Number = plane5.y;
    			var initPosY6:Number = plane6.y;
    			var initPosY7:Number = plane7.y;
    			var initPosY8:Number = plane8.y;
    			var initPosY9:Number = plane9.y;
    			*/
    
    			var initPosZ1:Number = plane1.z;
    			var initPosZ2:Number = plane2.z;
    			var initPosZ3:Number = plane3.z;
    			/*var initPosZ4:Number = plane4.z;
    			var initPosZ5:Number = plane5.z;
    			var initPosZ6:Number = plane6.z;
    			var initPosZ7:Number = plane7.z;
    			var initPosZ8:Number = plane8.z;
    			var initPosZ9:Number = plane9.z;
    			*/
    
    
    			//IMPORTANDO E ESCONDENDO O MOVIE DE LOADING
    			stage.addChild(boxLoading);
    			boxLoading.visible = false;
    
    
    			//MOUSEOVER DOS PLANES
    			function onMouseOver(e:InteractiveScene3DEvent):void {
    				Tweener.addTween(e.target, {z:e.target.z-100, time:0.2, transition:"easeInSine" });
    				zump.play();
    
    			}
    			
    			//MOUSEOUT DOS PLANES
    			function onMouseOut(e:InteractiveScene3DEvent):void {
    				//do3d.removeChild(text3D);
    				if (e.target.name == 3) {
    					Tweener.addTween(e.target, {z:initPosZ1, time:0.2, transition:"easeInQuint" });
    				}
    				if (e.target.name == 4) {
    					Tweener.addTween(e.target, {z:initPosZ2, time:0.2, transition:"easeInQuint" });
    				}
    				if (e.target.name == 5) {
    					Tweener.addTween(e.target, {z:initPosZ3, time:0.2, transition:"easeInQuint" });
    				}
    			}
    			
    			//CLICANDO NOS PLANES
    			function onMouseClick(e:InteractiveScene3DEvent):void {
    				material.interactive = false;
    				Tweener.addTween(e.target, {x:0, time:1, transition:"easeInQuint" });
    				Tweener.addTween(e.target, {y:0, time:1, transition:"easeInQuint" });
    				Tweener.addTween(e.target, {z:-700, time:1, transition:"easeInQuint", onComplete: function():void{boxLoading.visible = true;} });
    				e.target.removeEventListener(InteractiveScene3DEvent.OBJECT_OVER, onMouseOver);
    				e.target.removeEventListener(InteractiveScene3DEvent.OBJECT_OUT, onMouseOut);
    				Tweener.addTween(camera, {y:0, time:1, transition:"easeInQuint" });
    				Tweener.addTween(camera, {x:0, time:1, transition:"easeInQuint" });
    				foiClicado = true;
    				imgClicada = e.target;
    				//var myMovieClip:MovieClip = new Foto1();
    				//stage.addChild(myMovieClip);
    				//myMovieClip.x = 500;
    				//myMovieClip.y = 300;
    				//setChildIndex(myMovieClip,numChildren - 1);
    
    
    				if (e.target.name == 3) {
    					var url = "categoria1.swf";
    				}
    				var loader:Loader = new Loader();
    
    				loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
    				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
    
    				// Update the percentage display
    				function loadProgress(event:ProgressEvent):void {
    
    
    
    					var percentLoaded:Number = event.bytesLoaded / event.bytesTotal;
    					percentLoaded = Math.round(percentLoaded * 100);
    					boxLoading.x = 438;
    					boxLoading.y = 267;
    					boxLoading.loadingTXT.text = String(uint(percentLoaded)) + "%";
    				}
    				// Load complete, hide the animating graphic and text
    				function loadComplete(event:Event):void {
    					trace("Load Complete");
    
    				}
    				loader.load( new URLRequest( url ));
    				stage.addChild(loader);
    
    				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void {   ;
    				//e.target.removeEventListener(e.type, arguments.callee);
    				loader.content.addEventListener('fecha', deffoiClicado);
    				Tweener.addTween(logo, {z:-100, time:2, transition:"easeInQuint", onComplete: function():void{do3d.visible = false;}});
    
    				});
    
    				function deffoiClicado(e:Event):void {
    					do3d.visible = true;
    					trace(imgClicada);
    					boxLoading.visible = false;
    					if (imgClicada.name == 3) {
    						Tweener.addTween(plane1, {x:initPosX1, time:0.5, transition:"easeInQuint" });
    						Tweener.addTween(plane1, {y:initPosY1, time:0.5, transition:"easeInQuint" });
    						Tweener.addTween(plane1, {z:initPosZ1, time:0.5, transition:"easeInQuint", onComplete: function():void{foiClicado = false;material.interactive = true;}});
    						plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onMouseOver);
    						plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onMouseOut);
    					}
    					if (imgClicada.name == 4) {
    						Tweener.addTween(plane2, {x:initPosX2, time:0.5, transition:"easeInQuint" });
    						Tweener.addTween(plane2, {y:initPosY2, time:0.5, transition:"easeInQuint" });
    						Tweener.addTween(plane2, {z:initPosZ2, time:0.5, transition:"easeInQuint", onComplete: function():void{foiClicado = false;material.interactive = true;}});
    						plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onMouseOver);
    						plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onMouseOut);
    					}
    					if (imgClicada.name == 5) {
    						Tweener.addTween(plane3, {x:initPosX3, time:0.5, transition:"easeInQuint" });
    						Tweener.addTween(plane3, {y:initPosY3, time:0.5, transition:"easeInQuint" });
    						Tweener.addTween(plane3, {z:initPosZ3, time:0.5, transition:"easeInQuint", onComplete: function():void{foiClicado = false;material.interactive = true;}});
    						plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, onMouseOver);
    						plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, onMouseOut);
    					}
    					function voltaMouse(e:Event):void {
    						material.interactive = true;
    						foiClicado = false;
    					}
    					stage.removeChild(loader);
    				}
    			}
    		}
    		protected override function onRenderTick(e:Event = null):void {
    			//text3D.text = buildTime();
    			/*camera.x -= (camera.x - Math.sin(mouseX*0.01)*1000) /8;
    			camera.z -= (camera.z - Math.cos(mouseX*0.01)*1000) /8;
    			camera.y = -(((mouseY - (stage.height / 2)) / stage.height) * 1600)*/
    			if (foiClicado == false) {
    				camera.y = -(((mouseY - (600 / 2)) / 600) * 1600);
    				camera.x = (((mouseX - (940 / 2)) / 940) * 1600);
    
    			}
    			renderer.renderScene(scene, camera, viewport);
    		}
    	}
    }

  2. #2
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    your Main.fla is trying to access the stage during instantiation. however, it has no reference to it until its added as a child.

    so, you'll have to wait for it to be added to the stage, which means moving everything out of the Papervision2049 function, and dropping it into an init function...

    Code:
    package 
    {
    	import org.papervision3d.materials.special.CompositeMaterial;
    	import org.papervision3d.materials.WireframeMaterial;
    	import org.papervision3d.materials.ColorMaterial;
    	import org.papervision3d.materials.BitmapFileMaterial;
    	import org.papervision3d.materials.utils.MaterialsList;
    	import org.papervision3d.objects.DisplayObject3D;
    	import org.papervision3d.objects.primitives.*;
    	import org.papervision3d.view.BasicView;
    	import org.papervision3d.materials.special.ParticleMaterial;
    	import org.papervision3d.objects.special.ParticleField;
    	import org.papervision3d.typography.*;
    	import org.papervision3d.events.InteractiveScene3DEvent;
    	import org.papervision3d.materials.special.Letter3DMaterial;
    	import org.papervision3d.typography.fonts.*;
    	import org.papervision3d.objects.parsers.Collada;
    	import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
    	import org.papervision3d.lights.PointLight3D;
    
    
    	import caurina.transitions.*;
    	import fl.transitions.Tween;
    	import fl.transitions.easing.*;
    	import flash.events.*;
    	import flash.display.*;
    	import flash.filters.*;
    	import flash.net.URLRequest;
    	import flash.text.*;
    
    	//[SWF(width="940", height="600", backgroundColor="0xFFFFFF")];
    
    	public class Papervision2049 extends BasicView
    	{
    
    		var foiClicado:Boolean=false;
    		private var do3d:DisplayObject3D=new DisplayObject3D  ;
    		private var logo:Collada;
    		private var myText:TextField=new TextField  ;
    		private var boxLoading:Loading=new Loading  ;
    		private var introducao:Intro=new Intro  ;
    		private var imgClicada:Object;
    		var zump:Zump=new Zump  ;
    
    		public function Papervision2049(viewportWidth:Number=940,viewportHeight:Number=600,scaleToStage:Boolean=true,interactive:Boolean=true,cameraType:String="CAMERA3D")
    		{
    			super(viewportWidth,viewportHeight,scaleToStage,interactive,cameraType);
    			
    			if(!stage){
    				addEventListener(Event.ADDED_TO_STAGE, init);
    			} else {
    				init(null);
    			}
    		}
    		
    		private function init(e:Event):void
    		{
    			removeEventListener(Event.ADDED_TO_STAGE, init);
    			//CHAMA O MOVIE DE INTRODUCAO
    			stage.addChild(introducao);
    			introducao.iniciar.addEventListener(MouseEvent.CLICK,quandoIniciar);
    
    			function quandoIniciar(e):void
    			{
    				//INCLUI O AMBIENTE 3D NO ARQUIVO
    				scene.addChild(do3d);
    				introducao.visible=false;
    			}
    			//MATERIAIS
    			var compositeMaterial:CompositeMaterial=new CompositeMaterial  ;
    			compositeMaterial.addMaterial(new WireframeMaterial(0xffffff));
    			compositeMaterial.addMaterial(new ColorMaterial(0xffffff,1));
    			compositeMaterial.interactive=true;
    
    			var material:BitmapFileMaterial=new BitmapFileMaterial("elizabeth_sm.jpg");
    			material.interactive=true;
    			material.smooth=true;
    
    			//MATERIAL DA ESFERA DE FUNDO
    			var fundo:BitmapFileMaterial=new BitmapFileMaterial("abstract9.jpg");
    			fundo.doubleSided=true;
    			fundo.interactive=true;
    			fundo.smooth=true;
    
    			//MATERIAL DO LOGO
    			var mat:CompositeMaterial=new CompositeMaterial  ;
    			mat.addMaterial(new WireframeMaterial(0xcc0000));
    			mat.addMaterial(new ColorMaterial(0xcc0000,1));
    			var mp:MaterialsList=new MaterialsList  ;
    			mp.addMaterial(mat,"ERFlat10");
    
    			//INCLUSAO DE PLANES
    			var plane1:Plane=new Plane(material,250,160,10,10);
    			plane1.x=-200;
    			plane1.y=0;
    			plane1.z=0;
    			plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onMouseOver);
    			plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onMouseOut);
    			plane1.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,onMouseClick);
    			do3d.addChild(plane1);
    
    			var plane2:Plane=new Plane(compositeMaterial,250,160,10,10);
    			plane2.x=200;
    			plane2.y=0;
    			plane2.z=100;
    			plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onMouseOver);
    			plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onMouseOut);
    			plane2.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,onMouseClick);
    			do3d.addChild(plane2);
    
    			var plane3:Plane=new Plane(compositeMaterial,250,160,10,10);
    			plane3.x=200;
    			plane3.y=200;
    			plane3.z=-100;
    			plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onMouseOver);
    			plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onMouseOut);
    			plane3.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,onMouseClick);
    			do3d.addChild(plane3);
    
    
    
    			renderer.renderScene(scene,camera,viewport);
    
    			//IMPORTANDO O LOGO
    			logo=new Collada("logo.dae",mp);
    			logo.moveUp(500);
    			logo.moveRight(1200);
    			logo.scale=4;
    			do3d.addChild(logo);
    
    			//CRIANDO A ESFERA
    			var sphere:Sphere=new Sphere(fundo,1350,20,20);
    			sphere.z=-300;
    			sphere.rotationX=0;
    			sphere.rotationY=0;
    			sphere.rotationZ=0;
    			do3d.addChild(sphere);
    
    
    			//INCLUSAO DAS TAGS
    			var text3D1:Text3D=new Text3D("CATEGORIA 1",new HelveticaLight  ,new Letter3DMaterial(0xcc0000));
    			text3D1.alpha=0;
    			text3D1.scale=0.4;
    			text3D1.x=plane1.x - 150;
    			text3D1.y=plane1.y - 130;
    			text3D1.z=plane1.z - 100;
    			do3d.addChild(text3D1);
    
    
    			var text3D2:Text3D=new Text3D("CATEGORIA 2",new HelveticaLight  ,new Letter3DMaterial(0xcc0000));
    			text3D2.alpha=0;
    			text3D2.scale=0.4;
    			text3D2.x=plane2.x - 150;
    			text3D2.y=plane2.y - 130;
    			text3D2.z=plane2.z - 100;
    			do3d.addChild(text3D2);
    
    
    			var text3D3:Text3D=new Text3D("CATEGORIA 3",new HelveticaLight  ,new Letter3DMaterial(0xcc0000));
    			text3D3.alpha=0;
    			text3D3.scale=0.4;
    			text3D3.x=plane3.x - 150;
    			text3D3.y=plane3.y - 130;
    			text3D3.z=plane3.z - 100;
    			do3d.addChild(text3D3);
    
    
    			//scene.addChild(do3d);
    			camera.target=do3d;
    
    			startRendering();
    			this.startRendering();
    
    			//GRAVANDO POSICAO DOS PLANES
    			var initPosX1:Number=plane1.x;
    			var initPosX2:Number=plane2.x;
    			var initPosX3:Number=plane3.x;
    			/*var initPosX4:Number = plane4.x;
    			var initPosX5:Number = plane5.x;
    			var initPosX6:Number = plane6.x;
    			var initPosX7:Number = plane7.x;
    			var initPosX8:Number = plane8.x;
    			var initPosX9:Number = plane9.x;
    			*/
    
    			var initPosY1:Number=plane1.y;
    			var initPosY2:Number=plane2.y;
    			var initPosY3:Number=plane3.y;
    			/*var initPosY4:Number = plane4.y;
    			var initPosY5:Number = plane5.y;
    			var initPosY6:Number = plane6.y;
    			var initPosY7:Number = plane7.y;
    			var initPosY8:Number = plane8.y;
    			var initPosY9:Number = plane9.y;
    			*/
    
    			var initPosZ1:Number=plane1.z;
    			var initPosZ2:Number=plane2.z;
    			var initPosZ3:Number=plane3.z;
    			/*var initPosZ4:Number = plane4.z;
    			var initPosZ5:Number = plane5.z;
    			var initPosZ6:Number = plane6.z;
    			var initPosZ7:Number = plane7.z;
    			var initPosZ8:Number = plane8.z;
    			var initPosZ9:Number = plane9.z;
    			*/
    
    
    			//IMPORTANDO E ESCONDENDO O MOVIE DE LOADING
    			stage.addChild(boxLoading);
    			boxLoading.visible=false;
    
    
    			//MOUSEOVER DOS PLANES
    			function onMouseOver(e:InteractiveScene3DEvent):void
    			{
    				Tweener.addTween(e.target,{z:e.target.z - 100,time:0.2,transition:"easeInSine"});
    				zump.play();
    
    			}
    			//MOUSEOUT DOS PLANES
    			function onMouseOut(e:InteractiveScene3DEvent):void
    			{
    				//do3d.removeChild(text3D);
    				if (e.target.name == 3) {
    					Tweener.addTween(e.target,{z:initPosZ1,time:0.2,transition:"easeInQuint"});
    				}
    				if (e.target.name == 4) {
    					Tweener.addTween(e.target,{z:initPosZ2,time:0.2,transition:"easeInQuint"});
    				}
    				if (e.target.name == 5) {
    					Tweener.addTween(e.target,{z:initPosZ3,time:0.2,transition:"easeInQuint"});
    				}
    			}
    			//CLICANDO NOS PLANES
    			function onMouseClick(e:InteractiveScene3DEvent):void
    			{
    				material.interactive=false;
    				Tweener.addTween(e.target,{x:0,time:1,transition:"easeInQuint"});
    				Tweener.addTween(e.target,{y:0,time:1,transition:"easeInQuint"});
    				Tweener.addTween(e.target, {z:-700, time:1, transition:"easeInQuint", onComplete: function():void{boxLoading.visible = true;} });
    				e.target.removeEventListener(InteractiveScene3DEvent.OBJECT_OVER,onMouseOver);
    				e.target.removeEventListener(InteractiveScene3DEvent.OBJECT_OUT,onMouseOut);
    				Tweener.addTween(camera,{y:0,time:1,transition:"easeInQuint"});
    				Tweener.addTween(camera,{x:0,time:1,transition:"easeInQuint"});
    				foiClicado=true;
    				imgClicada=e.target;
    				//var myMovieClip:MovieClip = new Foto1();
    				//stage.addChild(myMovieClip);
    				//myMovieClip.x = 500;
    				//myMovieClip.y = 300;
    				//setChildIndex(myMovieClip,numChildren - 1);
    
    
    				if (e.target.name == 3) {
    					var url="categoria1.swf";
    				}
    				var loader:Loader=new Loader  ;
    
    				loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadProgress);
    				loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
    
    				// Update the percentage display
    				function loadProgress(event:ProgressEvent):void
    				{
    
    
    
    					var percentLoaded:Number=event.bytesLoaded / event.bytesTotal;
    					percentLoaded=Math.round(percentLoaded * 100);
    					boxLoading.x=438;
    					boxLoading.y=267;
    					boxLoading.loadingTXT.text=String(uint(percentLoaded)) + "%";
    				}
    				// Load complete, hide the animating graphic and text
    				function loadComplete(event:Event):void
    				{
    					trace("Load Complete");
    
    				}
    				loader.load(new URLRequest(url));
    				stage.addChild(loader);
    
    				loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void {   ;
    				//e.target.removeEventListener(e.type, arguments.callee);
    				loader.content.addEventListener('fecha', deffoiClicado);
    				Tweener.addTween(logo, {z:-100, time:2, transition:"easeInQuint", onComplete: function():void{do3d.visible = false;}});
    
    				});
    
    				function deffoiClicado(e:Event):void
    				{
    					do3d.visible=true;
    					trace(imgClicada);
    					boxLoading.visible=false;
    					if (imgClicada.name == 3) {
    						Tweener.addTween(plane1,{x:initPosX1,time:0.5,transition:"easeInQuint"});
    						Tweener.addTween(plane1,{y:initPosY1,time:0.5,transition:"easeInQuint"});
    						Tweener.addTween(plane1, {z:initPosZ1, time:0.5, transition:"easeInQuint", onComplete: function():void{foiClicado = false;material.interactive = true;}});
    						plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onMouseOver);
    						plane1.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onMouseOut);
    					}
    					if (imgClicada.name == 4) {
    						Tweener.addTween(plane2,{x:initPosX2,time:0.5,transition:"easeInQuint"});
    						Tweener.addTween(plane2,{y:initPosY2,time:0.5,transition:"easeInQuint"});
    						Tweener.addTween(plane2, {z:initPosZ2, time:0.5, transition:"easeInQuint", onComplete: function():void{foiClicado = false;material.interactive = true;}});
    						plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onMouseOver);
    						plane2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onMouseOut);
    					}
    					if (imgClicada.name == 5) {
    						Tweener.addTween(plane3,{x:initPosX3,time:0.5,transition:"easeInQuint"});
    						Tweener.addTween(plane3,{y:initPosY3,time:0.5,transition:"easeInQuint"});
    						Tweener.addTween(plane3, {z:initPosZ3, time:0.5, transition:"easeInQuint", onComplete: function():void{foiClicado = false;material.interactive = true;}});
    						plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onMouseOver);
    						plane3.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onMouseOut);
    					}
    					function voltaMouse(e:Event):void
    					{
    						material.interactive=true;
    						foiClicado=false;
    					}
    					stage.removeChild(loader);
    				}
    			}
    		}
    		
    		protected override  function onRenderTick(e:Event=null):void
    		{
    			//text3D.text = buildTime();
    			/*camera.x -= (camera.x - Math.sin(mouseX*0.01)*1000) /8;
    			camera.z -= (camera.z - Math.cos(mouseX*0.01)*1000) /8;
    			camera.y = -(((mouseY - (stage.height / 2)) / stage.height) * 1600)*/
    			if (foiClicado == false) {
    				camera.y=- mouseY - 600 / 2 / 600 * 1600;
    				camera.x=mouseX - 940 / 2 / 940 * 1600;
    
    			}
    			renderer.renderScene(scene,camera,viewport);
    		}
    	}
    }
    also, it's generally not good practice to construct functions within functions. in your case, I see functions within functions within functions within functions ...

    You may want to reconsider your structure there.
    Search first, asked questions later.

  3. #3
    Junior Member
    Join Date
    Jul 2008
    Posts
    6
    thx man, you saved my life.

    Also, thx for the tips about the construction, this is my first AS3 project, still learning a lot. thx again, see ya

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center