[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 639
  • Last Modified:

Modularizing AS3 function

Hi Experts,

I have pasted alot of code below. The reason for this is because i am unaware on how to make the MC's do different actions using the same clip

On Click of one of the cube's FACE it does the following actions:

Zooms the camera which is fixed for all FACES
Sets the position & angle of my cube according to which FACE has been clicked
Sets the positions of my Planes which moves according to which FACE has been clicked
Adds/Changes the listener of my  Learn More Button according to which FACE has been clicked

I want to modularise this but dont know how....I seem to be wasting lots of time trying to change one small thing in so many functions.

Help would be much appreciated...Thank you


 
function faceClick(e:MouseEvent):void
{
	xDista = 0;
	yDista = (135 - 15);
	zScale= -200
	p1 = 0;
	p2 = -300;
	p3 = -600
	p4 = -900
	p5 = -1200
	p6 = -1500
	doZoom1();
}
 
 
 
function face2Click(e:MouseEvent):void
{
 
	xDista = -90;
	yDista = (-45 - 15);
	zScale= -200
	p5 = 0;
	p4 = 300;
	p3 = 600
	p2 = 900
	p1 = 1200
	p6 = -300
	doZoom2();
	
	
}
 
 
 
function face3Click(e:MouseEvent):void
{
	xDista = 0;
	yDista = (-135- 15);
	zScale= -200
	p3 = 0;
	p2 = 300;
	p1 = 600
	p6 = -900
	p5 = -600
	p4 = -300
	doZoom3()
	
 
}
 
 
 
function closeClick1(e:MouseEvent):void
{
	unZoom1()
}
 
function learnClick1(e:MouseEvent):void
{
	navigateToURL(new URLRequest("DStemplate.php?pid=2"), "_self");
}
 
 
 
function doZoom1():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
	
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick1);
	closePlane.visible = true;
	button.visible = true;
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false;
	sphere.visible = false, sphereBig.visible = false
	learn_but.addEventListener(MouseEvent.CLICK, learnClick1);
	
 
}
	
function unZoom1():void
{
	addEventListener (Event.ENTER_FRAME, loop);
	setTimeout( resetPlane, 100 )
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick1);
	Tweener.addTween( camera, { y:100,zoom:5.5, rotationX:0, time:.5})
	trace("unZoom1")
	
	
	
}
	
function resetPlane() 
{	
	Tweener.addTween( cube2, {y:100, transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-950,transition:"easeoutexpo" })
	trace("reset")
	Tweener.addTween( plane1, { y:-300,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:-600,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:-900,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:-1200,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:-1500,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:-1800,transition:"easeoutexpo", time:.5})
	cube2.addEventListener(MouseEvent.MOUSE_OVER, controlCube);
	cube2.addEventListener(MouseEvent.MOUSE_OUT, loop1);
	removeEventListener(Event.ENTER_FRAME, stay);
	closePlane.visible = false
	button.visible = false;
	
	close_mc.alpha = 0;
	close_mc.buttonMode = false;
	
}
 
 
 
 
function closeClick2(e:MouseEvent):void
{
	unZoom2()
}
function learnClick2(e:MouseEvent):void
{
	navigateToURL(new URLRequest("DStemplate.php?pid=1"), "_self");
}
 
function doZoom2():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
 
	
	
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false; sphere.visible = false, sphereBig.visible = false;
	
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick2);
	closePlane.visible = true;
	button.visible = true;
	learn_but.addEventListener(MouseEvent.CLICK, learnClick2);
	
	
	
}
	
function unZoom2():void
{
	
	addEventListener (Event.ENTER_FRAME, loop);
	setTimeout( resetPlane, 100 )
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick2);
	Tweener.addTween( camera, { y:100,zoom:5.5, rotationX:0, time:.5})
	trace("unZoom2")
	
	
}
	
 
 
 
function closeClick3(e:MouseEvent):void
{
	unZoom3()
}
function learnClick3(e:MouseEvent):void
{
	navigateToURL(new URLRequest("DStemplate.php?pid=5"), "_self");
}
 
 
function doZoom3():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false; sphere.visible = false, sphereBig.visible = false;
 
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick3);
	closePlane.visible = true;
	button.visible = true;
	learn_but.addEventListener(MouseEvent.CLICK, learnClick3);
	
	
}
	
function unZoom3():void
{
	addEventListener (Event.ENTER_FRAME, loop);
 
	setTimeout( resetPlane, 100 )
	
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick3);
	trace("unZoom3")
	
	
}

Open in new window

0
mmucom
Asked:
mmucom
  • 8
  • 6
  • 5
1 Solution
 
rascalpantsCommented:
well it looks like you need to change a lot of properties for each method of your class...  so I would recommend possibly just passing in an object with the details needed and just use one method for each thing like zoom and learnClick, etc.

so at the very least you will only have one method for each bit of functionality, and then you pass in the parameters that are needed.  I like using an object, instead of passing in a ton or different parameters, because if you need to add one, you have to add it to more places... which makes more room for errors...  instead just use an object that contains the data needed.

hopefully this points you in the right direction...


rp / Zone Advisor

0
 
mmucomAuthor Commented:
thanks...is it possible to giude me a acouple links of tutorials or some reference code....much appreciated
0
 
