?
Solved

flash AS3 question

Posted on 2008-11-14
1
Medium Priority
?
875 Views
Last Modified: 2013-11-11
I have the following code, I am trying to slow the scroll speed of the mouse event but I do not know where to change it.

Please help
import org.papervision3d.scenes.*;
import org.papervision3d.objects.*;
import org.papervision3d.cameras.*;
import org.papervision3d.materials.*;
import gs.*;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
stage.align = "TL";
stage.scaleMode = StageScaleMode.NO_SCALE;
 
import kudos.*;
 
 
 
// init 
var w : Number = 150;
var h : Number = 220;
var d : Number = 25;
var n : Number = 3;
var pausing = false;
 
var defaultZoom	: Number = 5;
var maxZoom		: Number = 10;
var minZoom		: Number = 1;
var glowColor	: Number = 0xEAFD9B;
var popout		: Number = 0.7;//0-1
var fitScreen   : Boolean = true;
var xmlFile		: String = "xml/picTail.xml";
var vFullscreen : Boolean = false;
 
//variables
 
var myLd: Loader;
var nPics: Number = 50;
var cPics: Number = 0;
var cp : *;
var pContainer : Dictionary = new Dictionary(true);
 
var mcloader : MovieAssetMaterial = new MovieAssetMaterial("loader", true);
var ploader:Plane = new Plane(mcloader, 25, 25, 1, 1);
 
var info: info_mc = new info_mc();
info.visible = true;
info.y = stage.stageHeight;
 
info.des_txt.autoSize = TextFieldAutoSize.LEFT;
info.des_txt.multiline = true;
info.des_txt.wordWrap = true;
 
var tz: Number = defaultZoom;
 
addEventListener(Event.ENTER_FRAME, rotLoader);
 
// Create the container Sprite
var container:Sprite = new Sprite();
container.x = stage.stageWidth * 0.5;
container.y = stage.stageHeight * 0.5;
addChild(container);
var ld: URLLoader = new URLLoader();
ld.addEventListener(Event.COMPLETE, init);
ld.load(new URLRequest(LoaderInfo(root.loaderInfo).parameters.xmlFile));
var xml: XML;
function init(evt: Event){
	try {
		xml = new XML(ld.data);
		loadImg(xml.item[cPics].@link);
		nPics = xml.item.length();
		n = xml.@row;
	} catch (e: Error){
	}
}
// Setup the 3D scene
var scene:MovieScene3D = new MovieScene3D(container);
var camera:FreeCamera3D = new FreeCamera3D();
camera.z = -stage.stageHeight*4/3;
camera.y = -(h*n+d*(n-1))/2+120;
 
camera.extra = {
	x: 100, ry : 100, y: -(h*n+d*(n-1))/2+120, cz: camera.z
}
stage.addEventListener(MouseEvent.MOUSE_WHEEL, zoomCamera);
stage.addEventListener(Event.ENTER_FRAME, render);
stage.addEventListener(Event.RESIZE, update);
stage.displayState = (vFullscreen) ? "fullScreen" : "normal";
 
var clickArea : Sprite = drawRect(100,100);
clickArea.addEventListener(MouseEvent.CLICK, getlink);
clickArea.buttonMode = true;
 
var closeBtn : close_btn = new close_btn();
closeBtn.addEventListener(MouseEvent.CLICK, clkClose);
closeBtn.buttonMode = true;
 
