home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / VenusMission.swf / scripts / __Packages / games / MovingScene.as < prev    next >
Encoding:
Text File  |  2008-09-23  |  2.8 KB  |  88 lines

  1. class games.MovingScene extends AsBroadcaster
  2. {
  3.    var sceneMC;
  4.    var sceneArea;
  5.    var scenesTable;
  6.    function MovingScene(containerMC, d, w, h)
  7.    {
  8.       super();
  9.       this.sceneMC = containerMC.createEmptyMovieClip("movingscene" + d,d);
  10.       this.sceneArea = {_width:w,_height:h};
  11.       this.scenesTable = new Array();
  12.       AsBroadcaster.initialize(this);
  13.    }
  14.    function moveBackground(scene, speed)
  15.    {
  16.       var tMC = scene.MC;
  17.       var cMC = scene.container;
  18.       tMC._x = Math.ceil(tMC._x + speed);
  19.       var p;
  20.       var gb_inC = tMC.getBounds(cMC);
  21.       var gb_inT = tMC.getBounds();
  22.       if(gb_inC.xMax < this.sceneArea._width)
  23.       {
  24.          p = scene.element.createElement(tMC);
  25.          var tname = tMC._name;
  26.          var tdepth = tMC.getDepth();
  27.          var tposY = tMC._y;
  28.          var tposX = tMC._x;
  29.          var tScale = tMC._yscale;
  30.          var bitmap = scene.bitmap = new flash.display.BitmapData(gb_inC.xMax + p.width,tMC._height,true,0);
  31.          bitmap.draw(cMC);
  32.          tMC.removeMovieClip();
  33.          tMC = cMC.createEmptyMovieClip(tname,tdepth);
  34.          tMC._y = tposY;
  35.          tMC._yscale = tScale;
  36.          Object(tMC).attachBitmap(bitmap,0,true,false);
  37.          scene.broadcastMessage("onNewSceneElement",scene.upper,tMC._width,!scene.upper ? scene.posY - p.height : scene.posY + p.height);
  38.       }
  39.    }
  40.    function moveScene(moveby)
  41.    {
  42.       var obj;
  43.       for(var pos in this.scenesTable)
  44.       {
  45.          obj = this.scenesTable[pos];
  46.          this.moveBackground(obj,moveby * obj.multiplier);
  47.       }
  48.    }
  49.    function getBitmapOf(bgno)
  50.    {
  51.       return this.scenesTable[bgno].bitmap;
  52.    }
  53.    function getMCOf(bgno)
  54.    {
  55.       return this.scenesTable[bgno].MC;
  56.    }
  57.    function getSceneMC()
  58.    {
  59.       return this.sceneMC;
  60.    }
  61.    function broadcastBackground(bgno)
  62.    {
  63.       var scene = this.scenesTable[bgno];
  64.       scene.broadcastMessage = system.Delegate.create(this,this.broadcastMessage);
  65.    }
  66.    function addBackground(bgno, speedmultiplier, ypos, upper, w0, w1, h0, h1, wall0, slope0, wall1, slope1)
  67.    {
  68.       var scene = this.scenesTable[bgno] = new Object();
  69.       var tMC = this.sceneMC.createEmptyMovieClip("scene" + bgno,1000 - bgno);
  70.       tMC._y = ypos;
  71.       tMC.cacheAsBitmap = true;
  72.       if(upper != true)
  73.       {
  74.          tMC._yscale = -100;
  75.       }
  76.       scene.broadcastMessage = null;
  77.       scene.multiplier = - speedmultiplier;
  78.       scene.upper = upper;
  79.       scene.posY = ypos;
  80.       scene.container = tMC;
  81.       tMC = scene.MC = tMC.createEmptyMovieClip("viewMC",0);
  82.       tMC._x = this.sceneArea._width;
  83.       scene.bitmap = new flash.display.BitmapData(0,0);
  84.       scene.element = new games.MovingSceneElement(w0,w1,h0,h1,wall0,slope0,wall1,slope1,upper);
  85.       scene.element.createElement(tMC);
  86.    }
  87. }
  88.