rascalpantsCommented:
when you setup your event listener for the buttons, you add that object to the button, and then you can assess the properties later... like the code below...

the basic principle is to just use one method/function, and to have the data passed as a object... and in this case, we create and then assign the value of clipObj to the value of theObj... then we reference the movieclip by e.target and then the clipObj after than...

btw... I am pretty sure that it is e.target, but just in case i mix it up, it could be e.currentTarget.clipObj

rp / ZA



var theObj:Object = new Object();
 
theObj.xDista = 0;
theObj.yDista = (135 - 15);
theObj.zScale= -200
theObj.p1 = 0;
theObj.p2 = -300;
theObj.p3 = -600
theObj.p4 = -900
theObj.p5 = -1200
theObj.p6 = -1500
 
theBtn.clipObj = theObj;
theBtn.addEventListener( MouseEvent.CLICK, faceClick);
 
function faceClick(e:MouseEvent):void
{
  var ob:Object = e.target.clipObj;
 
  xDista = ob.xDista;
  yDista = ob.yDista;
  zScale = ob.zScale;
  p1 = ob.p1;
  p2 = ob.p2;
  p3 = ob.p3;
  p4 = ob.p4;
  p5 = ob.p5;
  p6 = ob.p6;
 
  doZoom1();
 
}

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mmucomAuthor Commented:
Ok... i understand the Object method...But how does it know which face i have clicked so that the p1 - p6 object values reflects accordingly and how does doZoom(1-6) happen accordingly...was hoping i could just use doZoom for all and change the values and listeners dynamically
0
 
rascalpantsCommented:
that was one other question I forgot to ask...

where are you setting up the event listener for the faces?  THAT is where you attach these objects to the movieclip...  if you have not done that yet, then what do you click on to make this thing work?

rp / ZA
0
 
section25Commented:
Sine you can't pass variables with event Listeners, you can set up a function variable to do the same thing. You need to set up a function variable for each object. This will reduce your code a lot, and allow you to pass the variables, but you still need a variable for each object. As in:

var face1Click = function(e:Event){faceClick(1,300,500,600,etc)};

faceClick(whichFace:int,p_1:int,p_2:int,p_3:int, etc...){
                     p1 = p_1;
      p2 = p_2;
      p3 = p_3;

}

Then set up event listeners for each object:
face_1.addEventListener(MouseEvent.MOUSE_DOWN, face1Click);

This allows you to only have one function, but multiple calls to it using variables. It also allows you to remove the event listeners by name.

0
 
mmucomAuthor Commented:
sorry for the delay... heres all the code...haven't included the imports....Have i put the listeners in the right place?? here's a link to what it is doing.. http://www.determinedstudio.com/intro.html

thanks

 var viewport:Viewport3D; // The Viewport
		  var renderer:BasicRenderEngine; // Rendering engine
		  
		// -- Scenes -- //
		  var scene:Scene3D; // A Scene
		// -- Cameras --//
		  var camera:Camera3D; // A Camera
		  var xDista:Number
		var yDista:Number
		var zScale:Number
		var p1:Number
		var p2:Number
		var p3:Number
		var p4:Number
		var p5:Number
		var p6:Number
		var phongMaterial:PhongMaterial;
		var pointLight:PointLight3D;
		var plane:Plane
		var planeFader:Plane
		var phongMaterialBlack:PhongMaterial
		
		
		var cube:Cube
		var cube2:Cube
		var cube3:Cube
		var sphereBig:Sphere
		var mambg:MovieMaterial
		var Fadbg:MovieMaterial
		var mam:MovieMaterial
		var mam2:MovieMaterial
		var mam3:MovieMaterial
		var mam4:MovieMaterial
		var mam5:MovieMaterial
		var mam6:MovieMaterial
		var closeM:MovieMaterial
var closePlane:Plane
var fmat:MovieMaterial
var bkmat:MovieMaterial
var lmat:MovieMaterial
var rmat:MovieMaterial
var tmat:MovieMaterial
var bmat:MovieMaterial
var sph_mat:MovieMaterial
 
var bam1:MovieMaterial
var bam2:MovieMaterial
var bam3:MovieMaterial
var bam4:MovieMaterial
var bam5:MovieMaterial
var bam6:MovieMaterial
var lbut:MovieMaterial
 
var plane1:Cube
var plane2:Cube
var plane3:Cube
var plane4:Cube
var plane5:Cube
var plane6:Cube
 
var viewportMode:Boolean
 
