0 Replies - 983 Views - Last Post: 02 April 2012 - 03:01 AM

#1 Dan123456789  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-April 12

Actionscript 2.0 array won't hold data

Posted 02 April 2012 - 03:01 AM

Hi,
I'm new to flash and making an interactive game I need an array to store strings of words which will then be looped through and every time a word matches a button name it'll play the button sound.

I can't get the array to hold the data every time the program loops through it seems to reset it and I don't know how to make it not do this.

The trace prints
NaN
0
NaN
0
NaN
0

everytime the orange or pink button is pressed... it's only on them at the moment as I want to get it working before I try it with all the buttons.

If anyone can help that would be amazing thanks.



_global.songArray = new Array();
_global.FreeIndex = new int;

	

Slider_1.onPress= function(){
	this.startDrag(true, _root.Groove_1._x, _root.Groove_1._y, _root.Groove_1._x + 350,  _root.Groove_1._y);// makes the slider move when the mouse is pressed, restricts the slider to movement only on the x axis up to the end of the groove. 
	
}

Slider_1.onRelease = function(){
	this.stopDrag();// When mouse click is released stop moving the volume slider
	
}

PlayBTN.onRelease = function(){
	mySong = new Sound()// variable to hold sound mySong
	mySong.attachSound("Example1");//MySong is given the sound 
	mySong.start(0,50);//Start it as soon as the button is pressed loop it 50 times
	
}

StopBTN.onRelease= function(){
	stopAllSounds();//Stop all sounds when stop button is pressed.
}

Slider_1.onmousemove = function(){
	newPoint = new Object();//makes the volume change when the slider is moved
	newPoint.x = this._x
	newPoint.y = this._y
	_root.Groove_1.globalToLocal(newPoint);
	_root.mySong.setVolume(-1*newPoint.x);//Line that actually changes volume
}


OrangeButton.onRelease = function(){
	OrangeSound = new Sound();//When coloured buttons are pressed they make the sound that corresponds in the library
	OrangeSound.attachSound("OrangeSound");//the name of the sound in the library
	OrangeSound.start(0,1);//They only make the sound for one loop 
	songArray[FreeIndex]="Orange";
	//trace(songArray[FreeIndex]);
	++FreeIndex;
	trace(FreeIndex);
	trace(songArray.length);
	for(i =0; i<songArray.length; ++i)
	{
		trace(songArray[i]);	}
}

PinkButton.onRelease = function(){
	PinkSound = new Sound();
	PinkSound.attachSound("PinkSound");
	PinkSound.start(0,1);
	songArray[FreeIndex]="Pink";
	//trace(songArray[FreeIndex]);
	++FreeIndex;
	trace(FreeIndex);
	trace(songArray.length);
	for(i =0; i<songArray.length; ++i)
	{
		trace(songArray[i]);	}

}

YellowButton.onRelease = function(){
	YellowSound = new Sound();
	YellowSound.attachSound("YellowSound");
	YellowSound.start(0,1);

}

BlueButton.onRelease = function(){
	BlueSound = new Sound();
	BlueSound.attachSound("BlueSound");
	BlueSound.start(0,1);

}

GreenButton.onRelease = function(){
	GreenSound = new Sound();
	GreenSound.attachSound("GreenSound");
	GreenSound.start(0,1);

}

RedButton.onRelease = function(){
	RedSound = new Sound();
	RedSound.attachSound("RedSound");
	RedSound.start(0,1);

}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1