GML - Not passing through a part of the code - gml

This is a Trigger Warp code:
if (needEnter) {
if (keyboard_check(vk_enter)) {
audio_play_sound(door_open,0,0);
room_goto(targetRoom);
obj_player.x = targetX;
obj_player.y = targetY;
obj_player.image_index = playerSide
}
else {
if (!instance_exists(obj_msgballoon)) {
balloon = instance_create_layer(obj_player.x, obj_player.bbox_top, "hud", obj_msgballoon);
balloon.balloon_msg = msg_openable_door;
}
playerIsIn = true
}
}
else {
room_goto(targetRoom);
obj_player.x = targetX;
obj_player.y = targetY;
}
The code above triggers the spawn of the obj_msgballoon Instance normally... but something like this doesn't:
if (keyboard_check(vk_enter)) {
if instance_exists(obj_msgballoon) {
if (obj_msgballoon.image_yscale > 1) {
if cooldown < 1 {
instance_destroy(obj_msgballoon)
balloon = instance_create_layer(obj_player.x, obj_player.bbox_top, "hud", obj_msgballoon)
balloon.isTimed = true;
balloon.balloon_msg = msg_locked_door;
cooldown = 15;
}
}
cooldown--;
}
else {
balloon = instance_create_layer(obj_player.x, obj_player.bbox_top, "hud", obj_msgballoon)
balloon.isTimed = true;
balloon.balloon_msg = msg_locked_door;
}
if (!audio_is_playing(locked_door_snd)) {
audio_play_sound(locked_door_snd,0,0);
}
}
Even if I do something like this it does not work:
balloon = instance_create_layer(obj_player.x, obj_player.bbox_top, "hud", obj_msgballoon);
balloon.balloon_msg = msg_openable_door;
I just can't find out the problem... maybe I'm missing something?
Edit: Here it is the code of the obj_msgballoon;
STEP:
if (p) {
sprite_index = ballon_msg;
p = false;
}
if (!isTimed) {
if image_yscale < 1 {
image_yscale += 0.3
}
x = obj_player.x
y = obj_player.bbox_top - 15
} else {
if image_yscale < 1 {
image_yscale += 0.3
}
x = obj_player.x
y = obj_player.bbox_top - 15
if cooldown < 1 {
instance_destroy();
}
cooldown--;
}
CREATE:
image_yscale = 0
p = true;
cooldown = 40;
isTimed = false;
balloon_msg = pointer_null;

Related

TypeError: Cannot read property 'width' of undefined - Nuxt JS and canvas

