0

Im trying to load an swf into a 3D Objectcontainer.Im using Away3D (gold)

Basically i have loaded an object into a 3d Container, now i would like to load an swf inside that same container. I would now have my object and a SWF inside the same container so if i rotate the container so will my SWF.My swf only consist of text for now its just a test...

The loading method im using is an array... Any ideas?

my error:

    TypeError: Error #1034: Type Coercion failed: cannot convert 
  flash.display::MovieClip@30ee0e41 to away3d.containers.ObjectContainer3D.
joshua
  • 676
  • 1
  • 5
  • 19
  • Can you post the code you're using to do this ? – Tim Baas Aug 20 '12 at 08:54
  • the code doesnt matter, but further more im trying to just load an empty mc and still getting error:var mc:MovieClip = new MovieClip(); mc.graphics.beginFill(0xFF0000); mc.graphics.drawRect(0, 0, 200, 200); mc.graphics.endFill(); mc.x = 80; mc.y = 60; than _3dcontainer.addchild(mc); – joshua Aug 20 '12 at 09:06
  • The `addChild` method of the `ObjectContainer3D` instance expects you to give an instance of a `Object3D`, `MovieClip` is not an `Object3D`, so it tries to convert it, but can't. So what you need to know is how to add a 2D object into your 3D environment. If I remember correctly you need to create a material with your MovieClip as the texture and add that to a Plane primitive with the same width and height as the SWF. – Tim Baas Aug 20 '12 at 09:33
  • your on the money just found that out too "http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=4&subindex=4&aid=121" looking over threads... Add your answer, i will vote it...it helps just a case some one else gets stuck...thank you – joshua Aug 20 '12 at 09:38
  • I did and added the code that will get you in the right direction, it will work if you have your camera's set up correctly, I guess. Good luck! – Tim Baas Aug 20 '12 at 09:42
  • code doesnt work , but the concept is correct i will update it when iv succceded so far so good – joshua Aug 20 '12 at 09:59

1 Answers1

1

Away3D 4, is a bit more difficult. But I'll try to point you in the right direction.

You need to create a Mesh out of Geometry and Material.

The Material has a texture with your MovieClip. The Geometry is a PlaneGeometry

The Mesh is the Object3D instance you need to add to your ObjectContainer3D.

You're code would look something like this:

var bitmapData:BitmapData = new BitmapData( mc.width, mc.height, false, 0x000000 );
var texture:BitmapTexture = new BitmapTexture( bitmapData );
var material:TextureMaterial = new TextureMaterial( texture, true );

var geometry:PlaneGeometry = new PlaneGeometry( mc.width, mc.height );

var planeMesh:Mesh = new Mesh( geometry, material );

_3dcontainer.addChild( planeMesh );

Now for the MovieClip to animate, you need to update the bitmap of your texture:

mc.addEventListener( Event.ENTER_FRAME, updateTexture );

private function updateTexture( e:Event ):void {
    texture.bitmapData = new BitmapData( mc.width, mc.height, false, 0x000000 );
}

Again, I did not test this, and it's long ago since I used Away3D 4. Just don't forget to import the used classes.

Just have a good look in the docs: http://away3d.com/livedocs/away3d/4.0/

Tim Baas
  • 6,035
  • 5
  • 45
  • 72
  • MovieMaterial( mc ) this would be correct on away3d 3.6, but the away3d 4.!! versions don"t seem to have this class – joshua Aug 20 '12 at 14:09
  • Away3D 4 is a bit more difficult, but it's still possible, check my answer for the 'concept' in Away3D 4. – Tim Baas Aug 20 '12 at 16:17
  • this would be the work around iv read up on, apparently its hectic on the CPU, i will test this tomorrow but at the moment i came up with a dumb alternative – joshua Aug 20 '12 at 17:31