IS condition not working in AS3 (extra site wont let me post) - if-statement

I have a pretty straight forward if statement
var mynum:Number = 0;
var myclip:MovieClip = new thisclass();
addChild(myclip);
in the class file
var i:int = 0;
for (i; i<stage.numChildren; ++i)
{
if (stage.getChildAt(i) is thisclass)
{ trace("true"); }
}
and Im not getting the expected results?
Is there more to the "is" condition?

Solved the issue by using parent instead of stage, not sure why it didn't like stage

Related

loop failing when wrapped in try catch to run few times [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 10 months ago.
Improve this question
Have this code where i am trying to run a loop for few times to make sure i do get my result, but for some reason, i am still getting an error displayed on sreen and it is not even doing the cflog so i can know what is going on, any help will be appreciated
var aData = [];
for (i = 1; i <= 10; i++) {
try {
var a = {};
var as = calltoapitoogetdata;
a['count'] = as;
ArrayAppend(aData, mData);
var retJSON = serializeJSON(aData);
writedump(retJSON);
//return serializeJSON(aData);
break;
} catch (any e) {
i = i + 1;
cflog(text = "Call failed #i#", application = true, file = "loogevent");
writedump(i);
}
}
Thanks
If your code is still erroring it is most likely coming from the cflog call being made in your cfcatch. If you are running a version of Adobe ColdFusion the script version would be :
WriteLog(type="Error", file="myapp.log", text="[#ex.type#] #ex.message#");
https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-t-z/writelog.html
Lucee has made many of the CFScript functions equivalent of their tag names but with Adobe CF there are a number of functions that do not comply with this. <cfdump> -> writeDump for example.
Too long for a comment.
I think troubleshooting is easier if all available information is right in front of you on the screen. So, I would troubleshoot like this. Your code is below with my additions in uppercase:
var aData = [];
for (i = 1; i <= 10; i++) {
try {
WRITEOUTPUT('TRY NUMBER #I# <BR>);
var a = {};
var as = calltoapitoogetdata;
WRITEDUMP(AS);
a['count'] = as;
ArrayAppend(aData, mData);
var retJSON = serializeJSON(aData);
writedump(retJSON);
//return serializeJSON(aData);
break;
} catch (any e) {
i = i + 1; // THIS LINE IS NOT NECESSARY
WRITEOUTPUT('CATCH NUMBER #I# <BR>);
cflog(text = "Call failed #i#", application = true, file = "loogevent"); //THIS LINE GETS REPLACED BY
WRITEDUMP(E);
writedump(i); // THIS LINE GOES AWAY
}
}

Insert list item into a specific Table of google doc

This is the point.
I've followed the suggest linked here More efficient way to append a list item after some text in Google Docs ,whose very helpfull tom me. But i have the problem mentioned at the bottom.
My placeholder is inside a known table within a google doc.
I've tried several ways to figure it out, but i didn't achieve.
Here below there is the portion of code of interest.
Note:
"CarattCentralGas1" is an array of values;
"DescrizioneCentralGas" is another array of values;
My intent is to insert a list, created if the if condition is true, at the placeholder place and than remove it.
Any ideas would be great!`
for (var i=0; i < CarattCentraleGas1.length; ++i)
{ var ValueToTest = CarattCentraleGas1[i][0];
Logger.log(ValueToTest)
if (ValueToTest ==='Presente')
{ var valueToextract = DescrizioniCentraleGas[i][0];
var search = '%Placeholder%';
var Table1 = body.getTables()[0];
var found = Table1.findText(search);
while (found) {
var elem = found.getElement().getParent().getParent();
var index = Table1.getChildIndex(elem);
Table1.insertListItem(index+1, valueToextract+';');
found = Table1.findText(search, found);}
Logger.log(valueToextract)}
}
var Table1Text = Table1.editAsText().replaceText('%CarattCentrale1%',"");
`
this is the template document I want to edit with the script.

Access nth item when iterating Ember object array with for rather than forEach

It made more sense in a particular case today to use a standard for (i = 0.. loop rather than a forEach, but I realised I don't know how to access objects of an Ember Array by number.
So lets say we have:
var order = this.get('order');
var orderItems = order.get('orderItems');
orderItems.forEach(function(orderItem) {
orderItem.set('price', 1000);
});
I thought I could do the equivalent as:
var order = this.get('order');
var orderItems = order.get('orderItems');
for (i = 0; i < orderItems.get('length'); i++) {
orderItems[i].set('price', 1000);
}
but I get orderItems[0] is undefined etc.
How do I access the nth element in an ember array in js?
Ember.js Array provides a objectAt method for accessing the nth element, which you can use for iteration.
Your updated code would look like :
var order = this.get('order');
var orderItems = order.get('orderItems');
for (i = 0; i < orderItems.get('length'); i++) {
orderItems.objectAt(i).set('price', 1000);
}
Check out it's documentation here: http://emberjs.com/api/classes/Ember.Array.html#method_objectAt

if does not work in changing color cell

After testing code below, all steps works except the if statement. Values of cells which are indeed "ik kom niet, mijn partner komt wel" >> but the color doesnot change into red.
Who is able to solve this problem?
function Changecolor (e)
{
var target = SpreadsheetApp.openById("1234");
var target_sheet = target.getSheetByName("lijst beschikbare bridgers");
var rows = target_sheet.getDataRange();
var numRows = rows.getNumRows();
var range = target_sheet.getRange("A1:K100");
range.setBackground('');
for (var i=2; i <= numRows; i++)
{
var value = target_sheet.getRange(i, 4).getValue();
if (value == "ik kom niet, mijn partner komt wel")
{
target_sheet.getRange(i,1).setBackground('red');
}
}
}
Mikeng ths for editing. I will change all my scripts like this.
Problem is solved. Actually there was no problem the script is OK and works. I just gave the wrong range:
var value = target_sheet.getRange(i, 4).getValue();
should be:
var value = target_sheet.getRange(i, 10).getValue();
Such a stupidy costs me at least 3 hours...

having some trouble with regex in as3

I want to extract from a string using regex, why doesn't it work?
From "10:13*12,20:23*22,60:36*432,...", i want to extract 10:13*12 then 20:23*22 and so on. Then, i want to extract from 10:13*12, 10, 13 and 12 and same with 20:23*22.
For example: levelObjs[i] = "10:13*12,20:23*22,60:36*432,..."
var levelObjExp:RegExp = /(.*?),/ig;
var levelObjInfoExp:RegExp = /(\d+):(\d+)*(\d+)/ig;
for(var i:int = 0; i < levelObjs.length; i++) {
if(levelObjs[i] != 0){
var levelObj:Object = levelObjExp.exec(levelObjs[i]);
while (levelObj != null) {
trace (levelObj[1]);
var levelObjInfo:Object = levelObjInfoExp.exec(levelObj[1]);
if (levelObjInfo != null) {
var levelObjNum:int = levelObjInfo[1];
var levelObjX:int = levelObjInfo[2];
var levelObjY:int = levelObjInfo[3];
trace(levelObjNum, levelObjX, levelObjY);
}
levelObj = levelObjExp.exec(levelObjs[i]);
}
}
}
Also, this code needs to be on every frame and it needs to be simple and with using less cpu usage as possible. Does regex uses relatively much cpu usage? Maybe is there a better way to do this without using regex?
Maybe wrong RegExp.
fix following line
var levelObjInfoExp:RegExp = /(\d+):(\d+)*(\d+)/ig;
to
var levelObjInfoExp:RegExp = /(\d+):(\d+)\*(\d+)/i;