var button:Plane
		init();
 
		  function init():void {
			initPapervision(); // Initialise papervision
			init3d(); // Initialise the 3d stuff..
			init2d(); // Initialise the interface..
			initEvents(); // Set up any event listeners..
			trace("init");
		}
		  function initPapervision():void {
			// Here is where we initialise everything we need to
			trace("init_PV3D");
			// render a papervision scene.
			viewport = new Viewport3D(0, 0, true, true);
			viewport.buttonMode = false;
			// The viewport is the object added to the flash scene.
			// You 'look at' the papervision scene through the viewport
			// window, which is placed on the flash stage.
			addChild(viewport); // Add the viewport to the stage.
			// Initialise the rendering engine.
			renderer = new BasicRenderEngine();
			// -- Initialise the Scenes -- //
			scene = new Scene3D();
			// -- Initialise the Cameras -- //
			camera = new Camera3D(); // The argument passed to the camera
			// is the object that it should look at. I've passed the scene object
			// so that the camera is always pointing at the centre of the scene.
		}
		  function init3d():void {
			// This function should hold all of the stages needed
			// to initialise everything used for papervision.
			// Models, materials, cameras etc.
			camera.zoom = 3.5;
			camera.focus = 100;
			camera.target = plane;
			camera.y = 300;
			camera.x = -25;
 
 
 
 
//instantiate your point light and set it back on the z
//pointLight = new PointLight3D(boolean parameter to show the light in the scene or not);
pointLight = new PointLight3D(true);
pointLight.z = 0;
pointLight.y = 500;
pointLight.rotationX = 90;
 
 
phongMaterial = new PhongMaterial(pointLight, 0xFF0033, 0x5A0000, 10);
 
phongMaterialBlack = new PhongMaterial(pointLight, 0x333333, 0x000000, 10);
 
mambg = new MovieMaterial(bg,false, false);
mambg.smooth = true;
 
Fadbg = new MovieMaterial(fader,true, true);
Fadbg.smooth = true;
Fadbg.animated = true;
 
 
plane = new Plane(mambg, 3000, 2000, 2, 2);
 
plane.rotationX = 90
plane.y = -250
plane.z = -400
scene.addChild(plane);
 
plane.visible = true;
 
planeFader = new Plane(Fadbg, 674, 292, 2, 2);
 
planeFader.rotationX = 20
planeFader.x = -40
planeFader.y = -350
planeFader.z = -450
scene.addChild(planeFader);
 
planeFader.visible = true;
 
 
close_mc.alpha = 0;
close_mc.buttonMode = false;
 
mam  = new MovieMaterial(face,false, true);
mam.interactive = true;
mam.smooth = true;
 
 
 
mam2  = new MovieMaterial(face2,false, true);
mam2.interactive = true;
mam2.smooth = true;
 
 
mam3  = new MovieMaterial(face3,false, true);
mam3.interactive = true;
mam3.smooth = true;
 
 
mam4  = new MovieMaterial(face4,false, true);
mam4.interactive = true;
mam4.smooth = true;
 
 
mam5  = new MovieMaterial(face5,false, true);
mam5.interactive = true;
mam5.smooth = true;
 
 
mam6  = new MovieMaterial(face6,false, true);
mam6.interactive = true;
mam6.smooth = true;
 
 
 
 
 closeM  = new MovieMaterial(close_mc,false, true);
closeM.interactive = true;
closeM.smooth = true;
//closeM.animated = true;
 
closePlane = new Plane(closeM, 70, 18, 10 , 10);
scene.addChild(closePlane);
 
closePlane.x = 220;
closePlane.z = -410;
closePlane.y = 70;
closePlane.rotationY = 0;
closePlane.scaleY = .75;
closePlane.scaleX = .75;
closePlane.visible = false;
 
 
// Create the material cube menu
 fmat  = new MovieMaterial(f_nav,true, true);
fmat.interactive = true;
fmat.oneSide = false;
fmat.smooth = true;
 
 
 bkmat  = new MovieMaterial(bk_nav,false, true);
bkmat.interactive = true;
bkmat.oneSide = false;
bkmat.smooth = true;
 
 lmat  = new MovieMaterial(l_nav,false, true);
lmat.oneSide = false;
lmat.interactive = true;
lmat.smooth = true;
 
 rmat  = new MovieMaterial(r_nav,false, true);
rmat.interactive = true;
rmat.oneSide = false;
rmat.smooth = true;
 
 tmat  = new MovieMaterial(t_nav,false, true);
tmat.oneSide = false;
tmat.interactive = true;
tmat.smooth = true;
 
bmat  = new MovieMaterial(b_nav,false, true);
bmat.oneSide = false;
bmat.smooth = true;
bmat.interactive = true;
 
sph_mat  = new MovieMaterial(sphere_mat,true, true);
sph_mat.oneSide = false;
sph_mat.smooth = true;
sph_mat.interactive = true;
 
cube = new Cube( new MaterialsList({front:mam, back:mam5, left:mam3, right:mam4,top:mam2, bottom:mam6}), 200, 200, 200, 10, 10, 10);
scene.addChild(cube);
 
cube2 = new Cube( new MaterialsList({front:mam, back:mam5, left:mam3, right:mam4,top:mam2, bottom:mam6}), 200, 200, 200, 10, 10, 10);
scene.addChild(cube2);
 
cube3 = new Cube( new MaterialsList({front:bkmat, back:fmat, left:rmat, right:lmat,top:tmat, bottom:bmat}), 20, 20, 20, 15, 15, 15);
scene.addChild(cube3);
 
sphereBig = new Sphere(sph_mat, 250, 20, 20);
scene.addChild(sphereBig);
 
sphereBig.z = -300;
sphereBig.y = 100;
 
cube.x = -950;
cube.y = -110;
cube.z = -500;
 
cube2.z = -500;
cube2.y = 100;
cube2.rotationY = -150;
 
cube3.z = -700;
cube3.y = 180;
cube3.x = 200;
 
cube3.rotationX = 0;
cube3.rotationY = 45;
cube3.rotationZ = 0;
 
 
// Create the material
 bam1  = new MovieMaterial(web,false, true);
bam1.oneSide = false;
bam1.smooth = true;
 
plane1 = new Cube( new MaterialsList({front:phongMaterial, back:bam1, left:phongMaterial, right:phongMaterial,top:phongMaterial, bottom:phongMaterial}), 300,  10, 175, 10, 10, 10);
scene.addChild(plane1);
 
 
 bam5  = new MovieMaterial(about,false, true);
bam5.oneSide = false;
bam5.smooth = true;
 
 plane2 = new Cube( new MaterialsList({front:phongMaterial, back:bam5, left:phongMaterial, right:phongMaterial,top:phongMaterial, bottom:phongMaterial}), 300,  10, 175, 10, 10, 10);
scene.addChild(plane2);
 
 bam3  = new MovieMaterial(deliv,false, true);
bam3.oneSide = false;
bam3.smooth = true;
 
 plane3 = new Cube( new MaterialsList({front:phongMaterial, back:bam3, left:phongMaterial, right:phongMaterial,top:phongMaterial, bottom:phongMaterial}), 300,  10, 175, 10, 10, 10);
scene.addChild(plane3);
 
 bam4  = new MovieMaterial(CGI,false, true);
bam4.oneSide = false;
bam4.smooth = true;
 
 plane4 = new Cube( new MaterialsList({front:phongMaterial, back:bam4, left:phongMaterial, right:phongMaterial,top:phongMaterial, bottom:phongMaterial}), 300,  10, 175, 10, 10, 10);
scene.addChild(plane4);
 
 
 bam2  = new MovieMaterial(graphic,false, true);
bam2.oneSide = false;
bam2.smooth = true;
 plane5 = new Cube( new MaterialsList({front:phongMaterial, back:bam2, left:phongMaterial, right:phongMaterial,top:phongMaterial, bottom:phongMaterial}), 300,  10, 175, 10, 10, 10);
scene.addChild(plane5);
 
 bam6  = new MovieMaterial(contact,false, true);
bam6.oneSide = false;
bam6.smooth = true;
 
 plane6 = new Cube( new MaterialsList({front:phongMaterial, back:bam6, left:phongMaterial, right:phongMaterial,top:phongMaterial, bottom:phongMaterial}), 300,  10, 175, 10, 10, 10);
scene.addChild(plane6);
 
lbut  = new MovieMaterial(learn_but,false, true);
lbut.interactive = true;
lbut.smooth = true;
 
button = new Plane(lbut, 44, 14, 10, 10);
scene.addChild(button);
 
button.x = 215;
button.z = -430;
button.y = -60;
button.rotationY = 0;
button.scaleY = 1;
button.scaleX = 1;
button.visible = false;
 
//innitialize Plane Positions
 
plane1.x = 110;
plane1.z = -400;
plane1.y = -300;
plane1.rotationY = 0;
 
plane2.x = 110;
plane2.z = -400;
plane2.y = -600;
plane2.rotationY = 0;
 
plane3.x = 110;
plane3.z = -400;
plane3.y = -900;
plane3.rotationY = 0;
 
plane4.x = 110;
plane4.z = -400;
plane4.y = -1200;
plane4.rotationY = 0;
 
plane5.x = 110;
plane5.z = -400;
plane5.y = -1500;
plane5.rotationY = 0;
 
plane6.x = 110;
plane6.z = -400;
plane6.y = -1800;
plane6.rotationY = 0;
 
// Add Listeners
cube2.addEventListener(MouseEvent.MOUSE_OVER, controlCube);
//cube2.addEventListener(MouseEvent.MOUSE_OUT, loop1);
 
sphereBig.addEventListener(MouseEvent.MOUSE_OVER, controlCube);
sphereBig.addEventListener(MouseEvent.MOUSE_OUT, loop1);
 
 
sphere.addEventListener(MouseEvent.MOUSE_OVER, rotateCube);
sphere.addEventListener(MouseEvent.MOUSE_OUT, loop2);
sphere.buttonMode= true;
 
next_mc.addEventListener(MouseEvent.MOUSE_OVER, rotateCube);
prev_mc.addEventListener(MouseEvent.MOUSE_OVER, rotateCube);
up_mc.addEventListener(MouseEvent.MOUSE_OVER, rotateCube);
down_mc.addEventListener(MouseEvent.MOUSE_OVER, rotateCube);
cube3.addEventListener(MouseEvent.MOUSE_OVER, rotateCube);
 
next_mc.visible = false;
prev_mc.visible = false;
up_mc.visible = false;
down_mc.visible = false; 
text123.visible = false;
 
 
text123.gotoAndPlay(2);
 
f_nav.addEventListener(MouseEvent.CLICK, face5Click);
bk_nav.addEventListener(MouseEvent.CLICK, faceClick);
l_nav.addEventListener(MouseEvent.CLICK, face4Click);
r_nav.addEventListener(MouseEvent.CLICK, face3Click);
t_nav.addEventListener(MouseEvent.CLICK, face2Click);
b_nav.addEventListener(MouseEvent.CLICK, face6Click);
 
face.addEventListener(MouseEvent.CLICK, faceClick);
face2.addEventListener(MouseEvent.CLICK, face2Click);
face3.addEventListener(MouseEvent.CLICK, face3Click);
face4.addEventListener(MouseEvent.CLICK, face4Click);
face5.addEventListener(MouseEvent.CLICK, face5Click);
face6.addEventListener(MouseEvent.CLICK, face6Click);
 
cface.addEventListener(MouseEvent.CLICK, faceClick);
cface2.addEventListener(MouseEvent.CLICK, face2Click);
cface3.addEventListener(MouseEvent.CLICK, face3Click);
cface4.addEventListener(MouseEvent.CLICK, face4Click);
cface5.addEventListener(MouseEvent.CLICK, face5Click);
cface6.addEventListener(MouseEvent.CLICK, face6Click);
 
 
closePlane.addEventListener(MouseEvent.MOUSE_OVER, animateCube);
closePlane.addEventListener(MouseEvent.MOUSE_OUT, stay1);
 
button.addEventListener(MouseEvent.MOUSE_OVER, animateCube);
button.addEventListener(MouseEvent.MOUSE_OUT, stay1);
 
cube.addEventListener(MouseEvent.MOUSE_OVER, animateCube);
cube.addEventListener(MouseEvent.MOUSE_OUT, stay1);
 
		}
		  function init2d():void {
			// This function should create all of the 2d items
			// that will be overlayed on your papervision project.
			// User interfaces, Heads up displays etc.
		}
		  function initEvents():void {
			// This function makes the onFrame function get called for
			// every frame.
			addEventListener(Event.ENTER_FRAME, loop);
			
			// This line of code makes the onEnterFrame function get
			// called when every frame is entered.
		}
		
		
		
		
		
			
			function loop1(e:Event):void
{
	addEventListener(Event.ENTER_FRAME, loop);
	removeEventListener(Event.ENTER_FRAME, controlCube1);
	
}
 
