Array element visibility

How to use an array to make random visib

Page 1 of 1

5 Replies - 3871 Views - Last Post: 30 March 2006 - 12:50 AM

#1 Alvaro Pablo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-March 06

Array element visibility

Posted 19 March 2006 - 05:53 PM

Describes the mood or content of the topic posted 03-19-06 09:27 PM
Hi, I have a script problem in Flash not sure it can be easily solved.
I am a casual Flash user and not sure if there is a easy solution to this:

I have and array of elements from which one of them is retrieve randomly, and then stored in the variable selectedElement

myElements = new Array("beerBelt", "bottleBelt", "canBelt", "chipBelt");

function randomAll() {
_global.randomNumber = Math.round(Math.random()*(myElements.length-1));
_global.selectedElement = myElements[randomNumber];
};


Inside a MC in the same scene I have a series of MCs with the instance name exactly the same names as the variable elements, they are invisible from the first frame,

beerBelt._visible = false;
bottleBelt._visible = false;
canBelt._visible = false;
chipBelt._visible = false;


then an action frame appears to make the selected MC visible,

selectedElement._visible = true;
selectedElement.gotoAndPlay(_currentframe + 1);
stop();


for any reason (my lack of knowledge sure is the one to blame) I cannot make that element visible, I tried everything I know.
Could you please advice me what is the best way to aproach this problem?
Is it really possible to use variables values (in this case strings) to modify a element property?
Am I missing something?

Please any comment would be really welcome....

Is This A Good Question/Topic? 0
  • +

Replies To: Array element visibility

#2 CyberCoder   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 19-March 06

Re: Array element visibility

Posted 19 March 2006 - 06:35 PM

You could store your data in a movieclip, then remove it using removeMovieClip(); in an if statement.
Was This Post Helpful? 0
  • +
  • -

#3 pioSko   User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Array element visibility

Posted 20 March 2006 - 01:57 AM

CyberCoder, on 20 Mar, 2006 - 01:27 AM, said:

You could store your data in a movieclip, then remove it using removeMovieClip(); in an if statement.

Makes no sense. What if he wants to re-use movieClips?

Alvaro, all you have to do is target the movieClip correctly. Since, I don't know from where the last set of actions is being called from, I will improvise.

First of all, the randomAll() function can be slightly modified. Specificlly the action creating the random number. What you have works, but it can be simplified to:
function randomAll() {
    _global.randomNumber = random(myElements.length);
    _global.selectedElement = myElements[randomNumber];
}


In the movieClip with the elements, call the randomAll() function and then target the element using _global variables...
beerBelt._visible = false;
bottleBelt._visible = false;
canBelt._visible = false;
chipBelt._visible = false;

_parent.randomAll();

this[selectedElement]._visible = true;
this[selectedElement].gotoAndPlay(_currentframe + 1);


The _parent.randomAll() depends on where you have the randomAll() function. You might have to modify that to suit your code.
Was This Post Helpful? 0
  • +
  • -

#4 Alvaro Pablo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-March 06

Re: Array element visibility

Posted 20 March 2006 - 09:07 AM

It works now

thanks very much to all

small adjustments, big difference
Was This Post Helpful? 0
  • +
  • -

#5 Alvaro Pablo   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 19-March 06

Re: Array element visibility

Posted 29 March 2006 - 05:08 PM

Again, I have another question…..about arrays….

From the previous script I posted, how can I “refresh” the array….I mean making this as it was at the beginning of the movie? The point is that I random the elements and the one is chosen is deleted from the array, but I need the array to be full again when the user starts a new round and the elements in the array in the same order as they where.


Any ideas?
:rolleyes:
Was This Post Helpful? 0
  • +
  • -

#6 pioSko   User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Array element visibility

Posted 30 March 2006 - 12:50 AM

Make a function that sets the array. whn you work on it do it just like before, but when you want to start over call the function whihc sets the array again how it was.
function makeArray(){
    myElements = new Array("beerBelt", "bottleBelt", "canBelt", "chipBelt");
}
makeArray();


Something like that. Now, whenever you want to reset your array you call the makeArray() function.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1