Niek0101
%Europe/Berlin %819 %2009, 20:39
Ik ben bezig met mijn eerste site in as3. Nu kom ik een paar problemen tegen met het linken naar de timeline. Ik wou het gewoon via frame label in the timeline doen maar dit werkt niet het zelfde als in AS2. Dus mijn vraag is hoe moet ik dit doen en waar moet ik deze code zetten?
Ik heb nu in de actie layer van mijn button staan (heb verschillende effecte op deze button:
//Import TweenMax
import gs.*;
//This array will contain all the rectangles
var rectangles:Array = new Array();
//Loop through the items in this movie clip
for (var i:uint = 0; i < this.numChildren; i++) {
//Get an object
var object:* = this.getChildAt(i);
//Check to see if the object is a MenuRectangle
if (object is MenuRectangle) {
//Save the rectangle's coordinates (we need these later on)
object.origX = object.x;
object.origY = object.y;
//Add the rectangle to the rectangles array
rectangles.push(object);
}
}
//Add mouse listeners for the mouse area
mouseArea.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
mouseArea.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
mouseArea.addEventListener(MouseEvent.CLICK, itemClicked);
//This function is called when the cursor is over the mouse area
function mouseOverHandler(e:Event):void {
//Loop through the rectangle array
for (var i:uint = 0; i < rectangles.length; i++) {
//Assign the rectangle to a local variable
var rectangle:MenuRectangle = rectangles[i] as MenuRectangle;
//Calculate random target coordinates for the rectangle
var randomX:Number = rectangle.x + 10 * Math.cos(Math.random() * Math.PI * 2);
var randomY:Number = rectangle.y + 10 * Math.sin(Math.random() * Math.PI * 2);
//Animate the rectangle to the random coordinates
TweenMax.to(rectangle, 0.4, {x: randomX, y: randomY, alpha: 0.6, tint: Math.random() * 0xffffff});
}
//Add an ENTER_FRAME listener for the shake effect
addEventListener(Event.ENTER_FRAME, shake);
}
//This function is called when the cursor moves out of the mouse area
function mouseOutHandler(e:Event):void {
//Loop through the rectangle array
for (var i:uint = 0; i < rectangles.length; i++) {
//Assign the rectangle to a local variable
var rectangle:MenuRectangle = rectangles[i] as MenuRectangle;
//Tween the rectangle to the original position
TweenMax.to(rectangle, 0.4, {x: rectangle.origX, y: rectangle.origY, rotation: 0, alpha: 0.47, tint: 0xD1B015});
}
//Remove the ENTER_FRAME listener (we don't want to shake the rectangle anymore)
removeEventListener(Event.ENTER_FRAME, shake);
}
//This function is called when the mouse area is clicked
function itemClicked(e:Event):void {
}
function shake(e:Event):void {
//Loop through the rectangles array
for (var i:uint = 0; i < rectangles.length; i++) {
//Assign the rectangle to a local variable
var rectangle:MenuRectangle = rectangles[i] as MenuRectangle;
//Rotate the rectangle a random amount (from -4 to 4)
rectangle.rotation += Math.random() * 8 - 4;
//Assign a new random position (from -4 to 4)
rectangle.x+=Math.random()*8-4;
rectangle.y+=Math.random()*8-4;
}
}
Zet je code in [as] tags.
Kan iemand mij helpen?
Zou erg dankbaar zijn:d
Ik heb nu in de actie layer van mijn button staan (heb verschillende effecte op deze button:
//Import TweenMax
import gs.*;
//This array will contain all the rectangles
var rectangles:Array = new Array();
//Loop through the items in this movie clip
for (var i:uint = 0; i < this.numChildren; i++) {
//Get an object
var object:* = this.getChildAt(i);
//Check to see if the object is a MenuRectangle
if (object is MenuRectangle) {
//Save the rectangle's coordinates (we need these later on)
object.origX = object.x;
object.origY = object.y;
//Add the rectangle to the rectangles array
rectangles.push(object);
}
}
//Add mouse listeners for the mouse area
mouseArea.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
mouseArea.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
mouseArea.addEventListener(MouseEvent.CLICK, itemClicked);
//This function is called when the cursor is over the mouse area
function mouseOverHandler(e:Event):void {
//Loop through the rectangle array
for (var i:uint = 0; i < rectangles.length; i++) {
//Assign the rectangle to a local variable
var rectangle:MenuRectangle = rectangles[i] as MenuRectangle;
//Calculate random target coordinates for the rectangle
var randomX:Number = rectangle.x + 10 * Math.cos(Math.random() * Math.PI * 2);
var randomY:Number = rectangle.y + 10 * Math.sin(Math.random() * Math.PI * 2);
//Animate the rectangle to the random coordinates
TweenMax.to(rectangle, 0.4, {x: randomX, y: randomY, alpha: 0.6, tint: Math.random() * 0xffffff});
}
//Add an ENTER_FRAME listener for the shake effect
addEventListener(Event.ENTER_FRAME, shake);
}
//This function is called when the cursor moves out of the mouse area
function mouseOutHandler(e:Event):void {
//Loop through the rectangle array
for (var i:uint = 0; i < rectangles.length; i++) {
//Assign the rectangle to a local variable
var rectangle:MenuRectangle = rectangles[i] as MenuRectangle;
//Tween the rectangle to the original position
TweenMax.to(rectangle, 0.4, {x: rectangle.origX, y: rectangle.origY, rotation: 0, alpha: 0.47, tint: 0xD1B015});
}
//Remove the ENTER_FRAME listener (we don't want to shake the rectangle anymore)
removeEventListener(Event.ENTER_FRAME, shake);
}
//This function is called when the mouse area is clicked
function itemClicked(e:Event):void {
}
function shake(e:Event):void {
//Loop through the rectangles array
for (var i:uint = 0; i < rectangles.length; i++) {
//Assign the rectangle to a local variable
var rectangle:MenuRectangle = rectangles[i] as MenuRectangle;
//Rotate the rectangle a random amount (from -4 to 4)
rectangle.rotation += Math.random() * 8 - 4;
//Assign a new random position (from -4 to 4)
rectangle.x+=Math.random()*8-4;
rectangle.y+=Math.random()*8-4;
}
}
Zet je code in [as] tags.
Kan iemand mij helpen?
Zou erg dankbaar zijn:d