I am trying to run a sketch on the canvas element in Nuxt JS but I am having some issues (I am completely new to Vue JS).
While I have no errors in VS Code, there is an error in the browser console:
client.js?06a0:84 TypeError: Cannot read property 'width' of undefined
at Blob.get (Blob_Point.js?a5e5:126)
at Blob.render (Blob_Point.js?a5e5:29)
below is the code for my Vue file:
<template>
<div>
<h1 class="pa-5 text-center">Blob</h1>
<canvas id="myCanvas" width="600" height="400"></canvas>
<!--<v-btn #click="drawRect">Clear</v-btn> -->
</div>
</template>
<script>
import Blob from "../assets/content/Blob_Point"
//import { Point } from "../assets/content/Blob_Point"
//import Point from "../assets/content/Blob_Point"
let oldMousePoint = { x: 0, y: 0 }
let blob = new Blob()
//let point = new Point()
let hover = false
let canvas
export default {
data() {
return {
canvas: null,
x: 0,
y: 0,
isDrawing: false,
rectWidth: 200,
//hover: false,
//oldMousePoint: { x: 0, y: 0 },
}
},
mounted() {
let canvas = document.getElementById("myCanvas")
this.canvas = canvas.getContext("2d")
},
created() {
new Blob("#C09EFF")
blob.canvas = canvas
blob.init()
blob.render()
},
methods: {
/* showCoordinates(e) {
this.x = e.offsetX
this.y = e.offsetY
},
drawLine(x1, y1, x2, y2) {
let ctx = this.vueCanvas
ctx.beginPath()
ctx.strokeStyle = "black"
ctx.lineWidth = 1
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
ctx.stroke()
ctx.closePath()
},
draw(e) {
if (this.isDrawing) {
this.drawLine(this.x, this.y, e.offsetX, e.offsetY)
this.x = e.offsetX
this.y = e.offsetY
}
},
beginDrawing(e) {
this.x = e.offsetX
this.y = e.offsetY
this.isDrawing = true
},
stopDrawing(e) {
if (this.isDrawing) {
this.drawLine(this.x, this.y, e.offsetX, e.offsetY)
this.x = 0
this.y = 0
this.isDrawing = false
//windowWidth = 0,
}
}, */
resize() {
document.getElementById("myCanvas").width = window.innerWidth
document.getElementById("myCanvas").height = window.innerHeight
},
/*drawRect() {
this.vueCanvas.clearRect(0, 0, 600, 800)
//this.vueCanvas.beginPath()
//this.vueCanvas.rect(20, 20, this.rectWidth, 100)
//this.vueCanvas.stroke()
},*/
mouseMove(e) {
let pos = blob.center
let diff = { x: e.clientX - pos.x, y: e.clientY - pos.y }
let dist = Math.sqrt(diff.x * diff.x + diff.y * diff.y)
let angle = null
blob.mousePos = {
x: pos.x - e.clientX,
y: pos.y - e.clientY,
}
if (dist < blob.radius && hover === false) {
let vector = {
x: e.clientX - pos.x,
y: e.clientY - pos.y,
}
angle = Math.atan2(vector.y, vector.x)
hover = true
// blob.color = '#77FF00';
} else if (dist > blob.radius && hover === true) {
let vector = {
x: e.clientX - pos.x,
y: e.clientY - pos.y,
}
angle = Math.atan2(vector.y, vector.x)
hover = false
blob.color = null
}
if (typeof angle == "number") {
let nearestPoint = null
let distanceFromPoint = 100
blob.points.forEach((point) => {
if (Math.abs(angle - point.azimuth) < distanceFromPoint) {
// console.log(point.azimuth, angle, distanceFromPoint);
nearestPoint = point
distanceFromPoint = Math.abs(angle - point.azimuth)
}
})
if (nearestPoint) {
let strength = {
x: oldMousePoint.x - e.clientX,
y: oldMousePoint.y - e.clientY,
}
strength =
Math.sqrt(strength.x * strength.x + strength.y * strength.y) * 1
if (strength > 100) strength = 100
nearestPoint.acceleration = (strength / 100) * (hover ? -1 : 1)
}
}
oldMousePoint.x = e.clientX
oldMousePoint.y = e.clientY
},
},
}
</script>
<style scoped>
#myCanvas {
border: 1px solid grey;
}
</style>
and below is the Blob_Point JS file that I am importing:
/* eslint-disable */
// Blob Class
export default class Blob {
// setup function
constructor(color) {
//the objects setup
// 'this' is a reference to the current class
this.points = []
this._color = color
}
init() {
for (let i = 0; i < this.numPoints; i++) {
let point = new Point(this.divisional * (i + 1), this)
//point.acceleration = -1 + Math.random() * 2;
this.push(point)
}
}
render() {
let canvas = this.canvas
let ctx = this.ctx
let position = this.position
let pointsArray = this.points
let radius = this.radius
let points = this.numPoints
let divisional = this.divisional
let center = this.center
ctx.clearRect(0, 0, canvas.width, canvas.height)
pointsArray[0].solveWith(pointsArray[points - 1], pointsArray[1])
let p0 = pointsArray[points - 1].position
let p1 = pointsArray[0].position
let _p2 = p1
// this is the draw
ctx.beginPath()
ctx.moveTo(center.x, center.y)
ctx.moveTo((p0.x + p1.x) / 2, (p0.y + p1.y) / 2)
for (let i = 1; i < points; i++) {
pointsArray[i].solveWith(
pointsArray[i - 1],
pointsArray[i + 1] || pointsArray[0]
)
let p2 = pointsArray[i].position
var xc = (p1.x + p2.x) / 2
var yc = (p1.y + p2.y) / 2
ctx.quadraticCurveTo(p1.x, p1.y, xc, yc)
// ctx.lineTo(p2.x, p2.y);
//ctx.fillStyle = this.color;
// ctx.fillRect(p1.x-2.5, p1.y-2.5, 5, 5);
p1 = p2
}
var xc = (p1.x + _p2.x) / 2
var yc = (p1.y + _p2.y) / 2
ctx.quadraticCurveTo(p1.x, p1.y, xc, yc)
ctx.lineTo(_p2.x, _p2.y)
ctx.closePath()
ctx.fillStyle = this.color
ctx.fill()
ctx.strokeStyle = this.color
// ctx.stroke();
/*
ctx.fillStyle = '#000000';
if(this.mousePos) {
let angle = Math.atan2(this.mousePos.y, this.mousePos.x) + Math.PI;
}*/
//requestAnimationFrame(this.render.bind(this))
}
push(item) {
if (item instanceof Point) {
this.points.push(item)
}
}
set color(value) {
this._color = value
}
get color() {
return this._color
}
set canvas(value) {
if (
value instanceof HTMLElement &&
value.tagName.toLowerCase() === "canvas"
) {
this._canvas = canvas
this.ctx = this._canvas.getContext("2d")
}
}
get canvas() {
return this._canvas
}
set numPoints(value) {
if (value > 10) {
this._points = value
}
}
get numPoints() {
return this._points || 32
}
set radius(value) {
if (value > 0) {
this._radius = value
}
}
get radius() {
return this._radius || 300
}
set position(value) {
if (typeof value == "object" && value.x && value.y) {
this._position = value
}
}
get position() {
return this._position || { x: 0.5, y: 0.5 }
}
get divisional() {
return (Math.PI * 2) / this.numPoints
}
get center() {
return {
x: this.canvas.width * this.position.x,
y: this.canvas.height * this.position.y,
}
}
set running(value) {
this._running = value === true
}
get running() {
return this.running !== false
}
}
// Point Class
export class Point {
constructor(azimuth, parent) {
this.parent = parent
this.azimuth = Math.PI - azimuth
this._components = {
x: Math.cos(this.azimuth),
y: Math.sin(this.azimuth),
}
this.acceleration = -0.3 + Math.random() * 0.6
}
solveWith(leftPoint, rightPoint) {
this.acceleration =
(-0.3 * this.radialEffect +
(leftPoint.radialEffect - this.radialEffect) +
(rightPoint.radialEffect - this.radialEffect)) *
this.elasticity -
this.speed * this.friction
}
set acceleration(value) {
if (typeof value == "number") {
this._acceleration = value
this.speed += this._acceleration * 2
}
}
get acceleration() {
return this._acceleration || 0
}
set speed(value) {
if (typeof value == "number") {
this._speed = value
this.radialEffect += this._speed * 3
}
}
get speed() {
return this._speed || 0
}
set radialEffect(value) {
if (typeof value == "number") {
this._radialEffect = value
}
}
get radialEffect() {
return this._radialEffect || 0
}
get position() {
return {
x:
this.parent.center.x +
this.components.x * (this.parent.radius + this.radialEffect),
y:
this.parent.center.y +
this.components.y * (this.parent.radius + this.radialEffect),
}
}
get components() {
return this._components
}
set elasticity(value) {
if (typeof value === "number") {
this._elasticity = value
}
}
get elasticity() {
return this._elasticity || 0.001
}
set friction(value) {
if (typeof value === "number") {
this._friction = value
}
}
get friction() {
return this._friction || 0.0085
}
}
Any ideas on the why lines 29 and 127 of the Blob_Point.js file are throwing errors?
I attached 2 screens of the developer tools in chrome to show the errors along with the JS its pointing to.
Thanks for any help!
The main issue I can identify is here. I have added comments to the code.
Blob_Point.js
render() {
let canvas = this.canvas // this references the Blob Class (not the Vue instance) and there is no initialised property such as canvas in the class
}
To fix this main issue, you can do something like
Blob_Point.js
export default class Blob {
constructor(color, canvas) {
//the objects setup
// 'this' is a reference to the current class
this.points = []
this._color = color;
this.canvas = canvas
}
}
And then in the .vue file
.Vue
mounted() {
let canvas = document.getElementById("myCanvas");
this.canvas = canvas.getContext("2d");
blob = new Blob("#C09EFF", this.canvas); // now canvas in the Blob Class constructor will refer to the vue instance canvas
blob.canvas = canvas;
blob.init();
blob.render();
},
I have identified another issue here.
set canvas(value) {
if (
value instanceof HTMLElement &&
value.tagName.toLowerCase() === "canvas"
) {
this._canvas = canvas // there is no initialised constructor property as _canvas
this.ctx = this._canvas.getContext("2d") // there is no initialised constructor property such as _canvas
}
}
get canvas() {
return this._canvas // there is no initialised constructor property as _canvas
}

Having issues with moving div

I am trying to create a 300px by 300 px div box that moves with mouse. The only thing is when the visitor click on div it disappear. Any help would be greatly appreciated.
if((document.getElementById) && window.addEventListener ||
window.attachEvent){ (function(){ var hairCol = "#ff0000";
var d = document; var my = -10; var mx = -10; var r; var
vert = "";
var idx = document.getElementsByTagName('div').length;
var thehairs = "<div id='theiframe' scrolling='no'
style='position:absolute;width:53px;height:23px;overflow:hidden;border:0;opacity:"
+ opacity +";filter:alpha(opacity=" + opacity * 100+ ");'>dsdsds"; document.write(thehairs); var like =
document.getElementById("theiframe");
document.getElementsByTagName('body')[0].appendChild(like);
var pix = "px"; var domWw = (typeof window.innerWidth ==
"number"); var domSy = (typeof window.pageYOffset == "number");
if (domWw) r = window; else{ if (d.documentElement &&
typeof d.documentElement.clientWidth == "number" &&
d.documentElement.clientWidth != 0)
r = d.documentElement; else{
if (d.body && typeof d.body.clientWidth == "number")
r = d.body; } }
if(time != 0){ setTimeout(function(){
document.getElementsByTagName('body')[0].removeChild(like);
if (window.addEventListener){
document.removeEventListener("mousemove",mouse,false);
}
else if (window.attachEvent){
document.detachEvent("onmousemove",mouse);
}
}, time); }
function scrl(yx){ var y,x; if (domSy){
y = r.pageYOffset;
x = r.pageXOffset; } else{
y = r.scrollTop;
x = r.scrollLeft; } return (yx == 0) ? y:x; }
function mouse(e){ var msy = (domSy)?window.pageYOffset:0; if
(!e)
e = window.event; if (typeof e.pageY == 'number'){
my = e.pageY - 5 - msy;
mx = e.pageX - 4; } else{
my = e.clientY - 6 - msy;
mx = e.clientX - 6; } vert.top = my + scrl(0) + pix; vert.left = mx + pix; }
function ani(){ vert.top = my + scrl(0) + pix; setTimeout(ani,
300); }
function init(){ vert =
document.getElementById("theiframe").style; ani(); } if
(window.addEventListener){
window.addEventListener("load",init,false);
document.addEventListener("mousemove",mouse,false); } else if
(window.attachEvent){ window.attachEvent("onload",init);
document.attachEvent("onmousemove",mouse); }
})();
}//End.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectForKey:]

