How to script an Interval in Photoshop - photoshop

I am trying to script something in Photoshop that has to run every X seconds. In JavaScript it would look like this:
function run() {
    alert('Ran!')
}
setInterval(run, 1000)
 
But in Photoshop's JavaScript, "setInterval is not a function". Any idea how else I would get any form of interval working?

This is by no means a good example, however, it stalls for a second. Those that don't know it there's no pause or sleep function in ECMA 3. I don't use a while loop as that's asking for trouble in Photoshop and may lock things up - which may lose your work.
sleepy(1000)
function sleepy(milliseconds)
{
// Start the fans please! I mean timer
var dStart = new Date().getTime();
var longtime = 10000000;
for(var i = 0 ; i < longtime; i++)
{
var now = new Date().getTime();
if (now > dStart + milliseconds)
{
// Stop the fans!
var dEnd = new Date().getTime();
var timeTaken = (dEnd - dStart)/1000;
var msgTime = (timeTaken + " seconds.");
alert(msgTime);
// alert("Ran");
return;
}
}
}
or if it's just a second, just calculate the Fibbonaci sequence to 28 spots. It's also machine dependant (and rather slower than expected in Photoshop)
function fibonacci(n)
{
if (n < 2)
return n
else
{
return fibonacci(n-1) + fibonacci(n-2);
}
}
var numOfNums = 28; // 0.91 seconds
// var numOfNums = 29; // 1.47 seconds
// var numOfNums = 30; // 2.39 seconds
// var numOfNums = 31; // 3.8 seconds
var dStart = new Date().getTime();
var msg = "";
for(var i = 0 ; i < numOfNums; i++)
{
msg += fibonacci(i) + ", ";
}
var dEnd = new Date().getTime();
var timeTaken = (dEnd - dStart)/1000;
// alert(msg);
alert(timeTaken);

Related

In the beginning, the script worked fine but it's getting slow with time as the number of rows is increasing

In the beginning, the script worked fine but it's getting slow with time as the number of rows is increasing.
Is there a way to optimize it or should I use some other tool?
function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Confidential- 1");
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 4 && activeCell.getRow() > 1){
activeCell.offset(0,1).clearContent().clearDataValidations();
var makes = datass.getRange(1,1,1, datass.getLastColumn()).getValues();
var makeIndex = makes[0].indexOf(activeCell.getValue()) + 1;
if(makeIndex != 0){
var validationRange = datass.getRange(3, makeIndex, datass.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0,1).setDataValidation(validationRule);
}
}
}

how do I change this google app script to hide sheets columns instead of rows based on column dates

