Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
0

looping through an Array to change visibility of MC

New Here ,
May 24, 2015 May 24, 2015

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;

  }

TOPICS
ActionScript
605
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , May 24, 2015 May 24, 2015

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

...
Translate
Community Expert ,
May 24, 2015 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);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 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!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2015 May 24, 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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

im using flash, and after i test movie when i exit. thats what i mean by kill app,

im trying to listen for the btn being clicked, and when that happens to store that click in maybe an Array, so when i reinitiate my app that MC(delete) is over the 2nd tbox (or any tbox btn that has been clicked) hope what im saying is making sense.

so if 2nd, 6th,10th,or 20th btn in tbox is clicked, i want to have that info stored to be reinitiated possibly through an array.

thank you

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2015 May 24, 2015

to save data to be used when you next open your flash app, use the sharedobject.

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.btn.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);

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

thx im going to try this out now

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2015 May 24, 2015

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

im getting this error

Column 61083: Syntax error: else is unexpected.

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=[];

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2015 May 24, 2015

then you misplaced that code within some other brackets.

copy and paste the code from message 5.  just add whatever you need in place is of the ellipses in the for-loop.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

one last thing thats popping up is

1067: Implicit coercion of a value of type Number to an unrelated type opt.

newText.options = i;

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

  newText = new tbox();

  newText.x = -220;

newText.btn.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);

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2015 May 24, 2015

what's

newText.options = i;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

its the btn

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2015 May 24, 2015

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);

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 24, 2015 May 24, 2015

Ok i understand, but when left newText.ivar.

i get this error

,Line 416, Column 131119: Access of possibly undefined property ivar through a reference with static type tbox.

I'm sorry for all these questions, but this is the last thing left for me to do, and its driving me crazy. thx!!!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 24, 2015 May 24, 2015

i assume tbox extends MovieClip, correct?  if so, change that line to:

MovieClip(newText).ivar=i;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 25, 2015 May 25, 2015

Thx for all your help. it didnt work for me but you led me in the right direction. I should be able to figure it out now

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 25, 2015 May 25, 2015
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines