[Swfdec] variable scope

Nguyen Thai Ngoc Duy pclouds at gmail.com
Sun Jun 10 16:37:32 PDT 2007


caveat: I haven't either read actionscript language spec nor really
got through swfdec context, frame and such. This is fully based on
blocky.swf code inspection.

thanks to flare, i can extract the below beautiful code. You don't
need to understand the whole thing but there is one thing to notice:
border[XY]start are initialized in on(press) and get used in
on(release). Currently swfdec makes those variable in on(press)'s
local scope or something. When on(release) is run, it cannot find
border[XY]current and hence fail to run properly.

I did a stupid hack in swfdec_as_context_eval_set_property. It checked
for border[XY]start. If it was the case then set variable in
cx->global (which i suspected global scope), not
cx->frame->var_object. It worked. So I think
swfdec_as_context_eval_set_property needs to be rechecked.

blocky.swf is flash 6, according to swfmill.

  button 155 {

    on (press) {
      if (_root.playgame) {
        borderXstart = Math.floor((_xmouse - 13) / CellSize) * CellSize + 13;
        borderYstart = Math.floor((_ymouse - 13) / CellSize) * CellSize + 13;
        switch (random(3)) {
          case 0:
            klik.start(0, 1);
            break;
          case 1:
            klik1.start(0, 1);
            break;
          case 2:
            klik2.start(0, 1);
            break;
          default:
            klik.start(0, 1);
        }
        someListener = new Object();
        someListener.onMouseMove = function () {
          _root.createEmptyMovieClip('rectangle', 10000);
          borderXcurrent = Math.floor((_xmouse - 13) / CellSize +
(_xmouse > borderXstart)) * CellSize + 13;
          borderYcurrent = Math.floor((_ymouse - 13) / CellSize +
(_ymouse > borderYstart)) * CellSize + 13;
          if (borderXcurrent > CellSize * widthMax + 13) {
            borderXcurrent = CellSize * widthMax + 13;
          }
          if (borderXcurrent < 13) {
            borderXcurrent = 13;
          }
          if (borderYcurrent > CellSize * heightMax + 13) {
            borderYcurrent = CellSize * heightMax + 13;
          }
          if (borderYcurrent < 13) {
            borderYcurrent = 13;
          }
          with (_root.rectangle) {
            lineStyle(10, 5592405, 100);
            moveTo(borderXstart + (borderXcurrent <= borderXstart) *
CellSize, borderYstart + (borderYcurrent <= borderYstart) * CellSize);
            lineTo(borderXcurrent, borderYstart + (borderYcurrent <=
borderYstart) * CellSize);
            lineTo(borderXcurrent, borderYcurrent);
            lineTo(borderXstart + (borderXcurrent <= borderXstart) *
CellSize, borderYcurrent);
            lineTo(borderXstart + (borderXcurrent <= borderXstart) *
CellSize, borderYstart + (borderYcurrent <= borderYstart) * CellSize);
            lineStyle(4, 16777215, 100);
            moveTo(borderXstart + (borderXcurrent <= borderXstart) *
CellSize, borderYstart + (borderYcurrent <= borderYstart) * CellSize);
            lineTo(borderXcurrent, borderYstart + (borderYcurrent <=
borderYstart) * CellSize);
            lineTo(borderXcurrent, borderYcurrent);
            lineTo(borderXstart + (borderXcurrent <= borderXstart) *
CellSize, borderYcurrent);
            lineTo(borderXstart + (borderXcurrent <= borderXstart) *
CellSize, borderYstart + (borderYcurrent <= borderYstart) * CellSize);
          }
          possibleRectangle(Math.floor((borderXstart - 13) /
CellSize), Math.floor((borderYstart - 13) / CellSize),
Math.floor((borderXcurrent - 13) / CellSize - Number(borderXcurrent >
borderXstart)), Math.floor((borderYcurrent - 13) / CellSize -
Number(borderYcurrent > borderYstart)));
        };

        Mouse.addListener(someListener);
      }
    }

    on (release) {
      if (_root.playgame) {
        _root.rectangle.removeMovieClip();
        Mouse.removeListener(someListener);
        checkForLegal(Math.floor((borderXstart - 13) / CellSize),
Math.floor((borderYstart - 13) / CellSize), Math.floor((borderXcurrent
- 13) / CellSize - Number(borderXcurrent > borderXstart)),
Math.floor((borderYcurrent - 13) / CellSize - Number(borderYcurrent >
borderYstart)));
      }
    }

    on (releaseOutside) {
      if (_root.playgame) {
        _root.rectangle.removeMovieClip();
        Mouse.removeListener(someListener);
        checkForLegal(Math.floor((borderXstart - 13) / CellSize),
Math.floor((borderYstart - 13) / CellSize), Math.floor((borderXcurrent
- 13) / CellSize - Number(borderXcurrent > borderXstart)),
Math.floor((borderYcurrent - 13) / CellSize - Number(borderYcurrent >
borderYstart)));
      }
    }
  }


-- 
Duy


More information about the Swfdec mailing list