Skip to main content
Known Participant
May 24, 2015
Answered

looping through an Array to change visibility of MC

  • May 24, 2015
  • 1 reply
  • 745 views

Hey to anyone , lets  say i have a for() loop that creates an instance of a movieClip newText, which contains textfields inside that get pushed through an Array, and are displayed again by the array when my app is reinitiated.

and in newText i also have a button inside that deletes the information(options), and when that button is pressed another MC(delete) pops up over newText.

What is my best approach to check if this button has been pressed? should i create another Array that passes "true" to the Array, and check if ( arrayCheck["???"] == true) { what do i do here};...etc i'm lost.

because i want to make MC(delete) visibility = true; when the app is reinitiated for the instances of newText, when (options) button has been clicked; any ideas would be highly appreciated????

BELOW IS MY FOR LOOP I HAVE ALREADY

________________________________________________________________________________________________________________________________________________________________________________

var kellog: Number = -5;

  //this variable sets in  Array index at 1

  var general: Number = -1;

  for (var i: Number = 0; i < mySaveNewT.data.myNText; ++i) {

  newText = new tbox();

  newText.x = -220;

  newText.y = -513 + i * 69 + 0 * 3.8;

  kellog += 6;  // this places each array index at the correct textfield in newText

  kellogs += 6; // this places each array index at the correct textfield in newText

  trace(kellogs, "  total cereal");

  newText.CN.text = String(unwrap.mySaveData.data.myDataArray[kellog]);

  newText.DF.text = String(unwrap.mySaveData.data.myDataArray[2 + kellog + general]);

  newText.Ad.text = String(unwrap.mySaveData.data.myDataArray[3 + kellog + general]);

  newText.PN.text = String(unwrap.mySaveData.data.myDataArray[4 + kellog + general]);

  newText.tap.text = String(unwrap.mySaveData.data.mynText[kellogs]);

  newText.tip.text = String(unwrap.mySaveData.data.mynText[kellogs + generals]);

  newText.OT.text = String(unwrap.mySaveData.data.myDataArray[5 + kellog + general]);

  VWD.addChild(newText);


  myDataArrayInProgram = unwrap.mySaveData.data.myDataArray;

  myNTextAddition = unwrap.mySaveData.data.mynText;

  }

This topic has been closed for replies.
Correct answer kglad

its the btn


then why are you assigning it to i?

again, use the code i suggested but change btn to options (if that's really your buttons name).

var so:SharedObject=SharedObject.getLocal("kellogs","/");

if(so.data.btnClickA && so.data.btnClickA.length>0){

for(var i:int=0;i<so.data.btnClickA.length;i++){

trace('button',so.data.btnClickA,'was clicked')

}

} else {

so.data.btnClickA=[];

}

  for (var i: Number = 0; i < mySaveNewT.data.myNText; ++i) {

  newText = new tbox();

  newText.x = -220;

newText.options.addEventListener(MouseEvent.CLICK,buttonF);

newText.ivar=i;

.

}

function buttonF(e:MouseEvent):void{

var i:int=MovieClip(e.currentTarget.parent).ivar;

if(so.data.btnClickA.indexOf(i)==-1){

so.data.btnClickA.push(i);

}

}

1 reply

kglad
Community Expert
Community Expert
May 24, 2015

your button should have an instance name.  assign listeners to each one in your for-loop.

eg, if tbox extends a MovieClip and your button is btn:

  for (var i: Number = 0; i < mySaveNewT.data.myNText; ++i) {

  newText = new tbox();

  newText.x = -220;

newText.btn.addEventListener(MouseEvent.CLICK,buttonF);

.

.

}

function buttonF(e:MouseEvent):void{

trace(MovieClip(e.currentTarget.parent).CN.text);

}

fi500005Author
Known Participant
May 24, 2015

this works in short, but i run into the problem, that when i kill my app, the MC(delete) isnt there

i.e,  if  "i" = 3, and there is 3 newText on stage, and btn is pressed on the 2nd newText on stage. when i kill my app how can i reinitiate MC(delete)

thx kglad!!!

kglad
Community Expert
Community Expert
May 25, 2015

what do you mean by 'kill my app'?

and what do you want to happen when the button in the 2nd tbox is clicked?