Skip to content

Instantly share code, notes, and snippets.

@tsak
Last active May 21, 2020 07:16
Show Gist options
  • Save tsak/61bdea5fc21615ff3d99f4293ade6362 to your computer and use it in GitHub Desktop.
Save tsak/61bdea5fc21615ff3d99f4293ade6362 to your computer and use it in GitHub Desktop.
Source of https://draw.tsak.net/viewer.swf. This loads a drawings movements and then replays it.
movie 'viewer.swf' {
// flash 6, total frames: 1, frame rate: 12 fps, 640x480 px, compressed
frame 1 {
function isLoaded(ref) {
if (ref.getBytesLoaded() > 20 && ref.getBytesLoaded() == ref.getBytesTotal()) {
return true;
} else {
return false;
}
}
function getPercentage(lBytes, tBytes) {
if (tBytes > 0) {
return Math.round((lBytes / tBytes) * 100);
} else {
return 0;
}
}
function paint(ref) {
if (_root.thumb == 'true') {
i = 1;
while (i <= _root.myLoadVars.num) {
action = (eval('_root.myLoadVars.i' + i)).split('_');
if (action[0] == 's') {
_root.drawingBoard.paper.lineStyle(action[1], action[2]);
} else {
if (action[0] == 'm') {
_root.drawingBoard.paper.moveTo(action[1], action[2]);
} else {
if (action[0] == 'l') {
_root.drawingBoard.paper.lineTo(action[1], action[2]);
}
}
}
++i;
}
} else {
_root.cLine = 1;
_root.cSteps = Math.round(_root.myLoadVars.num / 200) + 1;
trace(cSteps);
_root.myInt = setInterval(drawNextLine, 0);
}
}
function drawNextLine() {
if (_root.cLine <= _root.myLoadVars.num) {
i = 1;
while (i < _root.cSteps) {
action = (eval('_root.myLoadVars.i' + cLine)).split('_');
if (action[0] == 's') {
_root.drawingBoard.paper.lineStyle(action[1], action[2]);
} else {
if (action[0] == 'm') {
_root.drawingBoard.paper.moveTo(action[1], action[2]);
} else {
if (action[0] == 'l') {
_root.drawingBoard.paper.lineTo(action[1], action[2]);
}
}
}
++_root.cLine;
++i;
}
} else {
clearInterval(_root.myInt);
}
}
function draw(line) {
action = line.split('_');
if (action[0] == 's') {
_root.drawingBoard.paper.lineStyle(action[1], action[2]);
} else {
if (action[0] == 'm') {
_root.drawingBoard.paper.moveTo(action[1], action[2]);
} else {
if (action[0] == 'l') {
_root.drawingBoard.paper.lineTo(action[1], action[2]);
}
}
}
}
painting = new Array();
_root.createEmptyMovieClip('link', 6);
with (link) {
lineStyle(1, 0, 0);
beginFill(0, 0);
moveTo(0, 0);
lineTo(640, 0);
lineTo(640, 480);
lineTo(0, 480);
lineTo(0, 0);
endFill();
}
link.onPress = function () {
getURL(_root.file, '');
};
_root.createEmptyMovieClip('drawingBoard', 1);
with (drawingBoard) {
lineStyle(1, 0, 100);
moveTo(58, 1);
lineTo(639, 1);
lineTo(639, 479);
lineTo(58, 479);
lineTo(58, 1);
createEmptyMovieClip('paperMask', 3);
with (paperMask) {
lineStyle(1, 16777215, 0);
beginFill(16711680);
moveTo(59, 2);
lineTo(639, 2);
lineTo(639, 479);
lineTo(59, 479);
lineTo(59, 2);
}
createEmptyMovieClip('paper', 2);
paper.lineStyle(1, 0, 100);
paper.setMask(paperMask);
}
createEmptyMovieClip('loaderBlock', 5);
with (loaderBlock) {
lineStyle(1, 16777215, 0);
beginFill(16777215, 100);
moveTo(200, 210);
lineTo(500, 210);
lineTo(500, 265);
lineTo(200, 265);
lineTo(200, 210);
}
createTextField('mytext', 4, 58, 210, 592, 55);
with (mytext) {
multiline = false;
wordWrap = false;
border = false;
selectable = false;
text = '';
}
myformat = new TextFormat();
with (myformat) {
color = 0;
bullet = false;
bold = false;
underline = false;
font = 'Arial';
size = 55;
align = 'center';
}
mytext.setTextFormat(myformat);
myLoadVars = new LoadVars();
myLoadVars.load('paintings/' + file + '.txt');
this.onEnterFrame = function () {
if (isLoaded(_root.myLoadVars)) {
mytext.removeTextField();
loaderBlock.removeMovieClip();
_root.paint();
this.onEnterFrame = function () {};
} else {
percent = getPercentage(_root.myLoadVars.getBytesLoaded(), _root.myLoadVars.getBytesTotal());
mytext.text = percent + '%';
loaderBlock._alpha = percent;
mytext.setTextFormat(myformat);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment