Set the alpha of multiple movieclips in AS3?

Very simple beginner question.

I want to set the alpha of multiple movieclips in AS3

is there a shorter way to do it than separate lines like this?

pepper_mc.alpha = 0;
mushroom_mc.alpha = 0;
cheese_mc.alpha = 0;

Do you mean shorter code? You can always write:

pepper_mc.alpha=mushroom_mc.alpha=cheese_mc.alpha=0.5;

Or you can group movieclips in an array and execute a function for each of them:

var myClips:Array=new Array(pepper_mc,mushroom_mc,cheese_mc);

myClips.forEach(setAlpha);

function setAlpha(element:*, index:int, array:Array) {
	element.alpha=0.5;
}

Or you can put all movieclips in a parent movieclip and set the alpha of the parent clip only.

Thanks Glenn

The top one looks fine for now as I’ve just started tinkering with actionscript and haven’t got onto variables and arrays just yet.

I’m trying to make up a flash virtual pizza maker where users can select toppings to go onto the pizza and see them added to the blank base.

I have it started using drag and drop but I’m thinking adding all the ingredients as movieclips and simply showing/hiding them by setting their alpha to 0 or 1 as the user clicks on the buttons on the right.

here’s the drap drop version

tynesidegraphics.co.uk/pizzamaker/

If I can get this sorted then I’d like to perhaps set up a dynamic text field and an array to show the current ingredients.

Thanks for your help on the above.

Phil

Notice that there is also a visibility property in movieclip objects that you can use for showing/hiding movieclips.

myClip.visible=true; //or false to hide

I’d prefer the drag and drop version since it looks more fun to design the pizza the way I like. You may merge both though: some preset patterns for each ingredient may appear first but still dragable.

Thanks again Glenn

I’m reading adobes book and watching some video tutorials, trouble is, the more I read/watch the more options I have to do essentially the same thing.

I’ll try a few things and see how I get on.

Cheers

Phil

I’d quite like achieve this. At the moment I have 6 seperate instances of pepper_mc which can be dragged around seperately.

Rather than use separate instances could I have 1 button (pepper_btn) and set up an event listener CLICK to add separate instances of a pepper_mc to the stage.

would a function along something like this be on the right track …

function addPepper(event:MouseEvent):void
{
var pepper_mc:MovieClip = new MovieClip();
addChild(pepper_mc)
}

I’ve now managed to add a copy of the pepperomi graphic to the stage by clicking on the button. Using this code

pepper_btn.addEventListener(MouseEvent.CLICK, addPepper);

function addPepper(event:MouseEvent):void
{
	var pepperomi = new pepperomi_mc();
	addChild (pepperomi);
	trace ("pepper clicked");
}

Now all I need to do is to work out how to drag and drop the new instance.

tynesidegraphics.co.uk/pizzamaker/pizzamaker2.html

I’ve had a little help from a guy over on adobes forum and managed to come up with this.

Clicking on the ingredients on the right adds them to the stage, they can then be dragged on to the pizza base.

tynesidegraphics.co.uk/pizzamaker/pizzamaker3.html

Next step is to make some sort of bin so a user can remove ingredients which have been added.

Edit: I’ve added a couple of more ingredients and also a bin in the corner…

http://tynesidegraphics.co.uk/pizzamaker/pizzamaker5.html

Phil