Be a Supporter!

multiple array objects

  • 141 Views
  • 7 Replies
New Topic Respond to this Topic
A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
multiple array objects 2013-11-25 22:28:32 Reply

Any one know a way to delay multiple array objects from being added into my contsiner at the same time using as3?! I failed to use the timer to it, any idea ?

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Online!
Forum Stats
Supporter
Level 16
Game Developer
Response to multiple array objects 2013-11-25 23:42:23 Reply

At 11/25/13 10:28 PM, A-Genius wrote: Any one know a way to delay multiple array objects from being added into my contsiner at the same time using as3?! I failed to use the timer to it, any idea ?

Add the item to the array in the TimerEvent.TIMER handler function.

kkots
kkots
  • Member since: Apr. 16, 2013
  • Offline.
Forum Stats
Supporter
Level 10
Blank Slate
Response to multiple array objects 2013-11-26 11:38:42 Reply

Post your code, and point out where the problem is, using code comments //


BBS Signature
A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to multiple array objects 2013-11-26 18:23:24 Reply

At 11/26/13 11:38 AM, kkots wrote: Post your code, and point out where the problem is, using code comments //

I want my to execute the code inside my class but I think using setInterval(); was a bad idea

var i:Number =0;
var m1:Array = [new monster1()];
var MyTimer:Timer = new Timer(2000,8);

MyTimer.addEventListener(TimerEvent.TIMER,TimerFunction);

//the function increment and decrement the y and x in the path I have created it for it
function td():void{
m1[i].mapPattern();
}

function TimerFunction(e:TimerEvent):void{

for(i=0; i<m1.length; i++){
enemy_contain_mc.addChild(m1[i]);

//doesn't work
setInterval(td,1);
}
// doesn't work

}

MyTimer.start();
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Online!
Forum Stats
Supporter
Level 16
Game Developer
Response to multiple array objects 2013-11-26 18:59:10 Reply

At 11/26/13 06:23 PM, A-Genius wrote:
At 11/26/13 11:38 AM, kkots wrote: Post your code, and point out where the problem is, using code comments //
I want my to execute the code inside my class but I think using setInterval(); was a bad idea

You don't need setInterval, you already wrote out everything you need. Just push() the new thing into the array inside the timer function. The timer function IS your interval-setter.

A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to multiple array objects 2013-11-26 19:41:36 Reply

At 11/26/13 06:59 PM, MSGhero wrote:
I want my to execute the code inside my class but I think using setInterval(); was a bad idea
You don't need setInterval, you already wrote out everything you need. Just push() the new thing into the array inside the timer function. The timer function IS your interval-setter.

I have created this code but it works only for 2 objects

var i:Number =0;
var m1:Array = [new monster1(),new monster1()]

var addObj:Number = 21;
var MyTimer:Timer = new Timer(2000,1);
var MyTimer_2:Timer = new Timer(1,2000);
var MyTimer_3:Timer = new Timer (1,2000);

MyTimer.addEventListener(TimerEvent.TIMER,TimerFunction);

function Timer2Function(e:TimerEvent):void{
	MyTimer_3.addEventListener(TimerEvent.TIMER,Timer3Function);
	m1[i- m1.length + 1].mapPattern();
	
	if(m1[i-m1.length + 1].x == 70){
	MyTimer_3.start();
   	}
}

function Timer3Function(e:TimerEvent):void{
	m1[i- m1.length].mapPattern();
}

function TimerFunction(e:TimerEvent):void{
MyTimer_2.addEventListener(TimerEvent.TIMER,Timer2Function);


for(i=0; i<m1.length; i++){
enemy_contain_mc.addChild(m1[i]);
}

MyTimer_2.start();


}

MyTimer.start();
MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Online!
Forum Stats
Supporter
Level 16
Game Developer
Response to multiple array objects 2013-11-26 19:45:16 Reply

At 11/26/13 07:41 PM, A-Genius wrote: I have created this code but it works only for 2 objects

I don't think you understand what a timer does. Every 2 seconds your timer function runs. You want to add a new monster every 2 seconds. So add a new monster inside your timer function. The array starts out empty since you want to add things to it every 2 seconds.

array = [];
timer = new Timer(2000, 8);
timer.addEventListener(TimerEvent.TIMER, timerFunction);

function timerFunction(e:TimerEvent):void {
     array.push(new Monster());
}
A-Genius
A-Genius
  • Member since: Mar. 20, 2010
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to multiple array objects 2013-11-26 20:22:20 Reply

At 11/26/13 07:45 PM, MSGhero wrote: array = [];
timer = new Timer(2000, 8);
timer.addEventListener(TimerEvent.TIMER, timerFunction);

function timerFunction(e:TimerEvent):void {
array.push(new Monster());
}

OK now I understood the function better!