so I'm a long way form a competent programmer, but I do dabble in google sheets scripts.
I previously had a script running on a timer trigger to hide rows based on dates found in column A.
function min() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("OLD");
var v = s.getRange("A:A").getValues();
var today = new Date().getTime() - 86400000‬
for (var i = s.getLastRow(); i > 1; i--) {
var t = v[i - 1];
if (t != "") {
var u = new Date(t);
if (u < today) {
s.hideRows(i);
}
}
}
}
function max() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("OLD");
var v = s.getRange("A:A").getValues();
var today = new Date().getTime() + 86400000
for (var i = s.getLastRow(); i > 1; i--) {
var t = v[i - 1];
if (t != "") {
var u = new Date(t);
if (u > today) {
s.hideRows(i);
}
}
}
}
function SHOWROWS() {
// set up spreadsheet and sheet
var ss = SpreadsheetApp.getActiveSpreadsheet(), sheets = ss.getSheets();
for(var i = 0, iLen = sheets.length; i < iLen; i++) {
// get sheet
var sh = sheets[i];
// unhide rows
var rRows = sh.getRange("A:A");
sh.unhideRow(rRows);
}
}
this would be set to run at midnight every night so as to hide all rows not +-1 day from the current date.
I have now switched to using this document primarily through the android app I need to swap the input layout Moving dates from rows and values in columns to the inverse, values are now in rows and the dates are in columns, inputing vertical values would be much quicker....but honestly its more about understanding what im doing wrong thats really motivating my search for a answer.
can anyone help me modify my old script to work on this changed sheet.
my attempts fall flat..eg:
function min() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("OLD");
var v = s.getRange("1:1").getValues();
var today = new Date().getTime() - 86400000‬
for (var i = s.getLastColumn(); i > 1; i--) {
var t = v[i - 1];
if (t != "") {
var u = new Date(t);
if (u < today) {
s.hidecolumns(i);
}
}
}
}
example spreadsheet:
https://docs.google.com/spreadsheets/d/1EjRIeDPrG_qp1S9QhInl9r3G0cZx_16OvnTXORgA3n4/edit?usp=sharing
there is two sheets one with the old version of my layout called "OLD" and my new desired layout called "NEW"
thanks in advance to anyone able to help
This function hides a column whose top row date is less yesterday.
function hideColumnWhenTopRowDateIsBeforeYesterday() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var sh=ss.getSheetByName("Sheet1");
var rg=sh.getRange(1,1,1,sh.getLastColumn());
var vA=rg.getValues()[0];
var yesterday=new Date(new Date().getFullYear(),new Date().getMonth(),new Date().getDate()-1).valueOf();
vA.forEach(function(e,i){
if(new Date(e).valueOf()<yesterday) {
sh.hideColumns(i+1);
}
});
}
My Spreadsheet before hiding columns:
My Spreadsheet after hiding columns:

Set map borders to not cross inside the view area

