Flex 4.6 + Alternativa3D 8 spark problem

// July 25th, 2012 // Software

Recently I’ve been playing around with alternativa3D and I could not figure out why when I set up flex nativeproject using SDK 4.6 and Alternativaplatform 8 – notthing is displayed on the stage..

After A while I figured out what is going on. It turned out that the flex background is drew above the 3D stages. My fix is simple – just setting backgroundAlpha style to be 0 and the 3D appears.

Here you can see my test code:

<?xml version=”1.0″ encoding=”utf-8″?>
<s:Application xmlns:fx=”http://ns.adobe.com/mxml/2009″
xmlns:s=”library://ns.adobe.com/flex/spark” backgroundAlpha=”0″
xmlns:mx=”library://ns.adobe.com/flex/mx” xmlns:alternativaplatform=”http://alternativaplatform.com”
applicationComplete=”initApplication(event)” backgroundColor=”black”
minWidth=”950″ minHeight=”550″ xmlns:controller=”bg.lan.chess.controller.*” xmlns:local=”*”>

<controller:Controller id=”control” />

<fx:Style source=”css/styles.css” />

import alternativa.engine3d.controllers.SimpleObjectController;
import alternativa.engine3d.core.Camera3D;
import alternativa.engine3d.core.Object3D;
import alternativa.engine3d.core.Resource;
import alternativa.engine3d.core.View;
import alternativa.engine3d.materials.FillMaterial;
import alternativa.engine3d.primitives.Box;

import bg.lan.chess.events.InitApplicationEvent;
import bg.lan.chess.init.ResourceLoader;
import bg.lan.chess.view.MainView;

import flash.display3D.Context3D;
import flash.display3D.Context3DRenderMode;

import mx.events.FlexEvent;

public var mainView:MainView;
protected var rootContainer:Object3D = new Object3D();
protected var camera:Camera3D;
protected var box:Box;
private var stage3D:Stage3D;

private function initApplication(e:Event):void {


protected function initEngine():void
camera = new Camera3D(0.1, 50000);
camera.view = new View(800, 500);

camera.z = -1000;


alternativa3DSprite.addEventListener(Event.ENTER_FRAME, onEnterFrame);

protected function initScene():void
stage3D = alternativa3DSprite.stage.stage3Ds[0];
stage3D.addEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
box = new Box(500, 500, 500, 5, 5, 5);
var material:FillMaterial = new FillMaterial(0xFF7700, 1);


private function onContextCreate(e:Event):void {
stage3D.removeEventListener(Event.CONTEXT3D_CREATE, onContextCreate);
for each (var resource:Resource in rootContainer.getResources(true)){ // all resources are loaded in context3D

protected function onEnterFrame(e:Event):void
camera.view.width = stage.stageWidth;
camera.view.height = stage.stageHeight;


<s:SpriteVisualElement id=”alternativa3DSprite” width=”100%” height=”100%” />
<s:Label text=”Test Label above the 3D. Note that the box is visible. It is because of the backgroundAlpha=’0′ style” color=”white” horizontalCenter=”0″ verticalCenter=”0″ />

3 Responses to “Flex 4.6 + Alternativa3D 8 spark problem”

  1. Alejandro says:

    You save my life dude! God bless you!

Leave a Reply