[SOLVED - Solution inside] Loading Away3D 4 .swf into an Air 3.4 application

Software: Away3D 4.x

LeoBergmann, Newbie
Posted: 01 July 2013 08:19 AM   Total Posts: 6

Hello everyone,

I’ve posted under a quite similar thread last week, where the problem was caused by a compiler setting in my Flashbuilder. Since that now works I’ve got new problems and and lot of fiddling around and using google didn’t help, so maybe some of you guys have a clever idea what to do.

I got a host application which is written in Flash Professional CS6 as an Air 3.4 Desktop Application. This host application can load previously generated locally stored .swf files with content (via a Loader and add’s them to the display list), based on a code that is entered (a little bit like a webbrowser).
Now I need to have some of these .swf files to display some 3D models via Away3D 4.1

The Away 3D swf is written in FlashBuilder and works perfectly on it’s own, but when I try to load the file in my host application I get Security Sanbox errors like this one:

SecurityErrorError #2070: Security sandbox violation: caller file:///C:/Users/Leo/Documents/DLB/content/DLB_Test/swf/DLB_Test_006.swf cannot access Stage owned by app:/DLB_Host.swf.
 
at flash.display::Stage/get stage3Ds()
 
at away3d.core.managers::Stage3DManager()[/Users/robbateman/Documents/Adobe Flash Builder 4.7/away3d-core-fp11/src/away3d/core/managers/Stage3DManager.as:35]
 at away3d
.core.managers::Stage3DManager$/getInstance()[/Users/robbateman/Documents/Adobe Flash Builder 4.7/away3d-core-fp11/src/away3d/core/managers/Stage3DManager.as:45]
 at away3d
.containers::View3D/onAddedToStage()[/Users/robbateman/Documents/Adobe Flash Builder 4.7/away3d-core-fp11/src/away3d/containers/View3D.as:895]
 at flash
.display::DisplayObjectContainer/addChild()
 
at Basic_SkyBox/fnc_setupView()[C:\Users\Leo\Adobe Flash Builder 4.6\Basic_SkyBox\src\Basic_SkyBox.as:235]
 at Basic_SkyBox
/fnc_setupPage()[C:\Users\Leo\Adobe Flash Builder 4.6\Basic_SkyBox\src\Basic_SkyBox.as:192]
 at classes
.uiElements::ContentHolder/fnc_pageLoaded()[C:\Users\Leo\Desktop\Projekte\Liquid\Liquid\DLB_Entwicklung\DLB_Host\classes\uiElements\ContentHolder.as:452] 

I understand, that the stage3D lies under the normal 2D display layer and can only be accessed through the stage. Is there a known possibility to access the stage from inside the loaded swf content, that bypasses the security sandbox?

Another thing I tried is to generate the stage 3D in the host application itself and to pass the view3D or the models from the loaded .swf file with getter/setter methods to the host application, but when I do this, I get such errors:

TypeErrorError #1034: Type Coercion failed: cannot convert away3d.containers::View3D@5cb8ed9 to away3d.containers.View3D.
 
at classes.uiElements::ContentHolder/fnc_view3Dready()[C:\Users\Leo\Desktop\Projekte\Liquid\Liquid\DLB_Entwicklung\DLB_Host\classes\uiElements\ContentHolder.as:876]
 at flash
.events::EventDispatcher/dispatchEventFunction()
 
at flash.events::EventDispatcher/dispatchEvent()
 
at TestClientMain/fnc_setupPage()[C:\Users\Leo\Desktop\Projekte\Liquid\Liquid\DLB_Entwicklung\DLB_Clients\Realtime3DClient\TestClient\TestClientMain.as:93]
 at classes
.uiElements::ContentHolder/fnc_pageLoaded()[C:\Users\Leo\Desktop\Projekte\Liquid\Liquid\DLB_Entwicklung\DLB_Host\classes\uiElements\ContentHolder.as:451] 

or:

TypeErrorError #1034: Type Coercion failed: cannot convert away3d.entities::Mesh@eea9239 to away3d.entities.Mesh.
 
at classes.uiElements::ContentHolder/fnc_view3Dready()[C:\Users\Leo\Desktop\Projekte\Liquid\Liquid\DLB_Entwicklung\DLB_Host\classes\uiElements\ContentHolder.as:877]
 at flash
.events::EventDispatcher/dispatchEventFunction()
 