function update(...rest){
	TweenMax.to(container,0.25,{x: stage.stageWidth * 0.5, y:stage.stageHeight * 0.5, onUpdate: mov});
}
function mov(){
	//cp.container.width = stage.stageWidth;
	//cp.container.height = stage.stageH
	//try {
//		//trace(cp.container)
//		if (!TweenMax.isTweening(cp.container)){
//			var obj: Object = {width: stage.stageWidth, height: stage.stageHeight, parent: stage, x: 0, y: 0}
//			kFit(cp.container, obj, 5);
//			kAlign(cp.container, obj);
//		}
//	} catch (e: Error){}
	
	
	
 
	info.des_txt.width = stage.stageWidth-2*info.des_txt.x;
	info.info_bg.width = stage.stageWidth;
	info.info_bg.height = info.des_txt.height;
	var h: Number = stage.stageHeight;
	if (pausing){
		h -= info.des_txt.height;
	}		
	info.y = h;
	try {
		if (cp.container.width>stage.stageWidth || cp.container.height>stage.stageHeight){
			var obj: Object = {width: stage.stageWidth, height: stage.stageHeight, parent: stage}
			kFit(clickArea, obj);
			//kAlign(clickArea, obj);
			clickArea.x = (stage.stageWidth-clickArea.width)/2;
			clickArea.y = (stage.stageHeight-clickArea.height)/2;
			
		} else {
			clickArea.x = cp.container.parent.x-cp.container.width/2;
			clickArea.y = cp.container.parent.y-cp.container.height/2;
			clickArea.width = cp.container.width;
			clickArea.height = cp.container.height;
		}
		
	} catch (e: Error){}
	
	try {
		if (video_hld.parent != null && video_hld.visible == true){
			cp.container.visible = false;
		}
		video_hld.x = clickArea.x;
		video_hld.y = clickArea.y;
		video_hld.width = clickArea.width;
		video_hld.height = clickArea.height;
	} catch(e: Error){}
	
	try {
		if (swf_hld.parent != null && swf_hld.visible == true){
			cp.container.visible = false;
		}
		swf_hld.x = clickArea.x;
		swf_hld.y = clickArea.y;
		swf_hld.width = clickArea.width;
		swf_hld.height = clickArea.height;
	} catch(e: Error){}
	//trace(swf_hld);
	
	closeBtn.x = clickArea.x+clickArea.width-closeBtn.width-10;
	closeBtn.y = clickArea.y+10;	
	//********************	
}
 
function zoomCamera(evt:MouseEvent){
	var tmp: Number = tz+evt.delta/10;
	if (tmp<minZoom){tmp=minZoom}
	if (tmp>maxZoom){tmp=maxZoom}
	tz =tmp;
}
 
function render(e:Event):void
{	
	if (!pausing){
	var pos : Number = stage.mouseX/stage.stageWidth*2-1;
	//recalculate the target postion
	camera.extra.ry = pos*40;
	camera.extra.x += pos*80;
	
	//at two side
	if (camera.extra.x<1.5*(w+d)){
		camera.extra.ry = 0;
		camera.extra.x = 1.5*(w+d);
	}
	if (camera.extra.x>(nPics/n-2)*(w+d)){
		camera.extra.ry = 0;
		camera.extra.x = (nPics/n-2)*(w+d);
	}
	//ease render
	camera.x += (camera.extra.x - camera.x)/5;	
	camera.rotationY += (camera.extra.ry - camera.rotationY)/8;
	}
	camera.zoom += (tz-camera.zoom)/5;
	scene.renderCamera(camera);
	
}
 
if (popout==0){
	popout = 0.05;
}
if (popout==1){
	popout = 0.99;
}
 
function clicked(evt: * = null){
	try{
		video_hld.bar_player.clkStop();
	} catch (e:Error){}	
	var p: * = pContainer[evt.target];
	if (!p.extra.chk){
		// click first time	
		stage.removeEventListener(MouseEvent.MOUSE_WHEEL, zoomCamera);
		
		try {
			//
			TweenMax.to(cp, 1,{z: cp.extra.cz, scaleX : 1, scaleY : 1});
			if(cp.extra["reflect"] != undefined){
				TweenMax.to(cp.extra["reflect"], 1, {z: 0});
			}			
			pContainer["temp"] = cp.container["filters"];
			cp.container["filters"] = null;
			delete pContainer["temp"];
			cp.extra.chk = false;hideClose();
		} catch (e: Error){};
		
		var k: Number = (tz-minZoom)/(maxZoom-minZoom)+1;
		TweenMax.to(p, 1, {z: popout*camera.z/k,onComplete:showInfo,onCompleteParams:[p, evt.target]});
		TweenMax.to(p.container, 1, {glowFilter:{color:glowColor, alpha:1, blurX:8, blurY:8, strength:2}});
		TweenMax.to(camera, 2, {x: p.extra.cx, y: p.extra.cy, rotationY: 0,onComplete:cameraComplete,onCompleteParams:[p, evt.target]});
		
		if(p.extra["reflect"] != undefined){
			TweenMax.to(p.extra["reflect"], 1, {z: -150});
		}		
		cp = p;
		pausing = true;
	} else {
		// second click
		//hideClose();
		TweenMax.to(p, 1,{z: p.extra.cz, scaleX : 1, scaleY : 1, onComplete: returnMouseWheel});
		if(p.extra["reflect"] != undefined){
			TweenMax.to(p.extra["reflect"], 1, {z: 0});
		}
		pContainer["temp"] = p.container["filters"];
		p.container["filters"] = null;
		delete pContainer["temp"];
		
		TweenMax.to(camera, 2, {y: camera.extra.y})
		pausing = false;
		hideInfo();hideClose();
	}
	p.extra.chk = !p.extra.chk;
}
 
