<commit_before>/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
 * Copyright 2013 Mozilla Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*global MP3DecoderSession, AS2MovieClip, $DEBUG */

var MovieClipDefinition = (function () {
  var def = {
    __class__: 'flash.display.MovieClip',

    initialize: function () {
      this._currentFrame = 0;
      this._actualFrame = 0;
      this._currentFrameLabel = null;
      this._currentLabel = false;
      this._currentScene = 0;
      this._deferScriptExecution = false;
      this._enabled = null;
      this._frameScripts = { };
      this._framesLoaded = 1;
      this._isPlaying = true;
      this._labelMap = { };
      this._sceneFrameMap = { };
      this._sceneMap = { };
      this._scenes = [];
      this._timeline = null;
      this._totalFrames = 1;
      this._startSoundRegistrations = [];

      var s = this.symbol;
      if (s) {
        this._timeline = s.timeline || null;
        this._framesLoaded = s.framesLoaded || 1;
        this._labelMap = Object.create(s.labelMap || null);
        this._frameScripts = Object.create(s.frameScripts || null);
        this._totalFrames = s.totalFrames || 1;
        this._startSoundRegistrations = s.startSoundRegistrations || [];

        if (s.scenes) {
          this._scenes = s.scenes;
        } else {
          var map = this._labelMap;
          var labels = [];
          for (var name in map) {
            var frame = map[name];
            labels.push(new flash.display.FrameLabel(name, frame));
          }
          var scene = new flash.display.Scene('Scene 1', labels, this._totalFrames);
          this._scenes = [scene];
        }
      }

      this._needAdvance = true;
      this._onConstructFrame = function () {
        this._gotoFrame(this._currentFrame + 1);
        this._needAdvance = false;
        if (!this._isPlaying) {
          this._removeEventListener('constructFrame', this._onConstructFrame);
        }
      }.bind(this);
      this._addEventListener('constructFrame', this._onConstructFrame);
    },

    _callFrame: function (frameNum) {
      this._deferScriptExecution = true;
      if (frameNum in this._frameScripts) {
        var scripts = this._frameScripts[frameNum];
        for (var i = 0, n = scripts.length; i < n; i++) {
          if ($DEBUG) {
            try {
              scripts[i].call(this);
            } catch (e) {
              console.error('error ' + e + ', stack: \n' + e.stack);
            }
          } else {
            scripts[i].call(this);
          }
        }
      }
      this._deferScriptExecution = false;
      if (this._actualFrame !== this._currentFrame) {
        this._gotoFrame(this._actualFrame);
      }
    },
    _as2CallFrame: function (frame) {
      if (isNaN(frame)) {
        var frameNum = this._labelMap[frame];
        if (frameNum !== undefined) {
          this._callFrame(frameNum);
        }
      } else {
        this._callFrame(frame);
      }
    },

    _getAS2Object: function () {
      if (!this.$as2Object) {
        new AS2MovieClip().$attachNativeObject(this);
      }
      return this.$as2Object;
    },
    _gotoFrame: function (frameNum, scene) {
      if (frameNum < 1 || frameNum > this._totalFrames)
        frameNum = 1;

      if (frameNum > this.framesLoaded)
        frameNum = this.framesLoaded;

      var currentFrame = this._currentFrame;

      if (frameNum === currentFrame)
        return;

      this._actualFrame = frameNum;

      if (this._deferScriptExecution) {
        return;
      }

      if (currentFrame > 0) {
        var children = this._children;
        var timeline = this._timeline;
        var currentDisplayList = timeline[currentFrame - 1];
        var displayList = timeline[frameNum - 1];

        if (displayList !== currentDisplayList) {
          var walkList = frameNum > currentFrame ? displayList : currentDisplayList;

          for (var depth in walkList) {
            var cmd = displayList[depth];
            var currentListCmd = currentDisplayList[depth];
            var currentChild = null;
            var currentIndex = -1;
            var highestIndex = children.length;

            var i = highestIndex;
            while (i--) {
              var child = children[i];
              if (child._depth > depth) {
                if (child._animated)
                  highestIndex = i;
              } else if (child._depth == depth) {
                currentChild = child;
                currentIndex = i;
                break;
              }
            }

            if (!cmd) {
              if (currentChild && currentChild._owned) {
                children.splice(currentIndex, 1);

                this._control.removeChild(currentChild._control);
                currentChild._dispatchEvent(new flash.events.Event("removed"));
                if (this.stage) {
                  this.stage._removeFromStage(currentChild);
                }
                currentChild.destroy();
              }
            } else if (cmd !== currentListCmd) {
              if (currentChild &&
                  cmd.symbolId === currentListCmd.symbolId &&
                  cmd.ratio === currentListCmd.ratio) {
                if (currentChild._animated) {
                  if (cmd.hasClipDepth)
                    currentChild._clipDepth = cmd.clipDepth;

                  if (cmd.hasMatrix) {
                    var m = cmd.matrix;
                    var a = m.a;
                    var b = m.b;
                    var c = m.c;
                    var d = m.d;

                    currentChild._rotation = Math.atan2(b, a) * 180 / Math.PI;
                    var sx = Math.sqrt(a * a + b * b);
                    currentChild._scaleX = a > 0 ? sx : -sx;
                    var sy = Math.sqrt(d * d + c * c);
                    currentChild._scaleY = d > 0 ? sy : -sy;
                    var x = currentChild._x = m.tx;
                    var y = currentChild._y = m.ty;

                    currentChild._currentTransform = m;
                  }

                  if (cmd.hasCxform)
                    currentChild._cxform = cmd.cxform;

                  currentChild._invalidate();
                }
              } else {<commit_msg>Invalidate timeline objects before moving.<commit_after>/* -*- Mode: js; js-indent-level: 2; indent-tabs-mode: nil; tab-width: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
 * Copyright 2013 Mozilla Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*global MP3DecoderSession, AS2MovieClip, $DEBUG */

var MovieClipDefinition = (function () {
  var def = {
    __class__: 'flash.display.MovieClip',

    initialize: function () {
      this._currentFrame = 0;
      this._actualFrame = 0;
      this._currentFrameLabel = null;
      this._currentLabel = false;
      this._currentScene = 0;
      this._deferScriptExecution = false;
      this._enabled = null;
      this._frameScripts = { };
      this._framesLoaded = 1;
      this._isPlaying = true;
      this._labelMap = { };
      this._sceneFrameMap = { };
      this._sceneMap = { };
      this._scenes = [];
      this._timeline = null;
      this._totalFrames = 1;
      this._startSoundRegistrations = [];

      var s = this.symbol;
      if (s) {
        this._timeline = s.timeline || null;
        this._framesLoaded = s.framesLoaded || 1;
        this._labelMap = Object.create(s.labelMap || null);
        this._frameScripts = Object.create(s.frameScripts || null);
        this._totalFrames = s.totalFrames || 1;
        this._startSoundRegistrations = s.startSoundRegistrations || [];

        if (s.scenes) {
          this._scenes = s.scenes;
        } else {
          var map = this._labelMap;
          var labels = [];
          for (var name in map) {
            var frame = map[name];
            labels.push(new flash.display.FrameLabel(name, frame));
          }
          var scene = new flash.display.Scene('Scene 1', labels, this._totalFrames);
          this._scenes = [scene];
        }
      }

      this._needAdvance = true;
      this._onConstructFrame = function () {
        this._gotoFrame(this._currentFrame + 1);
        this._needAdvance = false;
        if (!this._isPlaying) {
          this._removeEventListener('constructFrame', this._onConstructFrame);
        }
      }.bind(this);
      this._addEventListener('constructFrame', this._onConstructFrame);
    },

    _callFrame: function (frameNum) {
      this._deferScriptExecution = true;
      if (frameNum in this._frameScripts) {
        var scripts = this._frameScripts[frameNum];
        for (var i = 0, n = scripts.length; i < n; i++) {
          if ($DEBUG) {
            try {
              scripts[i].call(this);
            } catch (e) {
              console.error('error ' + e + ', stack: \n' + e.stack);
            }
          } else {
            scripts[i].call(this);
          }
        }
      }
      this._deferScriptExecution = false;
      if (this._actualFrame !== this._currentFrame) {
        this._gotoFrame(this._actualFrame);
      }
    },
    _as2CallFrame: function (frame) {
      if (isNaN(frame)) {
        var frameNum = this._labelMap[frame];
        if (frameNum !== undefined) {
          this._callFrame(frameNum);
        }
      } else {
        this._callFrame(frame);
      }
    },

    _getAS2Object: function () {
      if (!this.$as2Object) {
        new AS2MovieClip().$attachNativeObject(this);
      }
      return this.$as2Object;
    },
    _gotoFrame: function (frameNum, scene) {
      if (frameNum < 1 || frameNum > this._totalFrames)
        frameNum = 1;

      if (frameNum > this.framesLoaded)
        frameNum = this.framesLoaded;

      var currentFrame = this._currentFrame;

      if (frameNum === currentFrame)
        return;

      this._actualFrame = frameNum;

      if (this._deferScriptExecution) {
        return;
      }

      if (currentFrame > 0) {
        var children = this._children;
        var timeline = this._timeline;
        var currentDisplayList = timeline[currentFrame - 1];
        var displayList = timeline[frameNum - 1];

        if (displayList !== currentDisplayList) {
          var walkList = frameNum > currentFrame ? displayList : currentDisplayList;

          for (var depth in walkList) {
            var cmd = displayList[depth];
            var currentListCmd = currentDisplayList[depth];
            var currentChild = null;
            var currentIndex = -1;
            var highestIndex = children.length;

            var i = highestIndex;
            while (i--) {
              var child = children[i];
              if (child._depth > depth) {
                if (child._animated)
                  highestIndex = i;
              } else if (child._depth == depth) {
                currentChild = child;
                currentIndex = i;
                break;
              }
            }

            if (!cmd) {
              if (currentChild && currentChild._owned) {
                children.splice(currentIndex, 1);

                this._control.removeChild(currentChild._control);
                currentChild._dispatchEvent(new flash.events.Event("removed"));
                if (this.stage) {
                  this.stage._removeFromStage(currentChild);
                }
                currentChild.destroy();
              }
            } else if (cmd !== currentListCmd) {
              if (currentChild &&
                  cmd.symbolId === currentListCmd.symbolId &&
                  cmd.ratio === currentListCmd.ratio) {
                if (currentChild._animated) {
                  currentChild._invalidate();
                  currentChild._bounds = null;

                  if (cmd.hasClipDepth)
                    currentChild._clipDepth = cmd.clipDepth;

                  if (cmd.hasMatrix) {
                    var m = cmd.matrix;
                    var a = m.a;
                    var b = m.b;
                    var c = m.c;
                    var d = m.d;

                    currentChild._rotation = Math.atan2(b, a) * 180 / Math.PI;
                    var sx = Math.sqrt(a * a + b * b);
                    currentChild._scaleX = a > 0 ? sx : -sx;
                    var sy = Math.sqrt(d * d + c * c);
                    currentChild._scaleY = d > 0 ? sy : -sy;
                    var x = currentChild._x = m.tx;
                    var y = currentChild._y = m.ty;

                    currentChild._currentTransform = m;
                  }

                  if (cmd.hasCxform)
                    currentChild._cxform = cmd.cxform;
                }
              } else {
{'fraction_non_alphanumeric': 0.10850354918151528, 'fraction_numerical': 0.006084311169056932, 'mean_word_length': 1.6664735419080725, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6515573', 'n_tokens_mistral': 3875, 'n_tokens_neox': 3670, 'n_words': 918}