I am trying to translate an old flash animation with animate. On the original flash animation the map image is draggable and zoomable but the map ´s borders always stick to the sides of the stage if you pan it or zoom it all the way.
On my test i grabbed some code that allows panning and zooming but the map crosses the stage boundaries if you pan all the way, in fact you can make the map dissapear of the stage.
I think there should be a way to draw like a secondary outer stage and not let the map image go beyond it.
This is the code I have.
var that = this;
var clickedX;
var clickedY;
var isDragging = false;
var friction = 0.85;
var speedX = 0;
var speedY = 0;
var mapOriginalX = this.map.x;
var mapOriginalY = this.map.y;
var mapNudge = 5;
var minScale = 0.25;
var maxScale = 3;
function onMouseWheel(e)
{
var delta;
if (e == window.event)
delta = -10 / window.event.wheelDeltaY;
else
delta = e.detail / 30;
var zoomFactor = delta;
scaleMap(zoomFactor);
}
function mouseDown(e)
{
clickedX = stage.mouseX;
clickedY = stage.mouseY;
isDragging = true;
console.log(stage.mouseX);
console.log(stage.mouseY);
}
function stageMouseUp(e)
{
isDragging = false;
}
function update(e)
{
if (isDragging)
{
speedX = stage.mouseX - clickedX;
speedY = stage.mouseY - clickedY;
}
speedX *= friction;
speedY *= friction;
// saber el tamaño actual del mapa en este punto.
that.map.x += speedX;
that.map.y += speedY;
console.log(that.map.y);
console.log(that.map.x);
clickedX = stage.mouseX;
clickedY = stage.mouseY;
//
}
function resetMap()
{
that.map.x = mapOriginalX;
that.map.y = mapOriginalY;
that.map.scaleX = that.map.scaleY = 1;
}
function zoomMap(e) //control visual
{
if (e.currentTarget == that.plusButton)
scaleMap(-0.1);
if (e.currentTarget == that.minusButton)
scaleMap(0.1);
}
function moveMap(e) //control visual
{
if (e.currentTarget == that.upButton)
speedY -= mapNudge;
else if (e.currentTarget == that.rightButton)
speedX += mapNudge;
else if (e.currentTarget == that.downButton)
speedY += mapNudge;
else if (e.currentTarget == that.leftButton)
speedX -= mapNudge;
}
function scaleMap(amount)
{
var map = that.map; // we will scale de map so this goes first.
map.scaleX -= amount; // same as map.scaleX = map.scaleX - amount
map.scaleY = map.scaleX;
if (map.scaleX < minScale)
map.scaleX = map.scaleY = minScale;
else if (map.scaleX > maxScale)
map.scaleX = map.scaleY = maxScale;
}
// listeners
this.map.on("mousedown", mouseDown.bind(this));
this.resetButton.on("click", resetMap.bind(this));
this.plusButton.on("click", zoomMap.bind(this));
this.minusButton.on("click", zoomMap.bind(this));
this.upButton.on("click", moveMap.bind(this));
this.rightButton.on("click", moveMap.bind(this));
this.downButton.on("click", moveMap.bind(this));
this.leftButton.on("click", moveMap.bind(this));
stage.on("stagemouseup", stageMouseUp.bind(this));
document.getElementById('canvas').addEventListener('mousewheel', onMouseWheel.bind(this));
document.getElementById('canvas').addEventListener('DOMMouseScroll', onMouseWheel.bind(this));
createjs.Ticker.addEventListener("tick", update.bind(this));
resetMap();
One trick I usually use is to create a "fence" procedure that checks bounds and corrects them. It will take some setup though.
To use this method, first set up these variables based on your own scene. Perhaps this is what you meant by defining a "second stage?"
var stageLeft = 0;
var stageRight = 500;
var stageTop = 0;
var stageBottom = 500;
this.map.setBounds(0,0,1462, 1047); // Set the values to match your map
var mapBounds = this.map.getBounds();
Then, add this procedure, or a variation of it based on how your map coordinates are set.
// procedure to correct the map x/y to fit the stage
function fenceMap() {
var map = that.map;
var ptTopLeft = map.localToGlobal(mapBounds.x,mapBounds.y);
var ptBotRight = map.localToGlobal(mapBounds.width,mapBounds.height);
if ((ptBotRight.x - ptTopLeft.x) > (stageRight-stageLeft)) {
if (ptTopLeft.x > stageLeft) {
map.x -= ptTopLeft.x - stageLeft;
speedX = 0;
} else if (ptBotRight.x < stageRight) {
map.x -= ptBotRight.x - stageRight;
speedX = 0;
}
}
if ((ptBotRight.y - ptTopLeft.y) > (stageBottom-stageTop)) {
if (ptTopLeft.y > stageTop) {
map.y -= ptTopLeft.y - stageTop;
speedY = 0;
} else if (ptBotRight.y < stageBottom) {
map.y -= ptBotRight.y - stageBottom;
speedY = 0;
}
}
}
Then, just add to the end of your update(), zoomMap(), moveMap(), and scaleMap() functions:
fenceMap();

Label Printing using iTextSharp