function returnMouseWheel(){
	stage.addEventListener(MouseEvent.MOUSE_WHEEL, zoomCamera);
}
 
 
function cameraComplete(...rest){
	var p	: * = rest[0];
	var tar	: * = rest[1];
	
	var scl : Number = p.extra.wP/tar.width;
	
	if (fitScreen){
		scl *= Math.min((stage.stageWidth-10)/p.extra.wP, (stage.stageHeight-10)/p.extra.hP);//5 = - outter glow effect border
	}
	TweenMax.to(rest[0], 1, {scaleX: scl, scaleY: scl, onComplete: showClose, onCompleteParams: [p, tar]});
}
function showInfo(...rest){
	var p	: * = rest[0];
	info.des_txt.htmlText = p.extra.des;
	addChild(info);
	info.visible = true;
	pausing = false;
	mov();
	pausing = true;
	TweenMax.to(info, 0.5, {y: stage.stageHeight-info.des_txt.height});	
}
 
function hideInfo(){
	TweenMax.to(info, 0.5, {y: stage.stageHeight, onComplete: inviInfo});
}
 
function inviInfo(){
	info.visible = false;
}
 
var video_hld : video_holder;
var swf_hld : MovieClip;
 
 
function showClose(...rest){
	//stage.mouseEnabled = false;
	
	//stage.removeEventListener(MouseEvent.MOUSE_WHEEL, zoomCamera);
	cp.container.mouseEnabled = false;
	clickArea.width = cp.container.width;
	clickArea.height = cp.container.height;
	clickArea.x = cp.container.parent.x-cp.container.width/2;
	clickArea.y = cp.container.parent.y-cp.container.height/2;
	
	closeBtn.x = clickArea.x+clickArea.width-closeBtn.height-15;
	closeBtn.y = clickArea.y+10;
	
	if(cp.extra.video != ""){
		//trace(cp.extra.video);
		hideInfo();
		video_hld = new video_holder();	
		stage.addChild(video_hld);
		
		video_hld.bar_player.init({view: video_hld.video_dsp,  mode: "flv"});
		video_hld.x = clickArea.x;
		video_hld.y = clickArea.y;
		
		video_hld.video_dsp.getChildAt(0).width = video_hld.video_bg.width = clickArea.width;
		video_hld.video_dsp.getChildAt(0).height = video_hld.video_bg.height = clickArea.height;
		
		video_hld.bar_player.resizeVideo({w: clickArea.width, h: clickArea.height});
		video_hld.bar_player.resizeController(clickArea.width);
		video_hld.bar_player.y = clickArea.height - video_hld.bar_player.height;
		video_hld.bar_player.x = (clickArea.width -  video_hld.bar_player.width)/2;
		video_hld.bar_player.loadMedia({link: cp.extra.video}, false);
	} else if (cp.extra.swf != ""){
		//trace(cp.extra.swf);
		hideInfo();
		swf_hld = new MovieClip();
		//if (swf_hld==null) swf_hld = new MovieClip();
		stage.addChild(swf_hld);
		while (swf_hld.numChildren>0){
			swf_hld.removeChildAt(0);
		}
		swf_hld.x = clickArea.x;
		swf_hld.y = clickArea.y;
		
		LoadIMG.load(String(cp.extra.swf), {to: swf_hld, form: {x: 0, y: 0, width: clickArea.width, height: clickArea.height}});
	} else {
		stage.addChild(clickArea);
	}
	stage.addChild(closeBtn);
}
 
function hideClose(...rest){	
	cp.container.mouseEnabled = true;
	cp.container.scaleX = cp.container.scaleY = 1;
	cp.container.visible = true;
	
	try {
		stage.removeChild(closeBtn);		
	} catch(e: Error){}
	try {
	stage.removeChild(clickArea);
	} catch(e: Error){}
	try {
	stage.removeChild(video_hld);
	} catch(e: Error){}
	try {
	stage.removeChild(swf_hld);
	} catch(e: Error){}
}
 
function clkClose(evt: MouseEvent){
	try{
		video_hld.bar_player.clkStop();
	} catch (e:Error){}	
	clicked({target: cp.container});
	
	//stage.addEventListener(MouseEvent.MOUSE_WHEEL, zoomCamera);
}
 
 
function over(evt: Event){
 
}
 
function out(evt: Event){
 
}
 
function getlink(evt: MouseEvent = null){
	navigateToURL(new URLRequest(cp.extra.url), "_blank");
}
 
