Hello everybody,
I have a problem with loading away3d swfs into a main swf. I don’t see the loaded swfs in the main swf, I only get a white screen.
To illustrate the problem I have made the following as3-files:
Two 3d buttons with away3d (swf_with_button_1.as and swf_with_button_2.as) and a main file (main.as).
See the code below and in the attachment.
What I would like to have is the following:
swf_with_button_1.swf and swf_with_button_2.swf are loaded into main.swf. So on your screen you see two 3d buttons.
swf_with_button_1.swf is on the left side of the screen and is small.
swf_with_button_2.swf is in the middle of the screen and is large.
When you hit the button on the left side, the two buttons (or swfs) are switching with a tween.
So swf_with_button_2.swf goes to the left side of the screen and becomes small and swf_with_button_1.swf goes to the middle of the screen and becomes large.
I have googled a lot and I have tried many things to make it work.
I hope somebody can explain me how to do something like this. Or maybe somebody can adjust the code, that would be very nice because I’m almost giving up…...
main:
package
{
import com.greensock.TweenLite;
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
public class main extends Sprite
{
private var swf1:MovieClip;
private var swf2:MovieClip;
public function main()
{
loadSwf(“swf_with_button_1.swf”, completeHandler1);
loadSwf(“swf_with_button_2.swf”, completeHandler2);
}
private function loadSwf(url:String, completehandler:Function)
{
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completehandler);
loader.load(new URLRequest(url));
}
private function completeHandler1(e:Event)
{
swf1 = MovieClip(e.currentTarget.content);
swf1.addEventListener(“switchScreens”, switchScreens);
addChild(swf1);
}
private function completeHandler2(e:Event)
{
swf2 = MovieClip(e.currentTarget.content);
swf2.addEventListener(“switchScreens”, switchScreens);
addChild(swf2);
}
private function switchScreens(e:Event)
{
var swf:MovieClip = MovieClip(e.currentTarget);
var x1:int = 0;
var x2:int = 275;
if(swf == swf2)
{
x1 = 275;
x2 = 0;
}
TweenLite.to(swf1, 1, {x:x1});
TweenLite.to(swf2, 1, {x:x2});
}
}
}
buttons: (this is only the code for button1. The code for button2 is the same only button_1 = button_2)
package {
import away3d.cameras.HoverCamera3D;
import away3d.containers.ObjectContainer3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.events.MouseEvent3D;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import com.greensock.TweenLite;
import model.button1.button1;
[SWF(width=“600”, height=“600”, frameRate=“60”, backgroundColor=”#000000”)]
public class swf_with_button_1 extends Sprite {
private var scene:Scene3D;
private var camera:HoverCamera3D;
private var view:View3D;
private var menuGroup:ObjectContainer3D;
private var doRotation:Boolean = false;
private var lastMouseX:int;
private var lastMouseY:int;
private var lastPanAngle:Number = 45;
private var lastTiltAngle:Number = -45;
private var model_button1:button1;
public function swf_with_button_1()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, onResize);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
init3D();
createScene();
this.addEventListener(Event.ENTER_FRAME, loop);
}
private function init3D():void
{
scene = new Scene3D();
camera = new HoverCamera3D({zoom:25, focus:30, distance:300});
camera.targetpanangle = camera.panangle = 20;
camera.targettiltangle = camera.tiltangle = 35;
camera.yfactor = 1;
camera.mintiltangle = -90;
camera.maxtiltangle = 90;
view = new View3D({scene:scene, camera:camera});
view.x = stage.stageWidth / 2;
view.y = stage.stageHeight / 2;
addChild(view);
}
private function createScene():void
{
model_button1 = new button1;
model_button1.x = 0;
model_button1.y = 0
model_button1.z = 0;
scene.addChild(model_button1);
model_button1.addOnMouseUp(test);
}
private function test(event:MouseEvent3D)
{
TweenLite.to(model_button1, 1, {rotationY:360, timeScale:1, scaleX:1, scaleY:1});
}
private function loop(event:Event):void
{
updateCamera();
camera.hover();
view.render();
}
private function updateCamera():void
{
if (doRotation)
{
camera.targetpanangle = 0.5 * (stage.mouseX - lastMouseX) + lastPanAngle;
camera.targettiltangle = 0.5 * (stage.mouseY - lastMouseY) + lastTiltAngle;
}
}
private function onMouseDown(event:MouseEvent):void
{
lastPanAngle = camera.targetpanangle;
lastTiltAngle = camera.targettiltangle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
doRotation = true;
stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onMouseUp(event:MouseEvent):void
{
doRotation = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onStageMouseLeave(event:Event):void
{
doRotation = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
private function onResize(event:Event):void
{
view.x = stage.stageWidth / 2;
view.y = stage.stageHeight / 2;
}
}
}