function loop2(e:Event):void
{
	addEventListener(Event.ENTER_FRAME, loop);
	removeEventListener(Event.ENTER_FRAME, rotateCube1);
	cube2.addEventListener(MouseEvent.MOUSE_OVER, controlCube);
	cube2.addEventListener(MouseEvent.MOUSE_OUT, loop1)
	
}
 
function loop(e:Event):void
{
	
		sndVroom.gotoAndStop(2);
		Tweener.addTween( camera, { y:100, zoom:5.5, rotationX:0, time:1.5,transition:"easeoutexpo"})
        Tweener.addTween(cube2, {rotationX:0,rotationY:-30, time:1, transition:"easeoutexpo"});
		Tweener.addTween(cube3, {rotationX:0,rotationY:-15, time:1, transition:"easeoutexpo"});
		
		next_mc.visible = true;
		prev_mc.visible = true;
		up_mc.visible = true;
		down_mc.visible = true;
		text123.visible = true;
		sphere.visible = true;
		sphereBig.visible = true;
		viewport.buttonMode = false;
		
		
		close_mc.removeEventListener(MouseEvent.CLICK, closeClick1)
		close_mc.removeEventListener(MouseEvent.CLICK, closeClick2)
		close_mc.removeEventListener(MouseEvent.CLICK, closeClick3)
		close_mc.removeEventListener(MouseEvent.CLICK, closeClick4)
		close_mc.removeEventListener(MouseEvent.CLICK, closeClick5)
		close_mc.removeEventListener(MouseEvent.CLICK, closeClick6)
		
		renderer.renderScene(scene, camera, viewport);
		
}
 
function btOn():void
{
	viewport.buttonMode =  true;
}
 
function btOff():void
{
	viewport.buttonMode =  true;
}
 
 
function stay1(e:Event):void
{
	addEventListener(Event.ENTER_FRAME, stay);
	removeEventListener(Event.ENTER_FRAME, animateCube1);
}
 
function stay(e:Event):void
{
 	
	
	removeEventListener(Event.ENTER_FRAME, controlCube1);
	cube2.removeEventListener(MouseEvent.MOUSE_OVER, controlCube);
	cube2.removeEventListener(MouseEvent.MOUSE_OUT, loop1);
	
 
	viewport.buttonMode = false;
	renderer.renderScene(scene, camera, viewport);
 
 
}
 
function stopAnim():void
{
		
		removeEventListener (Event.ENTER_FRAME, loop);
		addEventListener(Event.ENTER_FRAME, stay);
		
		
		
		
}
function animateCube(e:Event):void
{
	
	removeEventListener(Event.ENTER_FRAME, stay);
	addEventListener(Event.ENTER_FRAME, animateCube1);
	
	
}
 
 
 
function animateCube1(e:Event):void
{
 
		viewport.buttonMode = true;
		
	
	renderer.renderScene(scene, camera, viewport);
 
 
}
 
 
function controlCube(e:Event):void
{
	
	removeEventListener(Event.ENTER_FRAME, loop);
	addEventListener(Event.ENTER_FRAME, controlCube1);
	
	
}
 
 
 
function controlCube1(e:Event):void
{
	var xDist:Number = mouseX - stage.stageWidth * 0.5;
	var yDist:Number = mouseY - stage.stageHeight * 0.5;
 
 
		cube2.rotationY -= -xDist * 0.05;
		cube2.rotationX -= -yDist * 0.05;
		viewport.buttonMode = true;
		
	
	renderer.renderScene(scene, camera, viewport);
 
 
}
 
