the "I" scope in (for....) statement

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default Re: the "I" scope in (for....) statement

    kglad wrote:
    > first, if you set a movieclip's _visible property to false or zero, it can't
    > detect any mouse events. to remedy set it's _alpha to zero. second, you have
    > coding errors in that script, not the least of which is that setRGB() is
    > already a flash method.
    >
    It's all fine with all this. Try to trace 'i' variable and you'l
    understand it.

    This is correct code :

    for(var i=1; i<5; i++) {
    _root["b"+i].pair_mc = _root["m"+i];
    _root["b"+i].onRollOver=function(){
    trace(i+' '+this.pair_mc);
    this.pair_mc.setRGB(0xFFFFFF);
    }
    _root["b"+i].onRollOut=function(){
    this.pair_mc.setRGB(0x006600);
    }
    }

    RusD Guest

  2. Similar Questions and Discussions

    1. Application.xml -> Process -> Scope ; "app" disturbs FMSconsole
      Hi, I'm not sure if this is a bug related to version 2.0.1 but if we enable "app" scope in Application.xml (Application.xml -> Process -> Scope)...
    2. How can I callError ocurring when Event Listener methodein "for statement" is called
      Hy guys, I would be gratefull if somebody could answer me how can I call a method from flex in "for statement", that is actually in my remote...
    3. Flash Remoting and a CFC's "this" scope
      FYI - When accessing a CFC via Flash Remoting, you are making a static call, not creating an instance. This can be worked around however. You...
    4. What is postgresql doing for "statement: commit;begin;"
      Hi All I've turned on slow query reporting via log_min_duration_statement, and I've been looking through the log files. Quite a lot, I'm...
    5. execute + ArraySearch causes "Expected end of statement" error - Why?
      Here is the function ArraySearch: '-------------------------------------------------------------------------------------- 'ArraySearch will...
  3. #2

    Default the "I" scope in (for....) statement

    Hello everyone, I have some problem with the (for ... ) statement.. Basically,
    I have 4 invisible movie clip in the stage, they are named b1, b2, b3, b4,
    and another 4 movie clip in the stage, they are named m1, m2, m3, m4.

    What I want to achieve is when I rollover those invisible movie clip (b1,
    b2...), the other movie clip (m1, m2... ) change color, but it seems doesn't
    work..... I am wondering if this is something have to do with the scope of
    the "i"....

    I attached the AS here...

    Any help will be appreciated.

    Sam

    MovieClip.prototype.setRGB=function(col){
    (new Color(this)).setRGB(col);
    }

    for(i=1; i<5; i++) {

    _root["b"+i].onRollOver=function(){
    _root["m"+i].setRGB(0xFFFFFF);
    }

    _root["b"+i].onRollOut=function(){
    _root["m"+i].setRGB(0x006600);
    }

    }

    liangshun Guest

  4. #3

    Default Re: the "I" scope in (for....) statement

    first, if you set a movieclip's _visible property to false or zero, it can't
    detect any mouse events. to remedy set it's _alpha to zero. second, you have
    coding errors in that script, not the least of which is that setRGB() is
    already a flash method.

    kglad Guest

  5. #4

    Default Re: the "I" scope in (for....) statement

    now, you're introducing addtional errors. i is not a persistant variable. if
    you want to retreive the "i" associated wiht each of your movieclips you'll
    need to store its value in a persistant variable. try:

    for (var i = 1; i<5; i++) {
    _root["b"+i].pair_mc = _root["m"+i];
    _root["b"+i].iVar=i;
    _root["b"+i].onRollOver = function() {
    trace(this.iVar+' '+this.pair_mc);
    this.pair_mc.setRGB(0xFFFFFF);
    };
    _root["b"+i].onRollOut = function() {
    this.pair_mc.setRGB(0x006600);
    };
    }

    and you're still using setRGB() incorrectly. it's not a movieclip method,
    it's a color method. see the correct use above.

    kglad Guest

  6. #5

    Default Re: the "I" scope in (for....) statement

    in fact, just copy and paste this code into your movie and try it:

    MovieClip.prototype.colorChange = function(col) {
    myC = new Color(this);
    myC.setRGB(col);
    };
    for(i=1; i<5; i++) {
    _root["b"+i].onRollOver=function(){
    _root["m"+i].colorChange(0xFFFFFF);
    }
    _root["b"+i].onRollOut=function(){
    _root["m"+i].colorChange(0x006600);
    }
    }

    kglad Guest

  7. #6

    Default Re: the "I" scope in (for....) statement

    Thanks a lot ! it works perfect now. ..... I have much better understanding of nested function now.....

    Cheers!!

    Sam
    liangshun Guest

  8. #7

    Default Re: the "I" scope in (for....) statement

    Thanks a lot , RusD, kglad!!

    Cheers!

    Sam
    liangshun Guest

  9. #8

    Default Re: the "I" scope in (for....) statement

    you're very welcome and good luck, sam!
    kglad Guest

  10. #9

    Default Re: the "I" scope in (for....) statement

    kglad wrote: 
    I placed tracing of 'i' variable just to show error. I thought it's clear

    RusD Guest

  11. #10

    Default Re: the "I" scope in (for....) statement

    hi RusD, kglad, thanks again for the very helpful explaination.

    this line is the key..... :

    _root["b"+i].pair_mc = _root["m"+i];

    Cheers.

    Sam
    liangshun Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139