Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 show hide movie clip array items, single button.

New Here ,
Jul 10, 2014 Jul 10, 2014

Hello and please pardon my Noobdity I am teaching myself AS3 and stuck on what are obviously basics.

I have made the simplest of animations for years without using any AS3 at all, the time has come to get serious.

I do read the daylights out of all Adobe reference material now but I am stuck on this task.

I have 4 movie clip objects whose visibility I would like to control with two buttons.

First button will make two of these movie clips visible and the other two visible = false

Eg: Mc1 & Mc2> visible, Mc3 &Mc4> visible = false

The second button will perform the same function but in reverse

Eg: Mc1 & Mc2> visible = false, Mc3 & Mc4> visible

I have determined either correctly or incorrectly from endless reading & searching an array should be the best way to do this.

I may have to utilise the add child functionality but *shrugs I am lost atmo

I have been blundering about with the code for the first of the two simple buttons.

I am slowly starting to form a mindmap of what should be done but it is early days.

Here is my code and please feel free to

Latest attempt is trying to use the mouse out trigger to control the visible state of the second two movie clips.

var wcArray:Array = [myMovieclip1, myMovieclip2];

var acArray:Array = [myMovieclip3, myMovieclip4];

acComp_btn.addEventListener(MouseEvent.CLICK, _acComp); 

internal function _acComp(e:MouseEvent) : void {

    for each(var item:MovieClip in acArray) {

        item.visible = !item.visible;

     }

}

acComp_btn.addEventListener(MouseEvent.MOUSE_OUT, _wcComp);

internal function _wcComp(e:MouseEvent) : void {

    for each(var item:MovieClip in wcArray) {

        item.visible = !item.visible = false;

     }

}

Currently throwing error 1050: cannot assign to a non reference value.

The blue text works with the 2 acArray movie clips of course, hence the attempt to use mouse out. 

Any advice on the solution or best method to implement would be greatly appreciated.

TOPICS
ActionScript
2.4K
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

LEGEND , Jul 11, 2014 Jul 11, 2014

For what you are trying to do an array is moreso a complication than a solution, you've already divided that into two arrays anyways probably due to that imposition...  and having two buttons to do it is unnecessary, but you might already be realizing that since you only have code for one of them anyways.

All you need is one button that toggles the current visible properties to their opposites.

var array:Array = [myMovieclip1, myMovieclip2,myMovieclip3, myMovieclip4];

myMovieClip1.visible = myMovie

...
Translate
LEGEND ,
Jul 11, 2014 Jul 11, 2014

For what you are trying to do an array is moreso a complication than a solution, you've already divided that into two arrays anyways probably due to that imposition...  and having two buttons to do it is unnecessary, but you might already be realizing that since you only have code for one of them anyways.

All you need is one button that toggles the current visible properties to their opposites.

var array:Array = [myMovieclip1, myMovieclip2,myMovieclip3, myMovieclip4];

myMovieClip1.visible = myMovieclip2.visible = false;  // or the other two... whichever start out as invisible

btn.addEventListener(MouseEvent.CLICK,  _acComp); 

function _acComp(e:MouseEvent) : void {

    for each(var item:MovieClip in array) {

        item.visible = !item.visible;

    }

}

lf you need to have two buttons doing the opposite as you say then clicking either button has to end up affecting all buttons, not just one of the arrays as you did.  If each button has to do as you say then you should not be using the ! operator since that can switch to the opposite of what you intend, so you need to assign the specific state desired.

var wcArray:Array = [myMovieclip1, myMovieclip2];

var acArray:Array = [myMovieclip3, myMovieclip4];

acComp_btn.addEventListener(MouseEvent.CLICK, _acComp); 

function _acComp(e:MouseEvent) : void {

    for each(var item:MovieClip in acArray) {

        item.visible = false;

     }

    for each(var item2:MovieClip in wcArray) {

        item2.visible = true;

     }

}

wcComp_btn.addEventListener(MouseEvent.CLICK, _wcComp);

function _wcComp(e:MouseEvent) : void {

    for each(var item:MovieClip in wcArray) {

        item.visible = false;

     }

    for each(var item2:MovieClip in acArray) {

        item2.visible = true;

     }

}

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 ,
Jul 11, 2014 Jul 11, 2014
LATEST

Thank you Ned for taking the time to answer and cover all the possible bases.

The hours I have spent reading & searching got me most of the way, but not quite.

I have yet to scrutinise your solution but can't wait to see how far off the mark I was.

One can feign competency in just about all areas of life except computer code. lol

Love it!

Thanks again

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