function loaded(evt: Event){
	scene.removeChild(ploader);
	try{
	var bmd: BitmapData = Bitmap(myLd.content).bitmapData;
	var bm : BitmapMaterial = new BitmapMaterial(bmd);
	bm.smooth = false;
	var scl : Number = Math.max(evt.target.width/w, evt.target.height/h);
	var p:Plane = new Plane(bm, evt.target.width/scl, evt.target.height/scl, 2, 2);
	
	scene.addChild(p,"p"+cPics);
	p.x = int(cPics/n)*(w+d);
	p.y = -(cPics % n)*(h+d)-(h-evt.target.height/scl)/2+100;
	p.extra = {
		chk : false,
		cz  : p.z, cx  : p.x, cy: p.y,
		scl : scl,
		des : xml.item[cPics],
		url : xml.item[cPics].@url,
		video: (xml.item[cPics].@flv != undefined) ? xml.item[cPics].@flv : "",
		swf	 : (xml.item[cPics].@swf != undefined) ? xml.item[cPics].@swf : "",
		wP:evt.target.width,
		hP:evt.target.height
	}
	// reflect pictures
	if (cPics % n==n-1){
		bm.doubleSided = true;
		bm.name = "back";
		var bmp2:BitmapData = new BitmapData( w, h, true, 0x000000);
		// Flip vertical
		var m:Matrix = new Matrix();
		m.createBox(1/scl, -1/scl, 0, (w-p.extra.wP/scl)/2, h-(h-evt.target.height/scl));
		bmp2.draw( bmd, m );		
		//Reflection Bitmap Object
		var b2:Bitmap = new Bitmap(bmp2);		
		// Reflection mask
		m.createGradientBox(w, h,Math.PI/2,h);
		var mymask:Shape = new Shape();
		mymask.graphics.lineStyle(0,0,0);
		mymask.graphics.beginGradientFill("linear", [0x000000, 0x000000],[0.5, 0], [0, 190],m) ;
		mymask.graphics.drawRect(0,0,w,h);
		mymask.graphics.endFill();
		// CacheaAsBitmap
		mymask.cacheAsBitmap = true;
		b2.cacheAsBitmap = true;		
		// Create mask
		b2.mask = mymask;
		addChild(b2);
		addChild(mymask);		
		var bmp3:BitmapData = new BitmapData(w, h, true, 0x000000);
		bmp3.draw(b2);		
		// Create Reflection plane
		var bm2:BitmapMaterial = new BitmapMaterial(bmp3);
		bm2.smooth = true;
		bm2.doubleSided = true;		
		var p2:Plane = new Plane(bm2, 1, 0, 2, 2);		
		p2.x = int(cPics/n)*(w+d);
		p2.y =100 -(cPics % n)*(h+d)-(h+d/5);
 
		p.extra["reflect"] = p2;		
		scene.addChild(p2);
		removeChild(b2);
		removeChild(mymask);
		p.extra.ref = p2;
	}	
	p.container.buttonMode = true;
	p.container.name = "p"+cPics;
	p.container.addEventListener(MouseEvent.CLICK, clicked);
	pContainer[p.container] = p;
	} catch(e: Error){};	
	cPics++;
	(cPics<nPics) ? loadImg(xml.item[cPics].@link) : null;
}
function loadImg(lnk: String){
	myLd = new Loader();
	myLd.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);	
	myLd.load(new URLRequest(lnk));
	ploader.x = int(cPics/n)*(w+d);
	ploader.y = 100-(cPics % n)*(h+d);
	scene.addChild(ploader);
}
function rotLoader (...rest){
	ploader.rotationZ+=10;
}
function drawRect(w, h: Number): Sprite{
	var sprt : Sprite = new Sprite();
	with (sprt.graphics){
		beginFill(0, 0);
		drawRect(0, 0, w, h);
		endFill();
	}
	return sprt;
}
//stage.addChild(update_mc);
//************************************************** ADD VIDEO ***************************************************
//bar_player.init({view: video_dsp,  mode: "flv"});
//bar_player.loadMedia("1.flv", false);
 
//****************************************************************************************************************

Open in new window

0
Comment
Question by:krisred
1 Comment
 
LVL 14

Accepted Solution

by:
Designbyonyx earned 2000 total points
ID: 22981084
In the following function, try fooling around with the number 10 - if you make it larger... it should slow things down- I assume this is the mouse event your were talking about:

function zoomCamera(evt:MouseEvent){
	var tmp: Number = tz+evt.delta/10;
	if (tmp<minZoom){tmp=minZoom}
	if (tmp>maxZoom){tmp=maxZoom}
	tz =tmp;
}

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question