Copy link to clipboard
Copied
hey there 🙂
i got a small problem with actionscript. i want to let my chess board fade from low transparency to 100% transparency and i need to do this in action script...i've already tried several ways via greensock etc. can anyone help me? thank you
here's my code:
import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([TintPlugin]);
var Schachbrett:Array = new Array();
for(var i:int = 0; i < 4; i++)
{
Schachbrett.push(new Array(1,0,1,0,1,0,1,0));
Schachbrett.push(new Array(0,1,0,1,0,1,0,1));
}
var unitSize:int = 60;
function baueSchachbrett():void
{
for(var i:int = 0; i < Schachbrett.length; i++)
{
for(var j:int = 0; j < Schachbrett.length; j++)
{
var tile:Sprite = new Sprite();
var tileColor:int = Schachbrett
tile.graphics.beginFill(tileColor);
tile.graphics.drawRect(0, 0, unitSize, unitSize);
tile.graphics.endFill();
tile.name = ("tile__" + i + "_" + j + "_sp");
tile.addEventListener(MouseEvent.CLICK, klick);
tile.x = j * unitSize;
tile.y = i * unitSize;
addChild(tile);
}
}
}
...
import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([TintPlugin]);
var schachbrett:Sprite=new Sprite();
addChild(schachbrett);
schachbrett.alpha=0;
var Schachbrett:Array = new Array();
for(var i:int = 0; i < 4; i++)
{
Schachbrett.push(new Array(1,0,1,0,1,0,1,0));
Schachbrett.push(new Array(0,1,0,1,0,1,0,1));
}
var unitSize:int = 60;
function baueSchachbrett():void
{
for(var i:int = 0; i < Schachbrett.length; i++)
{
for(var j:int = 0; j < Schachbrett.length; j++)
Copy link to clipboard
Copied
if your board's reference is board, use:
var speed:Number=1;
board.alpha=.1;
TweenLite.to(board,speed,{alpha:1});
Copy link to clipboard
Copied
I don't see any tweening code here.
Also it would generally be better if all your individual tiles for each square were added to a parent sprite (or what have you) so then you could just fade up that one thing.
Currently your are just doing:
addChild(tile)
something like
schachbrett.addChild(tile)
would probably be a better strategy. Then you could just tween in the parent clip.
Copy link to clipboard
Copied
thanks for your quick replay
regrettably actionscript is completely new for me...can you tell me what exactely i have to change in my code? where do i have to put schachbrett.addChild(tile)?
the tweening code should look like this i think:
new TweenLite(???, 3, {tint:0xff0000});
so what do i have to put in for the three "?"?
thanks again ![]()
Copy link to clipboard
Copied
Exactly. What will you put for the ????
Just like in real life all the little tile squares on a chessboard belong to the chessboard and if you throw it across the room they all go. If they were all individuals it would be much more difficult to throw them all across the room 1 by 1.
So first create your chessboard.
var schachbrett:Sprite=new Sprite();
addChild(schachbrett)
Then make all your tiles with the loop and code you have except instead of
addChild(tile)
you would use
schachbrett.addChild(tile)
And then you would use the Tween syntax given by kglad above, that is assuming you wanted to do an alpha fade.
var speed:Number=1;
schachbrett.alpha=.1;
TweenLite.to(schachbrett,speed,{alpha:1});
Copy link to clipboard
Copied
import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([TintPlugin]);
var schachbrett:Sprite=new Sprite();
addChild(schachbrett);
schachbrett.alpha=0;
var Schachbrett:Array = new Array();
for(var i:int = 0; i < 4; i++)
{
Schachbrett.push(new Array(1,0,1,0,1,0,1,0));
Schachbrett.push(new Array(0,1,0,1,0,1,0,1));
}
var unitSize:int = 60;
function baueSchachbrett():void
{
for(var i:int = 0; i < Schachbrett.length; i++)
{
for(var j:int = 0; j < Schachbrett.length; j++)
{
var tile:Sprite = new Sprite();
var tileColor:int = Schachbrett
* 0xffffff; tile.graphics.beginFill(tileColor);
tile.graphics.drawRect(0, 0, unitSize, unitSize);
tile.graphics.endFill();
tile.name = ("tile__" + i + "_" + j + "_sp");
tile.addEventListener(MouseEvent.CLICK, klick);
tile.x = j * unitSize;
tile.y = i * unitSize;
schachbrett.addChild(tile);
}
}
TweenLite.to(schachbrett,1,{alpha:1});
}
Copy link to clipboard
Copied
many many thanks
you are the best ones!
worked fine... 🙂
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more