function rotateCube1(e:Event):void
{
 
next_mc.addEventListener( MouseEvent.CLICK, moveNextSide);
prev_mc.addEventListener( MouseEvent.CLICK, movePrevSide);
 
up_mc.addEventListener( MouseEvent.CLICK, moveUpSide);
down_mc.addEventListener( MouseEvent.CLICK, moveDownSide);
 
	viewport.buttonMode = true;
	renderer.renderScene(scene, camera, viewport);
 
 
}
 
function rotateCube(e:Event):void
{
 
	removeEventListener(Event.ENTER_FRAME, loop);
	addEventListener(Event.ENTER_FRAME, rotateCube1);
 
}
 
 
function moveNextSide( e:MouseEvent ){
	var newY = cube2.rotationY +89
	Tweener.addTween(cube2, {rotationY:newY, time:1, transition:"easeoutexpo"});
	var CnewY = cube3.rotationY +89
	Tweener.addTween(cube3, {rotationY:CnewY, time:1, transition:"easeoutexpo"});
	sndSwish.play();
	
}
 
function movePrevSide( e:MouseEvent ){
	var newY = cube2.rotationY -89
	Tweener.addTween(cube2, {rotationY:newY, time:1, transition:"easeoutexpo"});
	var CnewY = cube3.rotationY -89
	Tweener.addTween(cube3, {rotationY:CnewY, time:1, transition:"easeoutexpo"});
	sndSwish.play();
}
 
function moveUpSide( e:MouseEvent ){
	var newX = cube2.rotationX +89
	Tweener.addTween(cube2, {rotationX:newX, time:1, transition:"easeoutexpo"});
	var CnewX = cube3.rotationX +89
	Tweener.addTween(cube3, {rotationX:CnewX, time:1, transition:"easeoutexpo"});
	sndSwish.play();
	
}
 
function moveDownSide( e:MouseEvent ){
	var newX = cube2.rotationX -89
	Tweener.addTween(cube2, {rotationX:newX, time:1, transition:"easeoutexpo"});
	var CnewX = cube3.rotationX -89
	Tweener.addTween(cube3, {rotationX:CnewX, time:1, transition:"easeoutexpo"});
	sndSwish.play();
}
 
 
 
 
function faceClick(e:MouseEvent):void
{
	xDista = 0;
	yDista = (135 - 15);
	zScale= -200
	p1 = 0;
	p2 = -300;
	p3 = -600
	p4 = -900
	p5 = -1200
	p6 = -1500
	doZoom1();
}
 
 
 
function face2Click(e:MouseEvent):void
{
 
	xDista = -90;
	yDista = (-45 - 15);
	zScale= -200
	p5 = 0;
	p4 = 300;
	p3 = 600
	p2 = 900
	p1 = 1200
	p6 = -300
	doZoom2();
	
	
}
 
 
 
function face3Click(e:MouseEvent):void
{
	xDista = 0;
	yDista = (-135- 15);
	zScale= -200
	p3 = 0;
	p2 = 300;
	p1 = 600
	p6 = -900
	p5 = -600
	p4 = -300
	doZoom3()
	
 
}
 
 
 
function face4Click(e:MouseEvent):void
{
	xDista = 0;
	yDista = (45 - 15);
	zScale= -200
	p4 = 0;
	p3 = 300;
	p2 = 600
	p1 = 900
	p6 = -600
	p5 = -300
	doZoom4();
	
 
	
}
 
 
 
function face5Click(e:MouseEvent):void
{
	xDista = 0;
	yDista = (-45 - 15);
	zScale= -200
 
		p1 = 300;
	p2 = 0;
	p3 = -300
	p4 = -600
	p5 = -900
	p6 = -1200
	doZoom5();
 
	
}
 
 
 
function face6Click(e:MouseEvent):void
{
	xDista = -90;
	yDista = (135 - 15);
	zScale= -200
	p6 = 0;
	p5 = 300;
	p4 = 600
	p3 = 900
	p2 = 1200
	p1 = 1500
	doZoom6();
	
 
	
}
 
 
 
function closeClick1(e:MouseEvent):void
{
	unZoom1()
}
 
function learnClick1(e:MouseEvent):void
{
	Tweener.addTween( planeFader, {y:0,time:1,transition:"easeoutexpo"})
	navigateToURL(new URLRequest("DStemplate.php?pid=2"), "_self");
	
 
}
 
 
function doRotate():void
{
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo"})
	
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	
	sndZip.play();
	
}
 
 
function doZoom1():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
	
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick1);
	closePlane.visible = true;
	button.visible = true;
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false;
	sphere.visible = false, sphereBig.visible = false
	learn_but.addEventListener(MouseEvent.CLICK, learnClick1);
	
 
}
	
function unZoom1():void
{
	addEventListener (Event.ENTER_FRAME, loop);
	setTimeout( resetPlane, 100 )
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick1);
	Tweener.addTween( camera, { y:100,zoom:5.5, rotationX:0, time:.5})
	trace("unZoom1")
	
	
	
}
	
