Skip to main content
September 9, 2007
Answered

Long switch statement - am I illogical?

  • September 9, 2007
  • 4 replies
  • 273 views
Hi

I've attached code to show what I mean:

In a function setAlpha, I am trying to alter the alpha level of movieclips depending on the returned value "num". ie if num = x then a corresponding movieclip will have its alpha reduced by a value also carried in the function.

Do I have to use a case by case switch statement as below or is there an easier way to do this. It seems very labor intensive - especially as the executing code is virtually identical save for the target.

I've explored equating the "num" value with the instance name but can't work out how to do this: something like if movieclip name is string+"num" then execute code

I'd appreciate any help,

db
This topic has been closed for replies.
Correct answer kglad
:

4 replies

Inspiring
September 10, 2007
this is also common to javascript... its a similar approach. There are two ways to access properties of an object. Dot syntax or using the array access operators.

there's some notes and examples on this page.

http://www.flash-creations.com/notes/actionscript_complexdata.php

"Accessing properties of an object"
September 10, 2007
Related syntax question:

I had tried code similar but my error was to write:

this.["clip"+num].alpha = alphaLevel;

rather than

this["clip"+num].alpha = alphaLevel;

The latter works. Yet "hardcoded" it would work as

this.clip5.alpha = 1

Why the disappearing DOT? (Stupid question?)



kglad
Community Expert
Community Expert
September 10, 2007
there's a lot to learn. but if you learn a little at a time, over a long period of time, you'll learn a lot.
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 9, 2007
:

September 10, 2007
Thank you. Learning is harsh
x