My XML response:
{
"S:Envelope" = {
"S:Body" = {
"ns2:getMatchListResponse" = {
item = (
{
answerTime = {
text = 30;
};
challengerAppealsGranted = {
text = "0 of 16";
};
challengerHandle = {
text = manish;
};
challengerMatchesPlayed = {
text = 93;
};
challengerPic = {
text = "image.png";
};
challengerScore = {
text = 0;
};
challengerlosses = {
text = 0;
};
challengerwins = {
text = 4;
};
handle1 = {
text = sahni;
};
handle1AppealsGranted = {
text = 5;
};
handle1MatchesPlayed = {
text = 84;
};
handle1Response = {
text = Pending;
};
handle1Score = {
text = 0;
};
handle1losses = {
text = 0;
};
handle1wins = {
text = 1;
};
handle2MatchesPlayed = {
text = 0;
};
handle2Score = {
text = 0;
};
handle2losses = {
text = 0;
};
handle2wins = {
text = 0;
};
handle3MatchesPlayed = {
text = 0;
};
handle3Score = {
text = 0;
};
handle3losses = {
text = 0;
};
handle3wins = {
text = 0;
};
idMatch = {
text = 750;
};
isAppeal = {
text = false;
};
isFreeForm = {
text = false;
};
isMultichoiceQuestion = {
text = false;
};
isPublic = {
text = false;
};
matchName = {
text = ewtwert;
};
matchStartThresholdTime = {
text = "4 days 7 hrs";
};
matchStatus = {
text = wait;
};
matchType = {
text = Private;
};
noOfPlayers = {
text = 2;
};
priorityInList = {
text = 0;
};
scoreToWin = {
text = 5;
};
timeDuration = {
text = "5 days";
};
turnChangesIn = {
text = 0;
};
},
{
answerTime = {
text = 30;
};
challengerAppealsGranted = {
text = "0 of 16";
};
challengerHandle = {
text = manish;
};
challengerMatchesPlayed = {
text = 93;
};
challengerPic = {
text = "image.png";
};
challengerScore = {
text = 0;
};
challengerlosses = {
text = 0;
};
challengerwins = {
text = 4;
};
handle1MatchesPlayed = {
text = 0;
};
handle1Score = {
text = 0;
};
handle1losses = {
text = 0;
};
handle1wins = {
text = 0;
};
handle2MatchesPlayed = {
text = 0;
};
handle2Score = {
text = 0;
};
handle2losses = {
text = 0;
};
handle2wins = {
text = 0;
};
handle3MatchesPlayed = {
text = 0;
};
handle3Score = {
text = 0;
};
handle3losses = {
text = 0;
};
handle3wins = {
text = 0;
};
idMatch = {
text = 749;
};
isAppeal = {
text = false;
};
isFreeForm = {
text = false;
};
isMultichoiceQuestion = {
text = false;
};
isPublic = {
text = false;
};
matchName = {
text = gfhf;
};
matchStartThresholdTime = {
text = "4 days 6 hrs";
};
matchStatus = {
text = wait;
};
matchType = {
text = Public;
};
noOfPlayers = {
text = 2;
};
priorityInList = {
text = 0;
};
scoreToWin = {
text = 5;
};
timeDuration = {
text = "5 days";
};
turnChangesIn = {
text = 0;
};
}
);
"xmlns:ns2" = "http://services.tgs.com/";
};
};
"xmlns:S" = "http://schemas.xmlsoap.org/soap/envelope/";
};
}
I need value of key "matchStartThresholdTime".
I do:
NSDictionary *dictResult = [XMLReader dictionaryForXMLString:responseString error:nil];
NSDictionary *Enveloper = [dictResult objectForKey:#"S:Envelope"];
NSDictionary *Body = [Enveloper objectForKey:#"S:Body"];
NSDictionary *profileDetails = [Body objectForKey:#"ns2:getMatchListResponse"];
NSMutableArray *items = [profileDetails objectForKey:#"item"];
// NSLog(#"items===>%#",items);
NSDictionary *temp1;
for(temp1 in items)
{
thresholdTime = [NSString stringWithFormat:#"%#",[[temp1 objectForKey:#"matchStartThresholdTime"]objectForKey:#"text"]];...thresholdTime is NSString object.......and this line causes exception
//NSLog(#"time is===>%#",[[temp1 objectForKey:#"matchStartThresholdTime"]objectForKey:#"text"]);
}
What is the problem here?
Temp1 contains an NSString Object and not the NSDictionary, that you expect.
When dealing with JSON it is wise always to (double) check if a received object is really of the type that you expect. Always use
if ([temp1 isKindOfClass:[NSDictionary class]]) ...
or so.

How do you stop a swf from going blank after a user clicks print or cancel print using AS2?

I have an embedded swf that contains a print button which allows users to print some or all pages (AS 2.0) of the swf. The browser's print dialog box opens when the user clicks the print button from the swf. However, after the user clicks print, the swf become blank. This only occurs in IE and FF - works fine in Chrome. Here's the AS2.0 code:
print_btn.onPress = function() {
attachMovie("printbg", "printbg", 5000);
printbg._x = 623;
printbg._y = 360;
attachMovie("printall", "printall", 5001);
printall._x = 621;
printall._y = 316;
attachMovie("printun", "printun", 5002);
printun._x = 622;
printun._y = 342;
attachMovie("printcancel", "printcancel", 5003);
printcancel._x = 622;
printcancel._y = 367;
printcancel.onPress = function() {
removeprint();
};
function removeprint() {
removeMovieClip("printbg");
removeMovieClip("printall");
removeMovieClip("printun");
removeMovieClip("printcancel");
}
printall.onPress = function() {
printallterms();
removeprint();
};
printun.onPress = function() {
printunlearnedterms();
removeprint();
};
};
function printallterms() {
pageno = 0;
toptitle = "<b>"+title+"</b>\nALL\n\n";
attachMovie("printpage_mov", "printall"+pageno, 500);
this["printall"+pageno]._x = 1000;
this["printall"+pageno]._y = 0;
this["printall"+pageno].printtxt.htmlText = toptitle;
for (x=1; x<=20; x++) {
if (this["printall"+pageno].printtxt.textHeight+45>680) {
pageno++;
attachMovie("printpage_mov", "printall"+pageno, 501);
this["printall"+pageno]._x = 1000;
this["printall"+pageno]._y = 0;
this["printall"+pageno].printtxt.htmlText = "";
}
this["printall"+pageno].printtxt.htmlText += "<b>"+term_i[x]+"</b>"+"\n";
this["printall"+pageno].printtxt.htmlText += definition_i[x]+"\n\n";
}
printjobs();
}
function printunlearnedterms() {
pageno = 0;
toptitle = "<b>"+title+"</b>\nREMAINING\n\n";
attachMovie("printpage_mov", "printall"+pageno, this.getNextHighestDepth());
this["printall"+pageno]._x = 1000;
this["printall"+pageno]._y = 0;
this["printall"+pageno].printtxt.htmlText = toptitle;
for (x=1; x<=20; x++) {
if (this["printall"+pageno].printtxt.textHeight+45>680) {
pageno++;
attachMovie("printpage_mov", "printall"+pageno, this.getNextHighestDepth());
this["printall"+pageno]._x = 1000;
this["printall"+pageno]._y = 0;
this["printall"+pageno].printtxt.htmlText = "";
}
if (learned[x] == 0) {
this["printall"+pageno].printtxt.htmlText += "<b>"+term_i[x]+"</b>"+"\n";
this["printall"+pageno].printtxt.htmlText += definition_i[x]+"\n\n";
}
}
printjobs();
}
function printjobs() {
var allprintjob:PrintJob = new PrintJob();
allprintjob.start();
pagesToPrint = 0;
while (pagesToPrint<=pageno) {
allprintjob.addPage(this["printall"+pagesToPrint], {xMin:0, xMax:540, yMin:0, yMax:700});
//trace(this["printall"+pagesToPrint]._height);
removeMovieClip(this["printall"+pagesToPrint]);
pagesToPrint++;
}
if (pagesToPrint>0) {
allprintjob.send();
}
delete allprintjob;
}
Please help!

How to manage depth in AS2

How do I change the movie clip (mainClip) in AS2 code below so that is behind all graphics in the flash file?
Code is below:
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Rectangle;
import flash.geom.Point;
var imageBmp:BitmapData;
//setting the width of blind parts.
var widthB:Number = 40;
//setting the speed of blind parts movement;
var speedChart = 5;
//time to wait lo load another image
var nbSpeedPhoto:Number = 3000;
//Setting the minimum and maximum alpha for controls container and updating timer
var nbACMin:Number = 10;
var nbACMax:Number = 65;
var nbACUpd:Number = 40;
//Setting the minimum and maximum alpha for textField Container
var nbATMin:Number = 0;
var nbATMax:Number = 100;
var nbABMin:Number = 0;
var nbABMax:Number = 65;
//Setting the color for textField Container and font title
var nbATBackColor:Number = 0xD0C8CD;
var nbATFontColor:Number = 0x1F0010;
//Setting the right margin and top margin for controls
var nbRightMC:Number = 2;
var nbTopMC:Number = 2;
//Setting the bottom margin for title and its height
var nbBottomMT:Number = 5;
var nbHeightMT:Number = 50;
//Init Slider viewer
var bbPlay:Boolean = true;
//Setting left to right (1), right to left (2), paralell(3), or random(4) transition
var nbForm:Number = 4;
//if you don't choose parallel, setting the time lag.
var nbLag:Number = 1;
//initial state of FullScreen and AutoPlaying buttons
var bbFull:Boolean = false;
var bbAnimating:Boolean = false;
var bbEnableTitle:Boolean = false;
var bbActiveTitle:Boolean = false;
//setting the first image number to load
var imageNum:Number = 0;
var imageLast:Number;
//initial Photo
var nbPhoto:Number = 0;
//timer variables
var nbTimerNow:Number = 0;
var nbTimerNext:Number = nbSpeedPhoto;
/*********Arrays*******************/
//used for load XML values
var arPhotoPath:Array = new Array();
var arPhotoTitle:Array = new Array();
/**Setting listener to load images**********/
var listener:Object = new Object();
listener.onLoadComplete = function(imageClip:MovieClip):Void {
if (imageNum>0) {
imageBmp = new BitmapData(mainClip["image"+imageLast]._width, mainClip["image"+imageLast]._height);
imageBmp.draw(mainClip["image"+imageLast],new Matrix());
var sqBmp:BitmapData;
var x:Number = 0;
var y:Number = 0;
if (nbForm == 1 || nbForm == 2 || nbForm == 3) {
form = nbForm;
} else {
rnd=Math.random()
if (rnd>0.66) {
form = 1;
} else if (rnd>0.33){
form = 2;
}else{
form = 3;
}
}
for (var j:Number = 0; j<cols; j++) {
x = j*widthB;
if (j>=cols-1) {
var ww = Stage.width-j*widthB;
} else {
var ww = widthB;
}
sqBmp = new BitmapData(ww, mcMask._height);
sqBmp.copyPixels(imageBmp,new Rectangle(x, y, ww, mcMask._height),new Point(0, 0));
cloneClip.createEmptyMovieClip("clone"+imageLast,cloneClip.getNextHighestDepth());
makeSq(sqBmp,j,form);
}
}
unloadMovie(mainClip["image"+imageLast]);
bbAnimating = false;
bbEnableTitle = true;
nbTimerNext = getTimer()+nbSpeedPhoto;
nbOK = 0;
mcText.tfToolTip.text = "Photo "+String(nbPhoto+1)+" of "+String(xmlLength)+": "+arPhotoTitle[nbPhoto];
mcText.tfToolTip.setTextFormat(myformat);
imageNum++;
};
var imageLoader:MovieClipLoader = new MovieClipLoader();
imageLoader.addListener(listener);
/***Creating Squares*******/
function makeSq(sqBmp:BitmapData, jValue:Number, fvalue:Number):Void {
var sqClip:MovieClip = cloneClip["clone"+imageLast].createEmptyMovieClip("sq"+jValue, cloneClip["clone"+imageLast].getNextHighestDepth());
sqClip.attachBitmap(sqBmp,1);
sqClip._x = jValue*widthB;
if (fvalue == 1) {
sqClip.lag = jValue;
} else if(fvalue == 2) {
sqClip.lag = cols-jValue;
}else{
sqClip.lag = 0;
}
sqClip.init = 0;
sqClip.onEnterFrame = function() {
if (this.init>this.lag) {
this._xscale = this._xscale-speedChart;
}
this.init += nbLag;
if (this._yscale<0 || this._xscale<0) {
unloadMovie(this);
}
};
}
//setting the main movieclip and its clone.
//the clone will store the parts of the main image.
this.createEmptyMovieClip("mainClip",this.getNextHighestDepth());
this.createEmptyMovieClip("cloneClip",this.getNextHighestDepth());
this.createEmptyMovieClip("mcMask",this.getNextHighestDepth());
this.createEmptyMovieClip("mcMask2",this.getNextHighestDepth());
//Creating the text container and setting its properties
this.createEmptyMovieClip("mcText",this.getNextHighestDepth());
mcText.createEmptyMovieClip("mcBackText",this.getNextHighestDepth());
makeARectangle(mcText.mcBackText,0,Stage.height-nbBottomMT-nbHeightMT,Stage.width,nbHeightMT,nbATBackColor,100);
mcText.mcBackText._alpha = 0;
//Creating the mc text container
mcText.createTextField("tfToolTip",mcText.getNextHighestDepth(),0,Stage.height-nbBottomMT-nbHeightMT,Stage.width,nbHeightMT);
mcText.tfToolTip._alpha = 0;
//Creating the masks
var bmpMask:BitmapData = new BitmapData(Stage.width, Stage.height, false, 0xCCCCCC);
mcMask.attachBitmap(bmpMask,this.getNextHighestDepth());
mcMask2.attachBitmap(bmpMask,this.getNextHighestDepth());
mainClip.createEmptyMovieClip("image"+imageNum,this.getNextHighestDepth());
//setting the number of columns and files
var cols = Math.ceil(mcMask._width/widthB);
//setting the main and clone masks
mainClip.setMask(mcMask2);
cloneClip.setMask(mcMask);
//setting buttons behaviors
if (bbPlay) {
mcControl.mcPausePlay.gotoAndStop("onPlay");
} else {
mcControl.mcPausePlay.gotoAndStop("onPause");
}
mcControl.mcBackControls.onRollOver = mcControl.mcFull.onRollOver=mcControl.mcLast.onRollOver=mcControl.mcFirst.onRollOver=mcControl.mcPrevious.onRollOver=mcControl.mcPausePlay.onRollOver=mcControl.mcNext.onRollOver=function () {
clearInterval(activeID);
activeID = setInterval(activeControl, nbACUpd, true);
};
mcControl.mcBackControls.onRollOut = mcControl.mcFull.onRollOut=mcControl.mcLast.onRollOut=mcControl.mcFirst.onRollOut=mcControl.mcPrevious.onRollOut=mcControl.mcPausePlay.onRollOut=mcControl.mcNext.onRollOut=function () {
clearInterval(activeID);
activeID = setInterval(activeControl, nbACUpd, false);
};
function activeControl(bb:Boolean) {
if (bb) {
if (mcControl._alpha>=nbACMax) {
clearInterval(activeID);
} else {
mcControl._alpha += 4;
}
} else {
if (mcControl._alpha<nbACMin) {
clearInterval(activeID);
} else {
mcControl._alpha -= 4;
}
}
}
mcControl.mcFull.onRelease = function() {
if (bbFull) {
Stage.displayState = "normal";
this.gotoAndStop("onNormal");
bbFull = false;
} else {
Stage.displayState = "fullScreen";
this.gotoAndStop("onFull");
bbFull = true;
}
};
mcControl.mcPausePlay.onRelease = function() {
if (bbPlay) {
this.gotoAndStop("onPause");
bbPlay = false;
clearInterval(initPhoto);
} else {
if (!bbAnimating) {
this.gotoAndStop("onPlay");
bbPlay = true;
clearInterval(initPhoto);
initPhoto = setInterval(initPlay, 200);
}
}
};
mcControl.mcLast.onRelease = mcControl.mcFirst.onRelease=mcControl.mcPrevious.onRelease=mcControl.mcNext.onRelease=function () {
if (bbAnimating == false) {
clearInterval(initPhoto);
mcControl.mcPausePlay.gotoAndStop("onPause");
bbPlay = false;
mcControl.mcPausePlay.onRelease;
switch (this._name) {
case "mcFirst" :
nbPhoto = 0;
break;
case "mcPrevious" :
nbPhoto = (xmlLength+nbPhoto-1)%xmlLength;
break;
case "mcNext" :
nbPhoto = (nbPhoto+1)%xmlLength;
break;
case "mcLast" :
nbPhoto = xmlLength-1;
break;
default :
break;
}
imageLast = imageNum-1;
mainClip.createEmptyMovieClip("image"+imageNum,mainClip.getNextHighestDepth());
imageLoader.loadClip(arPhotoPath[nbPhoto],mainClip["image"+imageNum]);
bbAnimating == true;
}
};
/********************************/
function makeEnabled(bbEnable:Boolean) {
with (mcControl) {
mcPausePlay.enabled = bbEnable;
mcLast.enabled = bbEnable;
mcFirst.enabled = bbEnable;
mcPrevious.enabled = bbEnable;
mcNext.enabled = bbEnable;
}
}
function makeVisible(bbVisible:Boolean) {
with (mcControl) {
mcPausePlay.enabled = bbVisible;
mcLast.enabled = bbVisible;
mcFirst.enabled = bbVisible;
mcPrevious.enabled = bbVisible;
mcNext.enabled = bbVisible;
}
}
function initPlay() {
if (bbAnimating == false) {
if (bbPlay) {
if (getTimer()>=nbTimerNext) {
nbPhoto = (nbPhoto+1)%xmlLength;
imageLast = imageNum-1;
mainClip.createEmptyMovieClip("image"+imageNum,mainClip.getNextHighestDepth());
imageLoader.loadClip(arPhotoPath[nbPhoto],mainClip["image"+imageNum]);
bbAnimating = true;
nbTimerNext += nbSpeedPhoto;
}
}
}
}
var myformat:TextFormat = new TextFormat();
myformat.font = "myFont";
myformat.color = nbATFontColor;
myformat.size = 18;
mcText.tfToolTip.embedFonts = true;
mcText.tfToolTip.wordWrap = true;
mcText.onRollOver = function() {
if (bbEnableTitle && !bbAnimating) {
alphaTitle(nbATMax,nbABMax);
bbActiveTitle = true;
}
};
mcText.onRollOut = function() {
if (bbEnableTitle) {
alphaTitle(nbATMin,nbABMin);
bbActiveTitle = false;
}
};
function alphaTitle(nbTextAlpha:Number, nbBackAlpha) {
mcText.mcBackText._alpha = nbBackAlpha;
mcText.tfToolTip._alpha = nbTextAlpha;
mcText.tfToolTip.setTextFormat(myformat);
}
//drawing a square
function makeARectangle(mc:MovieClip, x:Number, y:Number, w:Number, h:Number, nbColor:Number, nbAlpha:Number) {
mc.lineStyle(1,nbColor,0);
mc.beginFill(nbColor,nbAlpha);
mc.moveTo(x,y);
mc.lineTo(x+w,y);
mc.lineTo(x+w,y+h);
mc.lineTo(x,y+h);
mc.lineTo(x,y);
mc.endFill();
}
//for loading external XML
var xmlPhotos:XML = new XML();
xmlPhotos.onLoad = function() {
xmlLength = this.firstChild.childNodes.length;
for (var i:Number = 0; i<xmlLength; i++) {
arPhotoPath[i] = (this.firstChild.childNodes[i].attributes.path);
arPhotoTitle[i] = (this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue);
}
imageLoader.loadClip(arPhotoPath[0],mainClip["image"+imageNum]);
bbAnimating = true;
initPhoto = setInterval(initPlay, 200);
};
/****Run XML*****************************************/
xmlPhotos.ignoreWhite = true;
xmlPhotos.load("photos.xml");
mainClip.swapDepths(1);
you need to make sure that all the movieclips are on the same layer on the timeline.