Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 6 of 6

Thread: loop through a list of similar names?

  1. #1

    loop through a list of similar names?

    I have this:
    Code:
    function onAdd(e:Event){
                switch (getQualifiedClassName(e.target))
                {
                case "Symbol0":
                e.target.filters = [AdjustColorMatrix];
                break;
                case "Symbol1":
                e.target.filters = [AdjustColorMatrix];
                break;
                case "Symbol2":
                    e.target.filters = [AdjustColorMatrix];
                    break;
                case "Symbol3":
                    e.target.filters = [AdjustColorMatrix];
                    break;
                case "Symbol4":
                    e.target.filters = [AdjustColorMatrix];
                    break;
                default:
                }
            }
    but i want to do something like this:

    Code:
    for (var i:Number=1; i<=5;i++){ 
    switch (getQualifiedClassName(e.target))
              {
                case "Symbol" + i:
                 e.target.filters = [AdjustColorMatrix];
                 break;
    }
          }
    Is there a way?

    Thanks!

  2. #2
    1,391
    posts
    Registered User
    hmmm - it seems as though all of your cases perform the same operation - it looks like you shouldn't have to differentiate between them - so you should be able to just do:
    Code:
    function onAdd( e:Event ):void {
        e.currentTarget.filters = [AdjustColorMatrix];
    }

  3. #3
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Quote Originally Posted by cbeech View Post
    it looks like you shouldn't have to differentiate between them
    Unless there's more options other than Symbol0 - Symbol4.

    You could do this:
    Code:
    function onAdd(e:Event){
                switch (getQualifiedClassName(e.target))
                {
                case "Symbol0":
                case "Symbol1":
                case "Symbol2":
                case "Symbol3":
                case "Symbol4":
                    e.target.filters = [AdjustColorMatrix];
                    break;
                default:
                }
            }
    Or this:
    Code:
    if((/Symbol[0-4]/).test(getQualifiedClassName(e.target))) e.target.filters = [AdjustColorMatrix]
    Or, if all Symbol classes have a common super class or interface:
    Code:
    if(e.target is SymbolSuperClass) e.target.filters = [AdjustColorMatrix]
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  4. #4
    1,391
    posts
    Registered User
    is that a regex condition there? nice - agreed, there could certainly be other cases, but given the info presented, the referencing and test appears unnecessary *shrug* another method (among many) would be similar to your last but within a switch - something like:
    Code:
    switch( true ) {
        case (e.currentTarget is SymbolClass): e.target.filters = [AdjustColorMatrix]; break;
        case (e.currentTarget is SpriteClass): e.target.filters = [SpriteColorMatrix]; break;
        ...
    }
    curious? your reason for using target over currentTarget?

  5. #5
    TheCanadian's Avatar
    10,305
    posts
    Noo doot aboot it, eh?
    Given the info presented, it's impossible to tell what's necessary

    Yeah that's regex. I used target because it's shorter to write, but I'll use whichever one is appropriate. He used target as well...
    Proud Montanadian
    We tolerate living and breathing. And niches.

    Name Brand Watches

    Maybe getTimer() or TweenMax is the answer to your problem . . .

  6. #6
    1,391
    posts
    Registered User
    lmao! excellent point - i spend way to much time guessin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012