at flash.events::EventDispatcher/dispatchEvent()
 
at TestClientMain/fnc_setupPage()[C:\Users\Leo\Desktop\Projekte\Liquid\Liquid\DLB_Entwicklung\DLB_Clients\Realtime3DClient\TestClient\TestClientMain.as:93]
 at classes
.uiElements::ContentHolder/fnc_pageLoaded()[C:\Users\Leo\Desktop\Projekte\Liquid\Liquid\DLB_Entwicklung\DLB_Host\classes\uiElements\ContentHolder.as:451] 


The code for the away3D swf testclient is as follows:

private var _view:View3D;
private var 
_torus:Mesh;

public function 
get view():View3D
{
 
return _view;
}

public function set view(inViewView3D):void
{
 _view 
inView;
}

public function get torus():Mesh
{
 
return _torus;
}

public function set torus(inTorusMesh):void
{
 _torus 
inTorus;
}

public function TestClientMain(){
}

public function fnc_setupPage():void {
 _view 
= new View3D();
 
// commented out to prevent security sandbox errors
 //addChild(_view);

 
_view.camera.= -600;
 
_view.camera.0;
 
_view.camera.lookAt(new Vector3D());

 var 
material:ColorMaterial = new ColorMaterial(0xFF00FF);
 
_torus = new Mesh(new TorusGeometry(150,60,40,20),material);
 
_view.scene.addChild(_torus);

 
addEventListener(Event.ENTER_FRAMEfnc_onEnterFrame);
 
dispatchEvent(new Event("viewReady"));
}

private function fnc_onEnterFrame(e:Event):void {
 _torus
.rotationX +=  2;
 
//_view.render();
 
dispatchEvent(new Event("renderView"));

The code in the host application looks for testing like this:

private function fnc_view3Dready(evtEvent): void{
   
var testViewView3D = new View3D();
   
   
testView pageContainer.view;
   var 
testTorusMesh pageContainer.torus;
  

I hope anybody got a clever idea how to “fix” this. I need to get this working somehow without writing all 3D Code in host application context.

Thank you very much for your time!

Greetings, Leo

   

LeoBergmann, Newbie
Posted: 07 August 2013 01:36 PM   Total Posts: 6   [ # 1 ]

Hello everyone,

Some time has passed and unfortunately nobody seemed to have a solution for my problem.

After some weeks of trying almost everything, I came to a solution for MY! problem, hence this solution should only be applied in a totally controlled environment like in my case (It’s like a closed kiosk application with no new data from untrusted sources).

So for the solution to load external swf files with Stage3D/Away3D content into an AIR application I modified my loading process from the normal Loader component to URLLoader component to load the swf into a byteArray like this:

var binaryLoaderURLLoader = new URLLoader();
binaryLoader.dataFormat URLLoaderDataFormat.BINARY;
binaryLoader.addEventListener(Event.COMPLETEfnc_binaryLoaded);
binaryLoader.load(urlToSWF);

// function after the swf has been loaded to a byteArray
private function fnc_binaryLoaded(evtEvent): void{
 
// remove the eventListener from the loader component
 
evt.target.removeEventListener(Event.COMPLETEfnc_binaryLoaded);
 
// create ne byteArray to hold the binary swf data
 
var swfByteArray = new ByteArray();
 
// read the byteArray data from URLLoader component
 
swfByteArray evt.target.data;
 
// create a loader context for the loader to allow codeImport for the binary swf file
 
var loaderContextLoaderContext = new LoaderContext();
 
loaderContext.allowCodeImport true;
 
// load the bytes from the byteArray
 
var SWFLoaderLoader = new Loader();
 
SWFLoader.contentLoaderInfo.addEventListener(Event.COMPLETEfnc_pageLoaded);
 
SWFLoader.loadBytes(swfByteArrayloaderContext);
   
fnc_dispatchErrorMessage(this.name ": Got swf client loaded into the binary array");
}

// function to add the loaded swf data as movieClip
private function fnc_pageLoaded(evtEvent): void{
 
// clean up the eventListener
       
SWFLoader.contentLoaderInfo.removeEventListener(Event.COMPLETEfnc_pageLoaded);
 
// casting it into the container movieClip, so that it's functions can be accessed
 
var pageContainerMovieClip MovieClip(SWFLoader.contentLoaderInfo.content);
        
addChild(pageContainer);

Hope I could help someone who has the same problem.

Cheers, Leo

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X