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,297
    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,297
    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