function resetPlane() 
{	
	Tweener.addTween( cube2, {y:100, transition:"easeoutexpo" })
	Tweener.addTween( planeFader, {y:-300, transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-950,transition:"easeoutexpo" })
	trace("reset")
	Tweener.addTween( plane1, { y:-300,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:-600,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:-900,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:-1200,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:-1500,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:-1800,transition:"easeoutexpo", time:.5})
	cube2.addEventListener(MouseEvent.MOUSE_OVER, controlCube);
	cube2.addEventListener(MouseEvent.MOUSE_OUT, loop1);
	removeEventListener(Event.ENTER_FRAME, stay);
	closePlane.visible = false
	button.visible = false;
	
	close_mc.alpha = 0;
	close_mc.buttonMode = false;
	
}
 
 
 
 
function closeClick2(e:MouseEvent):void
{
	unZoom2()
}
function learnClick2(e:MouseEvent):void
{
	
	Tweener.addTween( planeFader, {y:0,time:1,transition:"easeoutexpo"})
	navigateToURL(new URLRequest("DStemplate.php?pid=4"), "_self");
}
 
function doZoom2():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
 
	
	
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false; sphere.visible = false, sphereBig.visible = false;
	
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick2);
	closePlane.visible = true;
	button.visible = true;
	learn_but.addEventListener(MouseEvent.CLICK, learnClick2);
	
	
	
}
	
function unZoom2():void
{
	
	addEventListener (Event.ENTER_FRAME, loop);
	setTimeout( resetPlane, 100 )
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick2);
	Tweener.addTween( camera, { y:100,zoom:5.5, rotationX:0, time:.5})
	trace("unZoom2")
	
	
}
	
 
 
 
function closeClick3(e:MouseEvent):void
{
	unZoom3()
}
function learnClick3(e:MouseEvent):void
{
	navigateToURL(new URLRequest("DStemplate.php?pid=5"), "_self");
}
 
 
function doZoom3():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false; sphere.visible = false, sphereBig.visible = false;
 
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick3);
	closePlane.visible = true;
	button.visible = true;
	learn_but.addEventListener(MouseEvent.CLICK, learnClick3);
	
	
}
	
function unZoom3():void
{
	addEventListener (Event.ENTER_FRAME, loop);
 
	setTimeout( resetPlane, 100 )
	
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick3);
	trace("unZoom3")
	
	
}
 
 
 
 
function closeClick4(e:MouseEvent):void
{
	unZoom4()
}
function learnClick4(e:MouseEvent):void
{
	Tweener.addTween( planeFader, {y:0,time:1,transition:"easeoutexpo"})
	navigateToURL(new URLRequest("DStemplate.php?pid=3"), "_self");
}
 
 
function doZoom4():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
	
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false; sphere.visible = false, sphereBig.visible = false;
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick4);
	closePlane.visible = true;
	button.visible = true;
	learn_but.addEventListener(MouseEvent.CLICK, learnClick4);
	
	
}
	
function unZoom4():void
{
	addEventListener (Event.ENTER_FRAME, loop);
 
	setTimeout( resetPlane, 100 )
 
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick4);
	trace("unZoom4")
	
	
}
	
 
function closeClick5(e:MouseEvent):void
{
	unZoom5()
}
function learnClick5(e:MouseEvent):void
{
	Tweener.addTween( planeFader, {y:0,time:1,transition:"easeoutexpo"})
	navigateToURL(new URLRequest("DStemplate.php?pid=1"), "_self");
}
 
function doZoom5():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	  	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false; sphere.visible = false, sphereBig.visible = false;
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	sndZip.play();
	
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick5);
 
	closePlane.visible = true;
 
	button.visible = true;
	learn_but.addEventListener(MouseEvent.CLICK, learnClick5);
	
	
}
	
function unZoom5():void
{
	addEventListener (Event.ENTER_FRAME, loop);
	//Tweener.addTween( plane5, { y:-550, time:1})
	setTimeout( resetPlane, 100 )
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick5);
	trace("unZoom5")
	
	
}
	
 
 
function closeClick6(e:MouseEvent):void
{
	unZoom6()
}
function learnClick6(e:MouseEvent):void
{
	Tweener.addTween( planeFader, {y:0,time:1,transition:"easeoutexpo"})
	navigateToURL(new URLRequest("contact.php"), "_self");
}
 
 
function doZoom6():void
{
	Tweener.addTween( cube2, {y:-400,transition:"easeoutexpo" })
	Tweener.addTween( cube, {x:-270,rotationX:xDista, rotationY:yDista,z:zScale, time:1,transition:"easeoutexpo", onComplete:stopAnim})
	Tweener.addTween (camera, { y:200, zoom:9, rotationX:20, time:.5})
	next_mc.visible = false;
	prev_mc.visible = false;
	up_mc.visible = false;
	down_mc.visible = false; text123.visible = false; sphere.visible = false, sphereBig.visible = false;
	
	Tweener.addTween( plane1, { y:p1,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane2, { y:p2,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane3, { y:p3,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane4, { y:p4,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane5, { y:p5,transition:"easeoutexpo", time:.5})
	Tweener.addTween( plane6, { y:p6,transition:"easeoutexpo", time:.5})
	
	close_mc.alpha = 1;
	close_mc.buttonMode = true;
	close_mc.addEventListener(MouseEvent.CLICK, closeClick6);
	sndZip.play();
	
	closePlane.visible = true;
 
	button.visible = true;
	learn_but.addEventListener(MouseEvent.CLICK, learnClick6);
	
	
}
	
function unZoom6():void
{
	addEventListener (Event.ENTER_FRAME, loop);
	setTimeout( resetPlane, 100 )
	learn_but.removeEventListener(MouseEvent.CLICK, learnClick6);
	trace("unZoom6")
}
 
 
 
 
 
 
 
 
stop();

Open in new window

0
 
section25Commented:
Are you responding to me or rascalpants?

If you are responding to me, I don't see the varible definitions for the functions, so it won't work properly as I laid it out. If you are using rascalpants suggestions, then just ignore mine.

Thanks.
0
 
mmucomAuthor Commented:
Wow great... i understand this part...solves my probelm

So now if i was to call another function (doZoom) from within faceClick

1) Will it pass these p1,p2, p3 values in the doZoom(); function??

2)  will i have to refer to the whichFace again or have something withinh the doZoom(p1:int,   p2:int) of the function??

3) I have 2 listeners within the doZoom function

learn_but.addEventListener(MouseEvent.CLICK, learnClick1); this is a url....how do i set up the function like this??

var learnClick1 = function(e:Event){learnClick(new URLRequest("DStemplate.php?pid=2"))};
will this work??

thanks

0
 
mmucomAuthor Commented:
the first was @rascalpants

the next is @section25... M awarding points to you..thanks
0
 
rascalpantsCommented:
just to clear things up for anyone else who visits this PAQ...

Even though you are not able to pass extra "parameters" while using the AS 3.0 event listeners, you CAN pass properties by using an object assignment while setting up the event listener for the object.  

glad your question was answered...


rp / Zone Advisor
0
 
section25Commented:
1) it will if you pass them to it. So within the faceClick function, you can simply pass them along