I have a logic to export avery label pdf. The logic exports the pdf with labels properly but when i print that pdf, the page size measurements (Page properties) that i pass isn't matching with the printed page.
Page Properties
Width="48.5" Height="25.4" HorizontalGapWidth="0" VerticalGapHeight="0" PageMarginTop="21" PageMarginBottom="21" PageMarginLeft="8" PageMarginRight="8" PageSize="A4" LabelsPerRow="4" LabelRowsPerPage="10"
The above property values are converted equivalent to point values first before applied.
Convert to point
private float mmToPoint(double mm)
{
return (float)((mm / 25.4) * 72);
}
Logic
public Stream SecLabelType(LabelProp _label)
{
List<LabelModelClass> Model = new List<LabelModelClass>();
Model = RetModel(_label);
bool IncludeLabelBorders = false;
FontFactory.RegisterDirectories();
Rectangle pageSize;
switch (_label.PageSize)
{
case "A4":
pageSize = iTextSharp.text.PageSize.A4;
break;
default:
pageSize = iTextSharp.text.PageSize.A4;
break;
}
var doc = new Document(pageSize,
_label.PageMarginLeft,
_label.PageMarginRight,
_label.PageMarginTop,
_label.PageMarginBottom);
var output = new MemoryStream();
var writer = PdfWriter.GetInstance(doc, output);
writer.CloseStream = false;
doc.Open();
var numOfCols = _label.LabelsPerRow + (_label.LabelsPerRow - 1);
var tbl = new PdfPTable(numOfCols);
var colWidths = new List<float>();
for (int i = 1; i <= numOfCols; i++)
{
if (i % 2 > 0)
{
colWidths.Add(_label.Width);
}
else
{
colWidths.Add(_label.HorizontalGapWidth);
}
}
var w = iTextSharp.text.PageSize.A4.Width - (doc.LeftMargin + doc.RightMargin);
var h = iTextSharp.text.PageSize.A4.Height - (doc.TopMargin + doc.BottomMargin);
var size = new iTextSharp.text.Rectangle(w, h);
tbl.SetWidthPercentage(colWidths.ToArray(), size);
//var val = System.IO.File.ReadLines("C:\\Users\\lenovo\\Desktop\\test stock\\testing3.txt").ToArray();
//var ItemNoArr = Model.Select(ds => ds.ItemNo).ToArray();
//string Header = Model.Select(ds => ds.Header).FirstOrDefault();
int cnt = 0;
bool b = false;
int iAddRows = 1;
for (int iRow = 0; iRow < ((Model.Count() / _label.LabelsPerRow) + iAddRows); iRow++)
{
var rowCells = new List<PdfPCell>();
for (int iCol = 1; iCol <= numOfCols; iCol++)
{
if (Model.Count() > cnt)
{
if (iCol % 2 > 0)
{
var cellContent = new Phrase();
if (((iRow + 1) >= _label.StartRow && (iCol) >= (_label.StartColumn + (_label.StartColumn - 1))) || b)
{
b = true;
try
{
var StrArr = _label.SpineLblFormat.Split('|');
foreach (var x in StrArr)
{
string Value = "";
if (x.Contains(","))
{
var StrCommaArr = x.Split(',');
foreach (var y in StrCommaArr)
{
if (y != "")
{
Value = ChunckText(cnt, Model, y, Value);
}
}
if (Value != null && Value.Replace(" ", "") != "")
{
cellContent.Add(new Paragraph(Value));
cellContent.Add(new Paragraph("\n"));
}
}
else
{
Value = ChunckText(cnt, Model, x, Value);
if (Value != null && Value.Replace(" ", "") != "")
{
cellContent.Add(new Paragraph(Value));
cellContent.Add(new Paragraph("\n"));
}
}
}
}
catch (Exception e)
{
var fontHeader1 = FontFactory.GetFont("Verdana", BaseFont.CP1250, true, 6, 0);
cellContent.Add(new Chunk("NA", fontHeader1));
}
cnt += 1;
}
else
iAddRows += 1;
var cell = new PdfPCell(cellContent);
cell.FixedHeight = _label.Height;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
cell.Border = IncludeLabelBorders ? Rectangle.BOX : Rectangle.NO_BORDER;
rowCells.Add(cell);
}
else
{
var gapCell = new PdfPCell();
gapCell.FixedHeight = _label.Height;
gapCell.Border = Rectangle.NO_BORDER;
rowCells.Add(gapCell);
}
}
else
{
var gapCell = new PdfPCell();
gapCell.FixedHeight = _label.Height;
gapCell.Border = Rectangle.NO_BORDER;
rowCells.Add(gapCell);
}
}
tbl.Rows.Add(new PdfPRow(rowCells.ToArray()));
_label.LabelRowsPerPage = _label.LabelRowsPerPage == null ? 0 : _label.LabelRowsPerPage;
if ((iRow + 1) < _label.LabelRowsPerPage && _label.VerticalGapHeight > 0)
{
tbl.Rows.Add(CreateGapRow(numOfCols, _label));
}
}
doc.Add(tbl);
doc.Close();
output.Position = 0;
return output;
}
private PdfPRow CreateGapRow(int numOfCols, LabelProp _label)
{
var cells = new List<PdfPCell>();
for (int i = 0; i < numOfCols; i++)
{
var cell = new PdfPCell();
cell.FixedHeight = _label.VerticalGapHeight;
cell.Border = Rectangle.NO_BORDER;
cells.Add(cell);
}
return new PdfPRow(cells.ToArray());
}
A PDF document may have very accurate measurements, but then those measurements get screwed up because the page is scaled during the printing process. That is a common problem: different printers will use different scaling factors with different results when you print the document using different printers.
How to avoid this?
In the print dialog of Adobe Reader, you can choose how the printer should behave:
By default, the printer will try to "Fit" the content on the page, but as not every printer can physically use the full page size (due to hardware limitations), there's a high chance the printer will scale the page down if you use "Fit".
It's better to choose the option "Actual size". The downside of using this option is that some content may get lost because it's too close to the border of the page in an area that physically can't be reached by the printer, but the advantage is that the measurements will be preserved.
You can set this option programmatically in your document by telling the document it shouldn't scale:
writer.AddViewerPreference(PdfName.PRINTSCALING, PdfName.NONE);
See How to set initial view properties? for more info about viewer preferences.

