This is my first post ever :). I have quite a bit of experience in c# and a little in as3 and a lot in animation. Anyway onto the question.
I'm attempting to create a graphical representation of the microphone activity in flash for a conference.
I got a movieclip called eqNotch that's just a rectangle and its linkage name is EqNotch. I also have a movieclip where I am writing my as3 on the first frame, its called dynamicBar and linkage name is DynamicBar.
I've successfully written the code for the dynamicBar to create one column of eqNotches and the number of rows is dependent on mic activity. Here comes the problem: I place one on the stage, works fine. but i want to place about 25 and it only displays one. I tried loops creating dynamic items on the first frame on the stage. I tried dragging separately from the library I tried looping inside the dynamic bar code to move .x dependent on what loop it was in and inside that was the "while (this.numChildren < floater){..."
I want to be able to repeat the code of this object multiple times or something to that effect.
Code for dynamicBar:
import flash.media.Microphone;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;
var my_mic:Microphone = Microphone.getMicrophone();
my_mic.rate = 22;
my_mic.gain = 100;
my_mic.addEventListener(SampleDataEvent.SAMPLE_DATA, drawSampleData);
var myTimer:Timer = new Timer(20,8);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
var lastData:int;
var timeRemover;
var myData:ByteArray;
function timerListener(e:TimerEvent):void
{
var currentData:int = 1;
var floater:int = 1;
try
{
//currentData = myData.readFloat()*30;
currentData = my_mic.activityLevel/5;
}
catch (e:Error)
{
currentData = 1;
}
try
{
floater = Math.abs(((currentData*3 + lastData)/4)); //- (stage.x/2))
}
catch (e:Error)
{
floater = currentData;
}
lastData = currentData;
if (floater > 20)
{
floater = 20;
}
if (floater < 1)
{
floater = 1;
}
var numOfCols:int = 5;
var j:int;
var i:int;
while (this.numChildren < floater)
{
i++;
var eqNotch:EqNotch = new EqNotch();
eqNotch.y = i * -10;
try
{
addChild(eqNotch);
}
catch (e:Error)
{
}
}
this.removeChildAt(this.numChildren-1);
}
function drawSampleData(eventObject:SampleDataEvent):void
{
myTimer.start();
myData = eventObject.data;
}
UPDATE
Great idea Adam, I got it though but I am having trouble deleting the correct ones. I'm a little too far in to quit now and i want to learn this for the experience.
I had to create an array to record the height of each. It adds them properly but doesn't delete them correctly.
import flash.media.Microphone;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;
var my_mic:Microphone = Microphone.getMicrophone();
my_mic.rate = 22;
my_mic.gain = 100;
my_mic.addEventListener(SampleDataEvent.SAMPLE_DATA, drawSampleData);
var myTimer:Timer = new Timer(20,8);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
var lastData:int;
var timeRemover;
var myData:ByteArray;
var numOfCols:int = 25;
var columns:Array = new Array();
/*for (var iLoop:iLoop=0;iLoop<numOfCols;iLoop++){
column[
}*/
function timerListener(e:TimerEvent):void
{
var currentData:int = 1;
var floater:int = 1;
try
{
//currentData = myData.readFloat()*30;
currentData = my_mic.activityLevel / 5;
}
catch (e:Error)
{
currentData = 1;
}
try
{
floater = Math.abs(((currentData*3 + lastData)/4));//- (stage.x/2))
}
catch (e:Error)
{
floater = currentData;
}
lastData = currentData;
if (floater > 20)
{
floater = 20;
}
if (floater < 1)
{
floater = 1;
}
for(var j:int = 0; j<numOfCols;j++)
{
var notchDistance:int = j * 30;
if(columns[j]==null){
columns[j]=0;
}
while (int(columns[j]) <= floater)
{
var eqNotch:EqNotch = new EqNotch();
eqNotch.x = notchDistance;
eqNotch.y = int(columns[j]) * -7;
addChild(eqNotch);
columns[j]++;
}
if(int(columns[j]) >= floater){
columns[j]--;
this.removeChildAt(int(columns[j])*(j+1)-1-j);
trace("height"+columns[j]+"col"+j);
}
}
}
function drawSampleData(eventObject:SampleDataEvent):void
{
myTimer.start();
myData = eventObject.data;
}