Hi, folks.
I’m trying to make a cube have a fadeIn and fadeOut. The alpha property doesn’t work. So I try to take each face’s material. But it doesn’t have a alpha property too.
So my newbie question is: how can I set an alpha/transparency of a primitive? In its materials? In alpha property of the primitive? Nothing is working on this matter.
The most funny part: in “Cookbook” AND ‘3D in Flash” books I didnt find one, neighter a unique simple line of “alpha” or “fadeIn” “fadeOut” example. It is drive me crazy hahahah.
Thanks for all your help.
—Editing:
Well… this is what I did to “work around” this alpha problem. I dont know if this is the best (or correct) way to achieve this, but It is working:
package {
import away3d.materials.ColorMaterial;
import away3d.materials.Material;
import away3d.materials.MovieMaterial;
import away3d.primitives.Cube;
import away3d.primitives.data.CubeMaterialsData;
import com.greensock.TweenLite;
/**
* ...
* @author Pedro Paulo Almeida
*/
public class FaceNumber extends Cube {
private var _materials:Array;
override public function set alpha(value:Number):void {
super.alpha = value;
}
public function FaceNumber(init:Object = null) {
super(init);
this._materials = new Array();
}
public function init(front:MovieMaterial, back:MovieMaterial):void {
var cubeData:CubeMaterialsData = new CubeMaterialsData();
cubeData.front = front;
cubeData.left = new ColorMaterial(0xffffff);
cubeData.right = new ColorMaterial(0xffffff);
cubeData.top = new ColorMaterial(0xffffff);
cubeData.bottom = new ColorMaterial(0xffffff);
cubeData.back = back;
this._materials.push(front, back, cubeData.left, cubeData.right, cubeData.top, cubeData.bottom);
this.cubeMaterials = cubeData;
}
public function setAlpha(value:Number, speed:Number):void {
// If the value is zero, min value is 0.01 to avoid bitmap null bug
if (value <= 0) value = 0.01;
// if the desired value is upper than 0.01 turn it visible:
if (value > 0.01) this.visible = true;
// just matain "alpha" value updated in Cube, just in case....
this.alpha = value;
// Update materials alpha:
for (var i:int = 0; i < this._materials.length; i++) {
(i == 0) ? TweenLite.to(this._materials[i], speed, { alpha:value, onComplete:invisible } ) : TweenLite.to(this._materials[i], speed, {alpha:value});
}
}
// After the tween get finished, turn it visible= false, to improve performance (right?)
private function invisible():void {
this.visible = false;
}
}
}
Well, if someone here with a lof of experience has a better/different way or even a comment/suggestion I would love to hear.
Thank you all.
Pedro Paulo Almeida