Reducing score in relation to countdown timer

I have a quiz written in actionscript 2. Everything is going swimmingly except that I can't figure out how to get the score to reduce by one point for every second it takes to answer the question.
So... max score is 30 points for each question and there is a 30 sec timer... and so that the quiz is more challenging I'd like it to reduce by 1 point for every second it takes to answer.
Here is my code... and thanks in advance...
Answer0Button.enabled=false; button0._visible=false;
Answer1Button.enabled=false; button1._visible=false;
Answer2Button.enabled=false; button2._visible=false;
Answer3Button.enabled=false; button3._visible=false;
Answer4Button.enabled=false; button4._visible=false;
Answer5Button.enabled=false; button5._visible=false;
function countdown() {
counter--;
countdown_txt.text = counter;
if (counter == 0) {
Answer0Button.enabled=false;
Answer1Button.enabled=false;
Answer2Button.enabled=false;
Answer3Button.enabled=false;
Answer4Button.enabled=false;
Answer5Button.enabled=false;
clearInterval(intID);
AnswerPopUp_mc.gotoAndPlay(1);
AnswerPopUp_mc.AnswerPopUp.DisplayResult.htmlText = "" + TimeIsUp + "";
}
}
// defining variables for data
var ChosenNumberOfQuestions = int(0); // Number of questions in quiz
var TotalNumberOfQuestions = int(0); // Total number of questions in XML file
var NumberOfQuestions = int(0); // min of two above
var QuestionCounter = int(0); // for dynamicaly showing questions
var CurrentQuestion = QuestionCounter + 1; // for dynamicaly showing questions
var Points = 0; // for each question
var TotalPoints = 0; // Max Points
var Score = 0; // display total score
var NumberOfCorrectAnswers = 0; // counter for questions answered correctly
var RandOrderQuestions = new Array();
var Questions = new Array();
var Images = new Array();
var CorrectAnswers = new Array();
var Answers = new Array();
var ExplanationsIfCorrect = new Array();
var ExplanationsIfNotCorrect = new Array();
var TimesForSolving = new Array();
var NumberOfPoints = new Array();
// roll over states for buttons
button0.onEnterFrame = function() {
if (mouse_over_button0) {
_root.button0.nextFrame();
} else {
_root.button0.prevFrame();
}
};
button1.onEnterFrame = function() {
if (mouse_over_button1) {
_root.button1.nextFrame();
} else {
_root.button1.prevFrame();
}
};
button2.onEnterFrame = function() {
if (mouse_over_button2) {
_root.button2.nextFrame();
} else {
_root.button2.prevFrame();
}
};
button3.onEnterFrame = function() {
if (mouse_over_button3) {
_root.button3.nextFrame();
} else {
_root.button3.prevFrame();
}
};
button4.onEnterFrame = function() {
if (mouse_over_button4) {
_root.button4.nextFrame();
} else {
_root.button4.prevFrame();
}
};
button5.onEnterFrame = function() {
if (mouse_over_button5) {
_root.button5.nextFrame();
} else {
_root.button5.prevFrame();
}
};
// Label Color
var changeColor2 = new Color(label_mc.coloredLabel);
changeColor2.setRGB(labelColor);
// Change Buttons Color
var changeColorA = new Color(button0.letterA_mc.letterA);
changeColorA.setRGB(labelColor);
var changeColorB = new Color(button1.letterB_mc.letterB);
changeColorB.setRGB(labelColor);
var changeColorC = new Color(button2.letterC_mc.letterC);
changeColorC.setRGB(labelColor);
var changeColorD = new Color(button3.letterD_mc.letterD);
changeColorD.setRGB(labelColor);
var changeColorE = new Color(button4.letterE_mc.letterE);
changeColorE.setRGB(labelColor);
var changeColorF = new Color(button5.letterF_mc.letterF);
changeColorF.setRGB(labelColor);
// Change Color of points, counter...
var changeColorCounter = new Color(countdown_txt);
changeColorCounter.setRGB(labelColor);
var changeSlashColor = new Color(slash);
changeSlashColor.setRGB(labelColor);
var changeCurrQColor = new Color(DisplayCurrQ);
changeCurrQColor.setRGB(labelColor);
var changeTotalQColor = new Color(DisplayTotalQ);
changeTotalQColor.setRGB(labelColor);
var changePointsColor = new Color(DisplayPoints);
changePointsColor.setRGB(labelColor);
var changeScoreColor = new Color(DisplayScore);
changeScoreColor.setRGB(labelColor);
// Background Color
new Color (BackGround.bg).setRGB(BackgroundColor);
new Color (FadeIn.bg1.bg).setRGB(BackgroundColor);
// loading data from XML
var xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = function () {
// Default Time for solving
DefaultTimeInSeconds = this.firstChild.attributes.DefaultTimeInSeconds;
trace ("DefaultTime: " + DefaultTimeInSeconds);
// Default Points
DefaultPoints = this.firstChild.attributes.DefaultPoints;
trace ("DefaultPoints: " + DefaultPoints);
// Default comment on answers
DefaultIfCorrectAnswer = this.firstChild.attributes.DefaultIfCorrectAnswer;
DefaultIfWrongAnswer = this.firstChild.attributes.DefaultIfWrongAnswer;
// Default if time is up
TimeIsUp = this.firstChild.attributes.TimeIsUp;
// Random order of questions or not
RandomQuestions = this.firstChild.attributes.RandomQuestions;
trace ("RandomQuestions: " + RandomQuestions);
// Number Of Questions
ChosenNumberOfQuestions = this.firstChild.attributes.NumberOfQuestions;
trace ("ChosenNumberOfQuestions: " + ChosenNumberOfQuestions);
// Counting total number of Questions in XML file
var nodes = this.firstChild.childNodes;
for (var a=0; a<nodes.length; a++){
TotalNumberOfQuestions = a+1;
}
trace ("TotalNumberOfQuestions: " + TotalNumberOfQuestions);
// Finaly - number of questions in QUIZ - min of two above
if (ChosenNumberOfQuestions < TotalNumberOfQuestions) {
NumberOfQuestions = ChosenNumberOfQuestions;
} else {
NumberOfQuestions = TotalNumberOfQuestions;
}
// Random order Questions or not
// first we populate array with question numbers
for(i=0; i<TotalNumberOfQuestions; i++){
RandOrderQuestions[i] = i;
trace(RandOrderQuestions);
}
// if we want random questions we use random sorting of number of questions
if (RandomQuestions == "TRUE") {
RandOrderQuestions.sort(function () {
return random(2) ? true : false;
});
trace(RandOrderQuestions);
}
///////////////////////////
// POPULATING FROM XML
for (var i=0; i < NumberOfQuestions; i++ )
{
// Chose the number of question from RandOrderQuestions array
var numInXML = RandOrderQuestions[i];
trace("Question number in XML: " + numInXML);
// populating questions from XML
Questions[i] = this.firstChild.childNodes[numInXML].childNodes[0].firstChild.nodeValue;
//trace(Questions);
//populating Correct Answers from XML
CorrectAnswers[i] = this.firstChild.childNodes[numInXML].childNodes[1].attributes.correctAnswer;
//trace(CorrectAnswers);
// populating options for answers from XML
var NewArray = new Array(); // temp array for answers for each question
for (var j=0; j < this.firstChild.childNodes[numInXML].childNodes[1].childNodes.length; j++ )
{
trace(i + " "+ j);
NewArray[j] = this.firstChild.childNodes[numInXML].childNodes[1].childNodes[j].firstChild.nodeValue;
//trace(NewArray);
NewArray.sort(function () {
return random(2) ? true : false;
});
}
Answers.push(NewArray); // push answers for this i question in main Answers array
//populating additional options from XML
ExplanationsIfCorrect[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.explanationIfCorrect;
ExplanationsIfNotCorrect[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.explanationIfNotCorrect;
TimesForSolving[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.timeInSeconds;
NumberOfPoints[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.points;
Images[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.imageIfCorrect;
Images[i] = this.firstChild.childNodes[numInXML].childNodes[2].attributes.imageIfIncorrect;
}
trace("Questions: " + Questions); trace("Correct Answers: " + CorrectAnswers);
trace(NewArray);
trace(ExplanationsIfCorrect); trace(ExplanationsIfNotCorrect); trace(TimesForSolving); trace(NumberOfPoints); trace(Images);
// show first question (QuestionCounter=0)
QuestionNumber.text = "Question #" + 1;
QuestionDisplay.htmlText = Questions[QuestionCounter];
// show answers for first question (QuestionCounter=0)
if (0 < Answers[QuestionCounter].length){ Answer0Display.text = Answers[QuestionCounter][0]; Answer0Button.enabled=true; button0._visible=true;} else { button0._visible=false;}
if (1 < Answers[QuestionCounter].length){ Answer1Display.text = Answers[QuestionCounter][1]; Answer1Button.enabled=true; button1._visible=true;} else { button1._visible=false;}
if (2 < Answers[QuestionCounter].length){ Answer2Display.text = Answers[QuestionCounter][2]; Answer2Button.enabled=true; button2._visible=true;} else { button2._visible=false;}
if (3 < Answers[QuestionCounter].length){ Answer3Display.text = Answers[QuestionCounter][3]; Answer3Button.enabled=true; button3._visible=true;} else { button3._visible=false;}
if (4 < Answers[QuestionCounter].length){ Answer4Display.text = Answers[QuestionCounter][4]; Answer4Button.enabled=true; button4._visible=true;} else { button4._visible=false;}
if (5 < Answers[QuestionCounter].length){ Answer5Display.text = Answers[QuestionCounter][5]; Answer5Button.enabled=true; button5._visible=true;} else { button5._visible=false;}
// show image if defined
if (Images[QuestionCounter]){ loadMovie(Images[QuestionCounter],"imgContainer"); } else { }
// determine the number of points
if (NumberOfPoints[QuestionCounter]){ Points = NumberOfPoints[QuestionCounter] } else { Points = DefaultPoints }
// start counter
if (TimesForSolving[QuestionCounter]){
countdown_time = TimesForSolving[QuestionCounter]
} else {
countdown_time = DefaultTimeInSeconds
} // now call the function
counter = countdown_time;
countdown_txt.text = countdown_time;
clearInterval(intID);
intID = setInterval(countdown,1000);
}
I don't see where you added your scores, but I believe you can set score = counter since your counter is the time remaining.