For-loop doesn't compile - actionscript-3

Please help how to fix my for loop , i was a newbie using Adobe Flash .
This is my codes.
for (int i=0;i< nodes.lenght;i++)

There is an error in syntax:
for (var i:int = 0; i < nodes.lenght; i++)
{
}
P.S.: please, pay more attention to formatting of your question and to the correct topic.

Related

Razor component instances created in loop - parameters problem

I would like generate instances of component like these:
for (int i = 0; i < 10; i++)
{
<MyComponent Index="#i">
#i
</MyComponent>
}
Problem is that every component instance has in final view the same value of param Index, and this value is 9. It si probably because this is right variables value when render time. Is it possible to pass right value of "i" variable to components? Thanks very much.
Answer is very simple :-D
for (int i = 0; i < 10; i++)
{
int #iHlp = #i;
<MyComponent Index="#iHlp">
#iHlp
</MyComponent>
}

I have been trying to understand operator precedence but got stuck in this question

I have been trying to understand operator precedence but got stuck in this question.Here is the code:
int i=1;
int a= ++i + ++i + ++i * i++ + i++;
When I calculate using pen and paper, I am getting 26 as the value of a (2+3+4*4+5 => 2+3+16+5 = 26).But when I compile it I am getting 31 as the output.
Could somebody please help me with this.

Prevent Google App Script Memoization

I have a function that I want to use to demonstrate flipping a coin 100 times:
function simulateFlips(n, pHeads){
var head_count = 0;
var H;
for(var i=0; i < n; i++){
H = 0;
if (Math.random() < pHeads){
H = 1;
}
head_count += H;
}
return head_count;
}
However, it looks like the standard Google App Behavior is to "memoize" custom functions that are called with exactly the same inputs, which is not what you want for this kind of demo:
I know I could do something hacky (like modify pHeads by a very small amount), but I was hoping there was some cleaner way to get the desired behavior.
Here's the explanation of this behavior:
Script to summarise data not updating
Read the comments to see suggestions on how to workaround it.
Pass a second param in that you ignore but which is different for each line.

As3 - Get Movieclips That The Name Start With A Specific String

I'm making a tile based game where ta_*(number)* and ca_*(number)* acts like bins. You drag things towards it and drop. But the level may put several these tiles.
I am not going to make something like:
if (my_mc.hitTestObject(ta_0) || my_mc.hitTestObject(ta_1) || my_mc.hitTestObject(ta_2).........)
Because some may not exist and throw an error at me, and I don't want to make like hundreds of them.
Is there a way to find movieclips on stage that start with the name "ta_" and "ca_"?
So that I can get: ta_1, ta_2.....?
No, you can't. Unless you loop on getChildAt() and check all children's names.
But, why don't you add your bins to an array when creating them?
(I assume you create them dynamically)
var myBinArray:Array = new Array(10);
for (var i:int = 0; i < myBinArray.length; i++)
{
var myBin = new Bin();
myBinArray[i] = myBin;
}
Then you simply loop on your array:
for (var i:int = 0; i < myBinArray.length; i++)
{
if (mybinArray[i] != null)
if (my_mc.hitTestObject(mybinArray[i])
{
// statements
// and here I assume you want to break for loop
}
}

Animating a number of lines linking pairs of objects in AS3

I am trying to put together a match activity where word in one column are linked by a line to definitions in another column. Once all words have been linked to their definitions, you end up with a series of crossing lines so, so I want the definitions and their line to move so that each is level with their connected word and the lines have unravelled. I've got as far as connecting the words to their definitions using a line (as a sprite) and the definitions can then be moved using tweenlite -but I have no idea how I move the lines with their definition. Here is a much simplified section of code to give you an idea of what I am trying to do
import com.greensock.*;
import com.greensock.easing.*;
var wordArray:Array = [word1, word2, word3, word4];
var definitionArray:Array = [definition1, definition2, definition3,definition4];
for (var i:int = 0; i < wordArray.length; i++){
var line:Sprite = new Sprite();
line.graphics.lineStyle(2,0x000000);
line.graphics.moveTo(wordArray[i].x, wordArray[i].y);
line.graphics.lineTo(definitionArray[i].x, definitionArray[i].y);
this.addChild(line);
}
for (var j:int = 0; j < wordArray.length; j++){
TweenLite.to(definitionArray[j], 2, {delay:1, y:wordArray[j].y});
}
I am new to this so any help on how I would animate the lines to they follow the definitions would be very much appreciated.
Thanks for the help, it got me started - the errors occur because when onUpdate occurs, TweenLite needs to know the type of the arguments that are passed to the function. What I did was to call to a separate function and use onUpdateParams: to specify the nature of the arguments passed. Here is the code:
TweenLite.to(definitionArray[i], 3, {y:wordArray[j].y,onUpdate:refreshLines,
onUpdateParams:[lines,wordArray,definitionArray]});
with the function
function refreshLines(param1:Array,param2:Array,param3:Array):void{
for (var j:int = 0; j < param4.length; j++){
param1[j].graphics.clear();
}
for (var i:int = 0; i < param4.length; i++)
{
param1[i].graphics.lineStyle(2,0x000000);
param1[i].graphics.moveTo(param2[i].x, param2[i].y);
param1[i].graphics.lineTo(param3[i].x, param3[i].y);
}
}
Once again, many thanks for pointing me in the right direction, it saved me heaps of time.