Hello,
I have a problem with a project I’m building. The working swf is at
http://illusionary-amalgam.com/work_related/file01.swf
It currently has the following listeners active. When you click a blurb, you will zoom into it. When you click it again (or anywhere on the flash object) it will zoom back out. If you let it idle it will zoom in and out at roughly 10second intervals.
There are also keyboard functions that when you click on the arrow keys it will move the camera in various ways. The keys only work in the zoomed out state and are disabled on zoom in.
The problem that I’m having is with these. On startup, the keys work fine. If you let it idle and have it automatically zoom in then out, the keys will work fine. However, if you manually click out of a blurb, the keyboard event listeners stop working. I’m not sure why this happens since both the auto-zoom and the manual zoom both call the same function to zoom out.
At first it seems to be that the window is losing focus, since if I click on white space I can use the keyboard again. The problem though, is that when I use an DEACTIVATE event listener to test it, it doesn’t show the flash object losing focus. Because of that, I’m not really sure how I would go about fixing this problem.
package com.jonchau.twitter {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.KeyboardEvent;
import flash.utils.Timer;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.events.InteractiveScene3DEvent;
import com.greensock.*;
public class Pane extends MovieClip {
private var viewport: Viewport3D;
private var scene: Scene3D;
private var camera: Camera3D;
private var material: MovieMaterial;
private var primitive: Plane;
private var renderer: BasicRenderEngine;
private var up:Boolean = false;
private var down:Boolean = false;
private var left:Boolean = false;
private var right:Boolean = false;
private var shift:Boolean = false;
private var tweetArray:Array = new Array();
private var tweetCount:int = 0;
private var timer:Timer;
private var timerDelay:Number = 10;
private var resetDelay:Number = 7;
private var resetTimer:Timer;
private var fontType:String = "Frutiger LT Std 87 ExtraBlk Cn";
private var fontSize:int = 18;
private var fontColor:uint = 0x00000;
private var fontAlias:String = AntiAliasType.ADVANCED;
private var numTweets:int = 60;
private var screenBtn:MovieClip;
public function Pane():void {
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
//viewport = new Viewport3D(w, h, scaleToStage, interactive);
viewport = new Viewport3D(0, 0, true, true);
addChild(viewport);
viewport.buttonMode = true;
//instantiates a Scene3D instance
scene = new Scene3D();
//instantiates a Camera3D instance
camera = new Camera3D();
//renderer draws the scene to the stage
renderer = new BasicRenderEngine();
for (var i:int = 0; i < numTweets; i++) {
createPlane();
}
initTimer();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHit);
stage.addEventListener(KeyboardEvent.KEY_UP, keyOff);
}
private function initTimer():void {
timer = new Timer(timerDelay * 1000, 1);
timer.addEventListener("timer", chooseTweet);
timer.start();
resetTimer = new Timer(resetDelay*1000, 1);
resetTimer.addEventListener("timer", hideTweet);
}
private function chooseTweet(e:TimerEvent):void {
var tweetToChoose:int = Math.floor(Math.random() * (tweetCount));
showTweet(tweetToChoose);
}
private function showTweet(num:int):void {
TweenLite.to(camera, 1, {x: tweetArray[num].x-(tweetArray[num].rotationY*2.5), y: tweetArray[num].y, z: tweetArray[num].z-180, rotationY: tweetArray[num].rotationY, onComplete: addReturnBtn});
for (var i:int = 0; i< tweetCount; i++) {
if (i != num)
TweenLite.to(tweetArray*, .5, {alpha: .25});
}
resetTimer.start();
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyHit);
stage.removeEventListener(KeyboardEvent.KEY_UP, keyOff);
}
private function resetCam( e:MouseEvent ):void {
resetTweets();
}
private function hideTweet(e:TimerEvent):void {
resetTweets();
}
private function resetTweets():void {
for (var i:int = 0; i< tweetCount; i++) {
TweenLite.to(tweetArray*, 0.5, {alpha: 1});
}
TweenLite.to(camera, 1, {x: 0, y: 0, z: -1000, rotationY: 0});
if (screenBtn != null) {
screenBtn.removeEventListener(MouseEvent.CLICK, resetCam);
removeChild(screenBtn);
}
resetTimer.reset();
timer.start();
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyHit);
stage.addEventListener(KeyboardEvent.KEY_UP, keyOff);
}
private function pressEv( e:InteractiveScene3DEvent ):void {
showTweet(int(e.target.name));
timer.reset();
}
private function addReturnBtn():void {
screenBtn = new MovieClip();
addChild(screenBtn);
screenBtn.graphics.beginFill(0x0000FF, 0);
screenBtn.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
screenBtn.graphics.endFill();
screenBtn.buttonMode = true;
screenBtn.addEventListener(MouseEvent.CLICK, resetCam);
}
private function onEnterFrame(e:Event):void {
if (!shift) {
if (up)
camera.y += 30;
if (down)
camera.y -= 30;
if (left)
camera.x -= 30;
if (right)
camera.x += 30;
renderer.renderScene(scene, camera, viewport);
}
else {
if (up)
camera.z += 30;
if (down)
camera.z -= 30;
renderer.renderScene(scene, camera, viewport);
}
}
private function keyHit(e:KeyboardEvent):void {
switch(e.keyCode) {
case 16:
shift = true;
break;
case 37:
left = true;
break;
case 38:
up = true;
break;
case 39:
right = true;
break;
case 40:
down = true;
break;
}
timer.reset();
}
private function keyOff(e:KeyboardEvent):void {
switch(e.keyCode) {
case 16:
shift = false;
break;
case 37:
left = false;
break;
case 38:
up = false;
break;
case 39:
right = false;
break;
case 40:
down = false;
break;
}
timer.start();
}
private function createPlane():void {
var txt:TextField = new TextField();
txt.wordWrap = true;
txt.width = 600;
txt.height = 70;
txt.multiline = true;
txt.htmlText= "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nullam. Lorem ipsum dolor amet, consectetur adipiscing elit. Proin nullam.";
txt.autoSize = TextFieldAutoSize.CENTER;
txt.setTextFormat(new TextFormat(fontType, fontSize, fontColor));
txt.antiAliasType = fontAlias;
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0xFFFFFF);
mc.graphics.drawRect(0,0,600,70);
mc.graphics.endFill();
mc.addChild(txt);
var mat:MovieMaterial = new MovieMaterial(mc, true, true);
mat.interactive = true;
mat.smooth = true;
mat.tiled = true;
var p:Plane = new Plane(mat, 600, 70, 1, 1);
p.x = (Math.random()* stage.stageWidth - ((stage.stageWidth/2) -40))+20;
p.y = Math.random()* (stage.stageHeight*2) - stage.stageHeight;
p.z = Math.random()*(-500);
p.rotationY = (Math.random()*70) - (Math.random()*70);
p.useOwnContainer = true;
scene.addChild(p);
p.name = String(tweetCount);
tweetCount++;
p.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, pressEv);
tweetArray.push(p);
}
}
}
If anyone could help my shed some light on this issue it would be much appreciated.
Thanks in advance.