Skip navigation
Currently Being Moderated

3D Carousel

Apr 6, 2012 2:59 PM

Hi everyone,

 

Please help. I have script for a 3d Carousel everything works. But I want to get the images to stay facing the front.

I can change most things but am having trouble with getting the images front facing.

The property y.rotation I need to change is not in the same fuction as so I can't dinamically change the value using the eventlistner.

I have tried to do this but have had no success.

 

p.rotationY = 90; is the value I need to change dynamically but it is in the cacheimages section function initLoadCache(evt:Event):void. I need to be able to get this into the function render(e:Event):void from the addEventListener(Event.ENTER_FRAME, render); which is also in the function initLoadCache(evt:Event):void {

 

I think I can figure the rest out but need some help to figure this out.  

 

Script:

 

var scene:Scene3D;
var cam:Camera3D;
var _numActiveImage:uint;
var p_link:Boolean;
var total:Number;
var url_thumb:Array;
var container:Sprite;
container= new Sprite();
addChild(container);
var anglePer:Number;
var p_dict:Dictionary
var pc:Plane
var numOfRotations:Number = 1;
var yPos:Number;
yPos= 0;
var angle:Number;
angle= 0;
var angle2:Number;
angle2= 0;
var camX:Number;


///////////////////////////////////////////////////////// removeAllChildren ///////////////////////////////////////////////////////////////////// ///////////
function removeAllChildren(_container : DisplayObjectContainer, _index : uint = 0):void{
   var _numChild : uint = _container.numChildren;
   if (_numChild > _index){
    for (var i:int = _index; i < _numChild; i++) {
     _container.removeChildAt(_container.numChildren - 1);
    }
   }
  };
buildCategory();
create_thumbnail();
/////////////////////////////////////////////////////// create_thumbnail //////////////////////////////////////////////////////////////
function create_thumbnail():void {
removeEventListener(Event.ENTER_FRAME, render);
if(container) {
if (Tweener.getTweenCount(container) > 0) Tweener.removeTweens(container);
removeAllChildren(container, 0);
removeChild(container);
}
subpageInfo(_counterPage);
url_thumb = [];
total = subPageArr.length;
    for( var j:uint = 0; j < total; j++ ){
  url_thumb.push(subPageArr[j]._thumb);
}
container = new Sprite();
addChild(container);

 

addChildAt(container, (getChildIndex(fullscreen_mc)-1));
//addChildAt(fullscreen_mc, getChildIndex(container));

 

scene = new MovieScene3D(container);
cam = new Camera3D();
p_dict= new Dictionary();
pc= new Plane();
pc.visible = false;
cam.target = pc;
yPos = 0;
angle = 0;
cam.zoom = 0.5;
cam.y = 700;
    p_link = false;
anglePer = ((Math.PI*2) * numOfRotations) / total;
    cacheImages(url_thumb);
addChildAt(categoryMc,(getChildIndex(container)+1));
};


function p_rollover(me:MouseEvent) {
var sp:Sprite = me.target as Sprite;
var tw:Tween = new Tween(sp, 'alpha', Strong.easeOut, 1, 0.5, 0.6, true);
}
function p_rollout(me:MouseEvent) {
var sp:Sprite = me.target as Sprite;
var tw:Tween = new Tween(sp, 'alpha', Strong.easeOut, 0.5, 1, 0.6, true);
}
function p_click(me:MouseEvent) {
if(!p_link) {
p_link = !p_link;
var sp:Sprite = me.target as Sprite;
var s_no:Number = parseInt(sp.name.slice(3,6));
_numActiveImage = s_no;
onResizeStageApp();
new Tween(gallery1, 'alpha', Strong.easeOut, 0, 1, 1, true);
gallery1.visible = true;
openImage();

 

//_page.visible = true;
}
};


function render(e:Event):void {
if(container) {
container.x = stage.stageWidth/2;
container.y = stage.stageHeight/2;
}
var dist2:Number = ((stage.mouseX) - stage.stageWidth/2) * 0.0001;
angle += dist2;


//test

p.rotationY += angle;
//testEnd


if(!p_link) {
cam.y += ((stage.mouseY) * 0.04 - cam.y) * 0.08;
cam.x += (- Math.cos(angle) * 350-cam.x) * 0.08;
cam.z += (Math.sin(angle) * 350-cam.z) * 0.08;
var new_zoom = 3 - stage.mouseY * 0.002;
cam.zoom += ( new_zoom - cam.zoom ) * 0.06;
for( var i:uint = 0; i < total; i++ ){
   container.getChildByName("btn_sh" + i).y += (0-container.getChildByName("btn_sh" + i).y)*0.1;
      container.getChildByName("btn_sh" + j).alpha = 0.1;
  }
}else{
  for( var j:uint = 0; j < total; j++ ){
   container.getChildByName("btn_sh" + j).y += (-120-container.getChildByName("btn_sh" + j).y)*0.1;
  container.getChildByName("btn_sh" + j).alpha = 0.05;
  }
cam.y += ( 0 - cam.y ) * 0.2;
cam.zoom += ( 9 - cam.zoom ) * 0.06;
}
scene.renderCamera(cam);

 

}


/////////////////////////////////////////////////////// cacheImages /////////////////////////////////////////////////////////////////
var totalImages:Number;
var indexIm:Number;
var _loaderCacheImages:ImageLoader;
var _arrCacheImages:Array;
var _currContentCache:MovieClip;


function cacheImages(_arr:Array){
_txtLoadInfo.visible = true;
addChildAt(_txtLoadInfo,(getChildIndex(container)+1));
totalImages = _arr.length;
indexIm = 0;
_arrCacheImages = [];
_arrCacheImages = _arr;
var targetIm:String = _arrCacheImages[indexIm];
_loaderCacheImages = new ImageLoader(targetIm);
_loaderCacheImages.addEventListener(ProgressEvent.PROGRESS, progressCacheImages);
_loaderCacheImages.addEventListener(Event.INIT, initLoadCache);
};
function initLoadCache(evt:Event):void {
var _bitmapThumb:Bitmap = evt.target.urlImgData;
_bitmapThumb.smoothing = true;
  var bfm:BitmapMaterial = new BitmapMaterial(_bitmapThumb.bitmapData);
  bfm.oneSide = false;
  bfm.smooth = true;
  var p:Plane = new Plane(bfm, 180, 110, 2, 2);
  scene.addChild(p);
  var p_container:Sprite = p.container;
  p_container.name = "btn" + indexIm;
  p_dict[p_container] = p;
  p_container.buttonMode = true;
  p_container.addEventListener( MouseEvent.ROLL_OVER, p_rollover );
  p_container.addEventListener( MouseEvent.ROLL_OUT, p_rollout );
  p_container.addEventListener( MouseEvent.CLICK, p_click );

  var p1:Plane = new Plane(bfm, 180, 110, 2, 2);
  scene.addChild(p1);
  var p_container1:Sprite = p1.container;
  p_container1.name = "btn_sh" + indexIm;
  p_container1.alpha = 0.1;
  p_dict[p_container1] = p1;
  p1.rotationY = (-indexIm*anglePer) * (180/Math.PI) + 90;
  p1.rotationX = 180;
  if(total >=10) {
  p1.x = Math.cos(indexIm * anglePer) * 29*total;
  p1.z = Math.sin(indexIm * anglePer) * 29*total;
  }else{
  p1.x = Math.cos(indexIm * anglePer) * 40*total;
  p1.z = Math.sin(indexIm * anglePer) * 40*total;
  }
  p1.y = -110;
  p.rotationY = 90;
 
  if(total >=10) {
  p.x = Math.cos(indexIm * anglePer) * 29*total;
  p.z = Math.sin(indexIm * anglePer) * 29*total;
  }else{
  p.x = Math.cos(indexIm * anglePer) * 40*total;
  p.z = Math.sin(indexIm * anglePer) * 40*total;
  }

 

indexIm ++;
if (indexIm < totalImages){
  var targetIm:String = _arrCacheImages[indexIm];
  _loaderCacheImages = new ImageLoader(targetIm);
  _loaderCacheImages.addEventListener(ProgressEvent.PROGRESS, progressCacheImages);
  _loaderCacheImages.addEventListener(Event.INIT, initLoadCache);
}else{
indexIm = 0;
_txtLoadInfo.text = "";
_txtLoadInfo.visible = false;
_loaderCacheImages.removeEventListener(ProgressEvent.PROGRESS, progressCacheImages);
_loaderCacheImages.removeEventListener(Event.INIT, initLoadCache);
_loaderCacheImages = null;
container.alpha = 0;
onResizeStageApp();
Tweener.addTween(container, {alpha:1, time:2});
addEventListener(Event.ENTER_FRAME, render);
if(!loadSite) gotoAndStop(6);
}
};

function progressCacheImages(evt:ProgressEvent):void{
var _progressDataArr:Array = evt.target.progressImgArr;
var _bLoaded:Number = Number(_progressDataArr[0]);
var _bTotal:Number = Number(_progressDataArr[1]);
var loadPercent:int = Math.round(_bLoaded / _bTotal * 100);
_txtLoadInfo.text = "Loading thumb ... " + indexIm + "  " + loadPercent + "%";
_txtLoadInfo.x = Math.round((stage.stageWidth - _txtLoadInfo.width)/2);
_txtLoadInfo.y = Math.round((stage.stageHeight - _txtLoadInfo.height)/2);
}

 

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points