faceClick(whichFace:int,p_1:int,p_2:int,p_3:int, etc...){
      p1 = p_1;
      p2 = p_2;
      p3 = p_3;
     doZoom(whichFace,p_1,p_2,etc...)
}

You will have to set up doZoom to accept the variables as in:
function doZoom(which_face,p1,p2,etc) {
}

2) I think is the same answer as 1.

3) No that won't work like that, you simply need to pass the URL as a string and then use that to set up the new URL request.

Like this:

var learnClick1 = function(e:Event){learnClick("DStemplate.php?pid=2")};

function learnClick1(which_url:String){
  var url:String;
  var request:URLRequest;
  var myLoader:Loader = new Loader();
  var url = which_url;
  request = new URLRequest(url);
  myLoader.load(request);
}



0
 
mmucomAuthor Commented:
thanks so much!! I love this place!!
0
 
rascalpantsCommented:
section25,

as explained earlier, it is better to pass in an object in this case, instead of continuing to pass in a bunch of parameters... this will definitely speed up programming, because you only setup the properties once, instead of having to pass parameters to a function. the only thing that needs to be passed is one parameter, which is the object. This give the programmer the flexibility to pass in other parameters that "can" be used later down the string of processing...

for example... say you need to pass quite a few parameters, but you don't need to use all of them, or you don't need to use them until they are passed to another method/fucntion down the road...

its is much cleaner, to use my method instead of multiple functions using all the same parameters, or worse, only using a few... The only caveat to this, is debugging a solution that has a value that is not setup properly... but at least you can always go to the origin of the object to fix.

we differ quite a bit in programming style, and I would not recommend assigning a function as a propertie, just to call another seperate function to pass in a parameter... it is a bit sloppy and much harder to debug... but then again, i have been known to use a bit of short hand coding AFTER i know it works, just to keep the document "tighter

below is how I would setup the code you have given... I did a bit of consolidation, but I still kept enough of the code seperated for other developers to easily understand what is happening. And obviously you can add many more properties to the object(in this case a movieclip) as needed.

to each his/her own...

rp / Zone Advisor

learnClick1.theURL = "DStemplate.php?pid=2";
learnClick1.addEventListener( MouseEvent.CLICK, learnClick );
 
learnClick2.theURL = "DStemplate.php?pid=1002";
learnClick2.addEventListener( MouseEvent.CLICK, learnClick );
 
learnClick3.theURL = "DStemplate.php?pid=20087";
learnClick3.addEventListener( MouseEvent.CLICK, learnClick );
 
learnClick4.theURL = "DStemplate.php?pid=74636";
learnClick4.addEventListener( MouseEvent.CLICK, learnClick );
 
 
// one method/function that can be used by many event listeners
 
function learnClick( e:Event ):void
{
  var theURL:String = e.target.theURL;
  var theRequest:URLRequest = new URLRequest( theURL );
  var theLoader:Loader = new Loader();
  theLoader.load( theRequest );
}

Open in new window

0
 
mmucomAuthor Commented:
@section25: can i do this?

function doZoom(whichURL,p1,p2,etc) {

learn_but.addEventListener( MouseEvent.CLICK, learnClick(whichURL) );

}

@rascalpants: Ll def try out your way for sure...thanks



0
 
rascalpantsCommented:
mmucom,

I would setup all of your event listeners prior to any other code.  What you have is a function, doZoom, that when called, will setup a listener... but I assume you actually want to call the learnClick button instead...

rp / za
0
 
section25Commented:
No, you can't pass the paramter inside the event listener.
0
 
mmucomAuthor Commented:
Cool..ll figure it out thanks for getting me through this far :)
0
 
section25Commented:
You're welcome.

Good Luck
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 8
  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now