So I'm trying to create a row of ten buttons using a for loop that create a new button every time it runs, changing the x value each time. However ever each time a button is created i want it to be put into a specific array so i can refer to a specific button later on. However I'm not sure how to put objects into arrays. Is it possible to do this? This is the code I have so far:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class backgound extends MovieClip {
var btnx = 30;
var btny= 20;
var row1:Array = [];
public function backgound() {
// constructor code
var continueBtn:Button;
for(var i=0; i < 10; i++)
{
continueBtn = new Button();
continueBtn.x = btnx;
continueBtn.y = 100;
continueBtn.width = 30;
continueBtn.height = 20;
continueBtn.border = true;
continueBtn.visible = true;
continueBtn.label = "Continue";
addChild(continueBtn);
btnx += 30;
}
}
}
}
in your loop:
myArray.push(continueBtn);
or in your loop:
continueBtn =myArray[i]= new Button();
or many other ways.
now you can access your buttons:
myArray[3]// gets the 4th item in your array
I just wonder, is this ALL you want?
I H☺P E this helps !
Related
i am rebuilding a top down shooter form a .fla files with actions in it to a separate .as file
managed to fix allot of problems with is but i stumbled upon a problem with a function that drops random squares in to a particleContainer and adds them to stage to float down.
when the page is loaded is get allot of
TypeError: Error #1009: Cannot access a property or method of a null object reference. at Level/generateParticles()
i really hope someone can help me fix this! and show me where i made a mistake, i have tried allot of things already but none of them seem to work:(
package {
import playerAuto
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.utils.Timer;
import flash.text.TextField;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundMixer;
import flash.utils.*;
import flash.display.Shape;
import flash.display.DisplayObject
/**
*
*/
public class Level extends Sprite
{
//these booleans will check which keys are down
public var leftIsPressed:Boolean = false;
public var rightIsPressed:Boolean = false;
public var upIsPressed:Boolean = false;
public var downIsPressed:Boolean = false;
//how fast the character will be able to go
public var speed:Number = 5;
public var vx:Number = 0;
public var vy:Number = 0;
//how much time before allowed to shoot again
public var cTime:int = 0;
//the time it has to reach in order to be allowed to shoot (in frames)
public var cLimit:int = 12;
//whether or not the user is allowed to shoot
public var shootAllow:Boolean = true;
//how much time before another enemy is made
public var enemyTime:int = 0;
//how much time needed to make an enemy
//it should be more than the shooting rate
//or else killing all of the enemies would
//be impossible :O
public var enemyLimit:int = 16;
//the PlayerAuto's score
public var score:int = 0;
//this movieclip will hold all of the bullets
public var bulletContainer:MovieClip = new MovieClip();
//whether or not the game is over
public var gameOver:Boolean = false;
private var PlayerAuto:playerAuto = new playerAuto;
// publiek toegangkelijke verwijzing naar deze class
public static var instance:Level;
public var particleContainer:MovieClip = new MovieClip();
// constructor code
public function Level()
{
instance = this;
PlayerAuto.x = 200;
PlayerAuto.y = 100;
addChild(this.PlayerAuto);
Project.instance.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
Project.instance.stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
Project.instance.stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
Project.instance.stage.addEventListener(Event.ENTER_FRAME, generateParticles);
drieButton.addEventListener( MouseEvent.CLICK, loadScreenThree );
//checking if there already is another particlecontainer there
if(particleContainer == null)
{
//this movieclip will hold all of the particles
addChild(this.particleContainer);
}
}
function keyDownHandler(e:KeyboardEvent):void {
switch(e.keyCode) {
case Keyboard.LEFT : leftIsPressed = true; break;
case Keyboard.RIGHT : rightIsPressed = true; break;
case Keyboard.UP : upIsPressed = true; break;
case Keyboard.DOWN : downIsPressed = true; break;
}
}
function keyUpHandler(e:KeyboardEvent):void {
switch(e.keyCode) {
case Keyboard.LEFT : leftIsPressed = false; break;
case Keyboard.RIGHT : rightIsPressed = false; break;
case Keyboard.UP : upIsPressed = false; break;
case Keyboard.DOWN : downIsPressed = false; break;
}
}
function enterFrameHandler(e:Event):void {
vx = -int(leftIsPressed)*speed + int(rightIsPressed)*speed;
vy = -int(upIsPressed)*speed + int(downIsPressed)*speed;
PlayerAuto.x += vx;
PlayerAuto.y += vy;
}
function generateParticles(event:Event):void
{
//so we don't do it every frame, we'll do it randomly
if(Math.random()*10 < 2){
//creating a new shape
var mcParticle:Shape = new Shape();
//making random dimensions (only ranges from 1-5 px)
var dimensions:int = int(Math.random()*5)+1;
//add color to the shape
mcParticle.graphics.beginFill(0x999999/*The color for shape*/,1/*The alpha for the shape*/);
//turning the shape into a square
mcParticle.graphics.drawRect(dimensions,dimensions,dimensions,dimensions);
//change the coordinates of the particle
mcParticle.x = int(Math.random()*stage.stageWidth);
mcParticle.y = -10;
//adding the particle to stage
particleContainer.stage.addChild(mcParticle);
}
//making all of the particles move down stage
for(var i:int=0;i<particleContainer.numChildren;i++){
//getting a certain particle
var theParticle:DisplayObject = particleContainer.getChildAt(i);
//it'll go half the speed of the character
theParticle.y += speed*.5;
//checking if the particle is offstage
if(theParticle.y >= 400){
//remove it
particleContainer.stage.removeChild(theParticle);
}
}
}
/**
* eventhandler voor als je op de tweede knop klikt
*/
private function loadScreenThree( event:MouseEvent ):void
{
// eerst opruimen!
cleanListeners();
// dan naar ander scherm
Project.instance.switchScreen( "derde" );
}
private function cleanListeners():void
{
drieButton.removeEventListener( MouseEvent.CLICK, loadScreenThree );
stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
stage.removeEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.removeEventListener(Event.ENTER_FRAME, generateParticles);
}
}
}
I think the problem is here:
for(var i:int=0;i<particleContainer.numChildren;i++){
var theParticle:DisplayObject = particleContainer.getChildAt(i);
[...]
if (theParticle.y >= 400){
particleContainer.removeChild(theParticle);
}
}
You are removing children from the particleContainer while iterating through it. This is usually a bad idea because once you remove an item from the beginning, you are changing the index of all following items.
One solution is to loop backwards, so when you remove something the only items changed are the ones that you already checked.
for(var i:int=particleContainer.numChildren - 1; i>=0; i--){
And the rest keeps the same.
I have encountered quite a challenging one and I'd love to get some support.
Here is the scenario :
The main Game class instances the Level1 Class in charge for spawning enemies through nested For loops and push them to an array.
It then checks for collisions between the Bullet and Enemy and if it find a collision it calls a method in the Enemy class that removes removeChild and Splice itself from the array.
The thing is it works for the first few enemies, and then it will pick the wrong Enemy to destroy, and stop completely to function.
I tried using indexOf to be sure I am referring to the right object, but to no avail.
I think the Pslice and removeChild are pointing to different objects.
This mess happended when I moved the removeChild and splice from the Game Class to the Enmy class
Link to the work in progress : https://dl.dropboxusercontent.com/s/69hcmzygnkx7h1e/space_shooter.swf
I'd like some help on this one.
Thank you !!!
Main class : Game.AS
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.text.*;
import flash.geom.Point;
public class Game extends MovieClip
{
public var _instance : Game;
public var player:Player;
public static var level1:Level1;
public var bullet:Bullet;
private var bullets_arr:Array;
var fire_on : Boolean;
var fire_counter : int;
public function Game()
{
level1=new Level1(this.stage);
player = new Player ;
addChild(player);
player.y = 600;
bullets_arr = [];
addEventListener(Event.ENTER_FRAME,Main);
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpHandler);
}
function mouseDownHandler($e:MouseEvent):void
{
fire_on = true;
}
function mouseUpHandler($e:MouseEvent):void
{
fire_on = false;
fire_counter = 0;
}
function fire():void
{
bullet = new Bullet ;
addChild(bullet);
bullet.x = player.x;
bullet.y = player.y - 32;
bullets_arr.push(bullet);
}
public function Main(e: Event):void
{
player.x = mouseX;
if (bullets_arr)
{
for (var m:int = 0; m < bullets_arr.length; m++)
{
bullets_arr[m].y -= 20;
if(Game.level1.enemies_arr)
{
for (var n:int = 0; n < Game.level1.enemies_arr.length; n++)
{
if (Game.level1.enemies_arr[n].hitTestObject(bullets_arr[m]))
{
if(bullets_arr[m].parent)
{
bullets_arr[m].parent.removeChild(bullets_arr[m]);
bullets_arr.splice(bullets_arr[m],1);
Game.level1.enemies_arr[n].Damage(10, Game.level1.enemies_arr[n]);
}
}
}
}
}
}
if(fire_on)
{
fire_counter++;
if(fire_counter == 01)
{
fire();
}
else if(fire_counter >2)
{
fire_counter =0;
}
}
}
}
}
Level1.as where the enemies are spawned and pushed to the array.
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
public class Level1 extends MovieClip
{
var i:int;
var j:int;
var frame :int;
public var enemy:Enemy;
public var enemies_arr:Array;
public function Level1(target:Stage)
{
frame = 0;
enemies_arr = [];
for (var i:int = 0; i < 5; i++)
{
for (var j:int = 0; j < 3; j++)
{
enemy = new Enemy;
enemy.x = j*100 + 260;
enemy.y = i*40 - 150;
target.addChild(enemy);
enemies_arr.push(enemy);
trace(enemy.parent);
}
}
}
}
}
The Enemy class Enemy.AS
package
{
import flash.display.MovieClip;
public class Enemy extends MovieClip
{
var Health : int;
function Enemy()
{
Health =2;
}
public function Damage(Damage:int, enemyHit:Enemy)
{
Health -= Damage;
if (Health <1)
{
Die(enemyHit);
}
}
private function Die(enemyHit:Enemy)
{
if(enemyHit.parent)
{
this.parent.removeChild(this);
Game.level1.enemies_arr.splice(Game.level1.enemies_arr.indexOf(enemyHit,1));
}
}
}
}
You should traverse both Game.level1.enemies_arr and bullets_arr backwards. The point is, splice() shortens the array, shifts the elements that are in greater positions than the spliced one(s) to lesser indexes, and the loop counter is not automatically adjusted. The error is pretty common, but is often overlooked. Also, with bullets_arr you can get out of the array causing a 1009 error if your last bullet out of bullets_arr will hit an enemy.
A small nitpick: You are checking for the array's existence within a loop, and for another array's existence once within the enter frame listener. In fact you should either initialize them with at least new Array() or [] before you add an event listener to the Main object, or wherever this is assigned to, or check like if (!bullets_arr) bullets_arr=new Array(); and leave it at that, so one check of the array's existence will be needed.
public function Main(e: Event):void
{
player.x = mouseX;
if (!bullets_arr) bullets_arr=new Array();
if (!Game.level1.enemies_arr) throw new Error('Hey programmer, initialize your arrays!');
// ^ bad practice to throw exceptions in listeners, but if you get one, you've coded something wrongly.
for (var m:int=bullets_arr.length-1;m>=0;m--) {
var bm:Bullet=bullets_arr[m]; // TODO fix type
// the local variable is a cleaner and faster approach
bm.y-=20;
for (var n:int=Game.level1.enemies_arr.length-1;n>=0;n--) {
if (!bm) break; // bullet was destroyed, why checking more enemies vs that?
if (Game.level1.enemies_arr[n].hitTestObject(bm)) {
bm.parent.removeChild(bm);
bullets_arr.splice(m,1); // splice is done by index, not by object
bm=null; // oops, missed this. The bullet hit something and is now lost
// so we null the local var, so we can break out the loop.
Game.level1.enemies_arr[n].Damage(10, Game.level1.enemies_arr[n]);
}
}
}
// rest of your code follows here
}
I finally found the problem, it was very stupid of me :
I just mistyped the Die function in the Enemy class :
I have written :splice(Game.level1.enemies_arr.indexOf(enemyHit,1)) instead of splice(Game.level1.enemies_arr.indexOf(enemyHit),1)
Anyway I learnt a lot of think by trying to fix this error.
Thanks
package
{
import flash.events.Event;
import flash.display.MovieClip;
// class
public class GameGrid extends MovieClip
{
private var gameHeight:Number = 600;
private var gameWeight:Number = 800;
private var gridHeight:Number = 50;
private var gridWeight:Number = 50;
private var rowNumber:int = 12;
private var columnNumber:int = 16;
private var backgroundGrid:Array = new Array(12,16);
private var foregroundGrid:Array = new Array(12,16);
function GameGrid(){
}
function addBackGrid(rowN:int,colN:int,mcObject:MovieClip)
{
backgroundGrid[rowN,colN].push(mcObject);
}
function addForeGrid(rowN:int,colN:int,mcObject:MovieClip)
{
foregroundGrid[rowN,colN].push(mcObject);
}
function calculateRowDiff(rowA:int,rowB:int):Number
{
return Math.abs(rowA-rowB);
}
function calculateColDiff(colA:int,colB:int):Number
{
return Math.abs(colA-colB);
}
function calculateCorDiff(colA:int,colB:int,rowA:int,rowB:int):Number
{
return Math.sqrt((calculateRowDiff(rowA,rowB) * calculateRowDiff(rowA,rowB)) + (calculateColDiff(colA,colB) * calculateColDiff(colA,colB)));
}
// add to stage
function paintbackgroundGrid()
{
for (var i:int=0; i<16; i++)
{
for (var j:int=0; j<12; j++)
{
MovieClip(backgroundGrid[i,j]).x = i * 50;
MovieClip(backgroundGrid[i,j]).y = j * 50;
stage.addChild(MovieClip(backgroundGrid[i,j]));
}
}
}
}
}
So what this GameGrid class do is to hold an Array of grids(or tiles which extends MovieCLip) that will be added to the main stage and will call the initializeItem function.
function InitializeItem(e:Event)
{
var gamemap = new GameGrid();
var mc:MovieClip = new MainCharacter();
gamemap.addBackGrid(1,1,mc);
gamemap.paintbackgroundGrid();
//trace("Year: "+gameTime.gameYear+" Month: "+gameTime.gameMonth+" Day: "+gameTime.gameDay+" "+gameTime.gameHour+":"+gameTime.gameMinute+":"+gameTime.gameSecond);
}
The initializeItem should create an instance of gamegrid, and add movieclips to their respective locations(stored using array) and display them.
and this is the error stacktrace:
ReferenceError: Error #1069: Property 1 not found on Number and there is no default value.
at GameGrid/addBackGrid()
The debugger suggest that the error came from the line backgroundGrid[rowN,colN].push(mcObject);
Is there a way I can hold a 2d array movieclips? I'm new to AS3 and it looks very similar to JAVA, what am I missing?
Try this
private var backgroundGrid = [];
function addBackGrid(rowN:int,colN:int,mcObject:MovieClip) {
if (backgroundGrid[rowN] == null) {
backgroundGrid[rowN] = [];
}
backgroundGrid[rowN][colN] = mcObject;
}
In as3, following code means create a array and the array contains two elements, one is 12, and the other is 16.
private var backgroundGrid:Array = new Array(12,16);
I wanted to setup an array of movieclip buttons to navigate across my timeline via labels, this is where it went pear shaped.
Having spent three days reading and attempting most online solutions I couldn't find a method which worked 100% without failing in some way or another.
I've had some joy with the method below having seen a blog entry covering different ways to call frames etc and which highlighted the bugbear below :
clipArray[i].mouseChildren = false; //Hidden bugbear
I've added the full code below so hopefully it may help anyone else who similarly nearly resorted to hari-kari in trying this.
import flash.events.MouseEvent;
import flash.events.Event;
var clipArray:Array = [btn_1,btn_2]; // Movieclip's called btn_1 etc...
var destArray:Array = ["page_1","page_2"]; Labels on timeline...
for (var i:int = 0; i < clipArray.length; i++) {
clipArray[i].buttonMode = true; // Define Button from Movie Clip
clipArray[i].useHandCursor = true; // Enable HandCursor over clip
clipArray[i].mouseChildren = false; // Define clip as single denomination
clipArray[i].addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
clipArray[i].addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
clipArray[i].addEventListener(Event.ENTER_FRAME, frameHandler);
clipArray[i].addEventListener(MouseEvent.CLICK,clickHandler, false, 0, true);
}
function clickHandler(event:MouseEvent):void {
for (var i:int = 0; i < clipArray.length; i++) {
if (event.currentTarget == clipArray[i]) {
this.gotoAndStop(destArray[i]);
clipArray[i].mouseEnabled = false;
clipArray[i].useHandCursor = false;
clipArray[i].alpha = 0.5;
} else {
clipArray[i].mouseEnabled = true;
clipArray[i].useHandCursor = true;
clipArray[i].alpha = 1;
}
}
}
function mouseOverHandler(e:MouseEvent){
e.target.onOff = true;
}
function mouseOutHandler(e:MouseEvent){
e.target.onOff = false;
}
function frameHandler(e:Event){
if(e.target.onOff){
e.target.nextFrame();
} else {
e.target.prevFrame();
}
}
This works fine, now however my understanding of whether it is 'good' code or not is an issue, if this could be improved in any way I'd like to know why and how as the problem with learning AS3 from 2 is that often you use code having seen it online without fully grasping the detail.
Tentatively, I'm pleased as this proved to be a nightmare to find or to resolve and hope it helps anyone else in a similar state of mind.
Adding MovieClip buttons with fluidity and which cancel out from an array became a three day mission when you're learning...
You might find you have more freedom if you put all of this in a class and use the Tween class to travel to your 'labels' instead of the timeline. It would mean that you would be able to remove your event listeners until your animation has finished.
Also it looks like you might be better off using the MouseEvent.ROLL_OVER and MouseEvent.ROLL_OUT
If I'm honest I don't know what some of your methods want to do without seeing your whole project, but I've quickly written a class for you. I've replaced animating between pages with just having your buttons animate to a ramdom location. (Remember to export your MovieClips you create with the IDE into actionscript, giving them the class name Button01, Button02 etc...). I hope this sends you in the right direction :)
package com
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
public class Main extends MovieClip
{
private var btn_1:Button01 = new Button01;
private var btn_2:Button02 = new Button02;
private var clipArray:Array = new Array();
private var xAxis:Number = 0;
private var yAxis:Number = 0;
private static const WIDTH:int = 300;
private static const HEIGHT:int = 250;
private var tweenButton:Tween;
public function Main()
{
makeArrays();
addChildren();
setEventListeners()
}
private function makeArrays():void
{
for(var i:uint=0; i<2; i++)
clipArray.push(this['btn_'+(i+1)]);
}
private function addChildren():void
{
for(var i:uint=0; i<clipArray.length; i++){
addChild(clipArray[i]);
clipArray[i].x = WIDTH*Math.random();
clipArray[i].y = HEIGHT*Math.random();
}
}
private function setEventListeners():void
{
for (var i:uint=0; i<clipArray.length; i++) {
clipArray[i].buttonMode = true; // Define Button from Movie Clip
//clipArray[i].useHandCursor = true; // Enable HandCursor over clip
//clipArray[i].mouseChildren = false; // Define clip as single denomination // DON'T NEED THIS WITH ROLL_OVER
clipArray[i].addEventListener(MouseEvent.ROLL_OVER, mouseOverHandler);
clipArray[i].addEventListener(MouseEvent.ROLL_OUT, mouseOutHandler);
clipArray[i].addEventListener(Event.ENTER_FRAME, frameHandler);
clipArray[i].addEventListener(MouseEvent.CLICK, clickHandler, false, 0, true);
}
}
private function tweenButtons(e:Event):void
{
var dispObj = e.currentTarget as DisplayObject;
dispObj.removeEventListener(MouseEvent.CLICK, clickHandler)
tweenButton = new Tween(dispObj, 'x', Regular.easeIn, dispObj.x, WIDTH*Math.random(), 1, true);
tweenButton = new Tween(dispObj, 'y', Regular.easeIn, dispObj.y, HEIGHT*Math.random(), 1, true);
tweenButton.addEventListener(TweenEvent.MOTION_FINISH, reattachEventListener);
}
private function reattachEventListener(e:Event):void
{
tweenButton.removeEventListener(TweenEvent.MOTION_FINISH, reattachEventListener);
for (var i:uint=0; i<clipArray.length; i++) {
if(!(hasEventListener(MouseEvent.CLICK)))
clipArray[i].addEventListener(MouseEvent.CLICK, clickHandler, false, 0, true);
}
}
private function clickHandler(e:MouseEvent):void
{
for (var i:uint=0; i<clipArray.length; i++) {
if (e.currentTarget == clipArray[i]) {
tweenButtons(e);
clipArray[i].buttonMode = false
clipArray[i].alpha = 0.5;
} else {
clipArray[i].buttonMode = true;
clipArray[i].alpha = 1;
}
}
}
private function mouseOverHandler(e:MouseEvent):void // I HAVE NO IDEA WHAT YOU'RE TRYING TO DO HERE
{
e.target.onOff = true;
}
private function mouseOutHandler(e:MouseEvent):void // I HAVE NO IDEA WHAT YOU'RE TRYING TO DO HERE
{
e.target.onOff = false;
}
private function frameHandler(e:Event):void // I HAVE NO IDEA WHAT YOU'RE TRYING TO DO HERE
{
if(e.target.onOff){
e.target.nextFrame();
}else{
e.target.prevFrame();
}
}
}
}
Hi I try pass my Arry to Class. I try to pass it and it look like this:
Frame 32 earlier are some animations.
import flash.events.MouseEvent;
import fl.transitions.Tween;
import flash.display.MovieClip;
import Wyjazd;
stop();
ofertaBTN.addEventListener(MouseEvent.CLICK, wyskok);
function wyskok(e:MouseEvent)
{
var vektor:Array = new Array(I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII);
var menu:Wyjazd = new Wyjazd(vektor);
}
Class
package
{
import fl.transitions.Tween;
import fl.motion.easing.*;
import flash.filters.*;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.display.MovieClip;
public class Wyjazd extends MovieClip
{
public function Wyjazd(ar:Array)
{
var xX = ar.x;
var time:Number = 2;
var offset:Number = 0;
for (var i:Number = 0; i < 12; i++)
{
var tween:Tween = new Tween(ar[i],"x",Sine.easeOut,ar[i].x,266.65 + offset,time,true);
ar[i].addEventListener(MouseEvent.MOUSE_OVER,podswietlenie);
ar[i].addEventListener(MouseEvent.MOUSE_OUT,zgaszenie);
time += 0.2;
offset += 15.25;
}
function zgaszenie(e:MouseEvent)
{
ar[i].filters = [];
}
function podswietlenie(e:MouseEvent)
{
var pods:GlowFilter = new GlowFilter ;
pods.inner = false;
pods.color = 0x000000;
pods.knockout = false;
ar[i].filters = [pods];
}
/*var targetLabel:String;
ar.addEventListener(MouseEvent.MOUSE_OVER, podswietlenie);
ar.addEventListener(MouseEvent.MOUSE_OUT, zgaszenie);
ar.addEventListener(MouseEvent.CLICK,przejscie);
function przejscie(e:MouseEvent)
{
targetLabel= e.currentTarget.name;
tween = new Tween(ar,"x",Sine.easeOut,ar.x,xX,time,true);
trace(targetLabel);
}*/
}
}
}
But I still gets Error #1063. It say that I pass no argument. How pass it properly? So Could you help me?
UPDATE #1:
I use try use trace. Frame code isn't chance but Class look like this.
package
{
import fl.transitions.Tween;
import fl.motion.easing.*;
import flash.filters.*;
import flash.events.MouseEvent;
import flash.display.Stage;
import flash.display.MovieClip;
public class Wyjazd extends MovieClip
{
public function Wyjazd(ar:Array)
{
trace(ar.length);
//reast is commented
}
}
}
But still, I got Error #1063, we must go deeper. Then I change frame code:
import flash.events.MouseEvent;
import fl.transitions.Tween;
import flash.display.MovieClip;
stop();
ofertaBTN.addEventListener(MouseEvent.CLICK, wyskok);
function wyskok(e:MouseEvent)
{
var vektor:Array = [I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII];
trace(vektor.lenght);
//var menu:Wyjazd = new Wyjazd(vektor);
}
Now I got Error #1007 Instantiation attempted on a non-constructor. at site_fla::MainTimeline/wyskok()
It looks like you meant to quote each of the values in the array:
new Array('I','II','III','IV','V','VI','VII','VIII','IX','X','XI','XII');
To narrow it down, I would suggest commenting out your Wyjazd function code and replacing it with a trace statement such as trace(ar.length);
See if you can run that and if it traces out the array length. If it can, then the problem is not the passing of the array to the function.
I was able to test this and it worked for me when I created this, so that's why I suggest the above.
If it does still throw the same error, then can you supply me with a little more information?
Are you using Flash Professional?
Are you calling var vektor from frame 1 in the actions tab?
Are you calling the Wyjazd class from your main document any other way (such as adding the class to the .fla properties?
Try this:
var vektor:Array = [I,II,III,IV,V,VI,VII,VIII,IX,X,XI,XII];
Also, I think this line is not correct:
var xX = ar.x;
.. and btw, you could change this too
// for (var i:Number = 0; i < 12; i++)
for (var i:int = 0; i < ar.length; i++)
You can't have a parameter for a symbol that is instanciate from the IDE, check this similar question and answer : AS3 not accepting constructor
You have to try to initialize your class differentely, but it really depends on your usage
for example :
public class Wyjazd extends MovieClip
{
public function Wyjazd(ar:Array=null) // use a default parameter
{
if (ar!=null) init(ar) // call your init function
}
public function init(ar:Array):void {
var xX = ar.x;
var time:Number = 2;
var offset:Number = 0;
for (var i:Number = 0; i < 12; i++)
{
var tween:Tween = new Tween(ar[i],"x",Sine.easeOut,ar[i].x,266.65 + offset,time,true);
ar[i].addEventListener(MouseEvent.MOUSE_OVER,podswietlenie);
ar[i].addEventListener(MouseEvent.MOUSE_OUT,zgaszenie);
time += 0.2;
offset += 15.25;
}
function zgaszenie(e:MouseEvent)
{
ar[i].filters = [];
}
function podswietlenie(e:MouseEvent)
{
var pods:GlowFilter = new GlowFilter ;
pods.inner = false;
pods.color = 0x000000;
pods.knockout = false;
ar[i].filters = [pods];
}
/*var targetLabel:String;
ar.addEventListener(MouseEvent.MOUSE_OVER, podswietlenie);
ar.addEventListener(MouseEvent.MOUSE_OUT, zgaszenie);
ar.addEventListener(MouseEvent.CLICK,przejscie);
function przejscie(e:MouseEvent)
{
targetLabel= e.currentTarget.name;
tween = new Tween(ar,"x",Sine.easeOut,ar.x,xX,time,true);
trace(targetLabel);
}*/
}
}
}