ActionScript 3.0 :: Howto Loop Through Object
Sep 7, 2008how do loop through an object in as3, to get its keys/properties? [code]what would be the equivalent in the modern times ?
View 8 Replieshow do loop through an object in as3, to get its keys/properties? [code]what would be the equivalent in the modern times ?
View 8 Repliesbeen busy on a project (temp: [URL].. where I load in data from a mysql-db in textfields.however when I put this in the db
line 1
line 2
Flash outputs this:
line 1
line 2
with an empty line in between. How can I control this ?
verytime I reach the next level I get this error: TypeError: Error #1009: Cannot access a property or method of a null object reference.at Game_fla::MainTimeline/movecircle()I also want the timer to stop counting when I die or finnish.
I've tried
Code:
if (platforms.currentFrame == platforms.totalFrames -1)
[code].....
I'm now using for..in and for each..in almost exclusively with looping Objects. I love it. But how can I loop an Object backwards?
i.e. - with an array I might do something like this:
for (var i:uint = arr.length; i-- > 0; ) {
Queston #2 - I've found the ordering of for...in to be quite predictable but am seeing some blog posting that say otherwise (thats AS2 was extremely predictable but AS3 is not). Which is it?
I want to go through an object, recursively. I've got that part down sort of. I want to list out ALL the values in the object. I can do that. But what I can't seem to do is to get the name of the actual property.It has to be something obvious but I'm clueless. I've searched this page, and I'm positive I'm just overlooking something obvious.
Code:
function recursiveList(obj:Object){
if(!obj){
[code]....
I have 8 text boxes (called h1, h2 etc) that I want to do things with, the code below is just to make them all invisible when the movie loads,this works:
for (b=1; b<9; b++) {
_root["h"+b]._visible = false;
}
[code]....
This may look like a long post but you may not have to read throught the whole thing... I have created a textfield within a loop and put it in a sprite called textHolder. I loaded images in the same loop and put them in a container called imageHolder. The containers are assigned to the buttons button created by the loop. This works all great. But the thing that I am having trouble with is being able to tweenMax one of the holders. for example:
I have a tweenMax that scales b1 (the first buttons created from the loop) by 3x. But I also need the text to fade out without the image fading out. So I tried just putting a tween on textHolder but nothin' happens! Maybe there is some rule here that I am missing that says I cant do that? If not, I dont know what I am doing wrong. here is some of my code:
[Code]....
Here's a piece of script I would like to condense into a single loop where the number of instances created would be dynamic:
Actionscript Code:
//create instances of Door objectvar door_1:Door = new Door();var door_2:Door = new Door();var door_3:Door = new Door();var door_4:Door = new Door();var door_5:Door = new
[code]....
i am creating a certain amount of instances of a class-object (called Jaar).When i click on one of them, I would like to change a value (isSelected) in all the instances of this class.How can i do this?So far i have this (simplified version) :
ActionScript Code:
package{
import flash.display.*;
[code].....
can I mask multiple object through a loop
should be the question
ActionScript Code:
for (var m = 0; m < mylooper; m++ ) {
MovieClip(holdbox.getChildByName("mytxt" + [m] )).mask = mymask
}
it seems to only mask the last object not all of them
I'm experiencing a strange behaviour in a for-in loop, has someone ever seen this before? >> I have an Object-variable _files, which contains 3 seperate class instances of the wsaxSingleFileUploader class (which, as you can imagine, is a class to upload files ) My code for removing these instances:
[Code].....
So, in the first line of code, it traces all keys within the object. Then in a similar loop, it triggers all the remove() functions of the instances, and then sets the instance to null. Strangely, as you can see in bold in the trace-results below, it tries pdf_hl twice? Does anybody have any clue why that is? The problem occurs in FireFox with Firebug/Flashbug and the Flash 10.2 debugger plugin.
[Code].....
How can I load sounds using a loop? As there are around 20 sound files named something like s1.mp3, s2.mp3......sn.mp3
We can load sounds and create dynamic sound object in AS2 something like this:
ActionScript Code:
for(n=1;n<=20;n++){
_root["s"+n]=new Sound();
_root["s"+n].loadSound("s"+n+".mp3");
}
Is there anyway in AS3 to create dynamic sound objects?
I've got a question about scrolling. I would like to scroll a 100x100 mc in the y-direction (going up). I would like to scroll the same mc many times in an infinite loop. How can I scroll this mc infinitely, repeating every 40 pixels...when the _root timeline is loaded?
View 1 RepliesI'm building a web flash 8 app with an animated nurse that talks and help the user in different events. the voices sit in a external folder and i load them using load sound method. It works fine as a desktop app, but when testing the movie on slow download (DSL 32 KB/s) I realized that i must load all the sound before i can play the animation.
problem nr.1: How do i create folowing sound objects (voice_0, voice_1, voice_2..) using a loop?
I've tried this, but it doesn't work
for (i=0;i<numVoices;i++)
{
var this["voice_"+i]:Sound=new Sound;
}
[Code]....
why does this not working?
for (i=0; i<=numVoices; i++) {
var this["voice"+i]:Sound= new Sound();
}
[code]......
I'v been toying with this for a few weeks now and I'm trying to find the best way to animate several instances of an object created by a for loop thru an ENTER_FRAME function.When the function runs only 1 of the 3 instances that were created animates.
var balloonArray:Array = new Array();var balloon: hotAirBalloon;var xVel: Number = -3;var yVel: Number = -4;
addEventListener(Event.ENTER_FRAME, startBalloons)
[code]....
what is the problem of this code:
package{
import flash.display.*;
import flash.events.*;
import flash.net.*;
[Code].....
I want to store the bitmap data from _sampleTile in array, but I was wondering how to increase the performance. If I do it like this:
var _sampleTile:BitmapData;
var _arrayLenght:int = _tileClipArray.length;
for(var i:int = 0; i < _arrayLenght; ++i){
[code].....
I want to remove an object that is created in a loop, with a timer.
var timer:Timer = new Timer(2000);
timer.addEventListener(TimerEvent.TIMER, voegtoe);
In function voegtoe I'm adding an Movieclip Object called man:
man.x=Math.random()*650;
man.y=Math.floor(Math.random()*(70))+350;
addChild(man);
I want to remove this object after 2 seconds. The problem is that there are multiple 'man' objects.
Is there a way i can Loop through the attributes of a strongly typed Object or just convert a strongly typed Object into a generic Object.I tried typecasting a Strongly typed object created using LCDS into a Object.But it just returned me a typed Object.
View 1 RepliesJust curious, if you want to loop through an array or object that is less processor intensive.[code]...
View 4 RepliesIn a movie a have a sound object, that i make it through (for example)
Code:
musica = new Sound();
musica.attachSound("fondo");
I have many other sounds in the movie but this object is for a loop... The problem is that when I set the volume for that object, through:
Code:
_root.musica.setVolume(0);
Or whatever value, all the other sounds are set to that volume too. I just want to mute the loop but also the buttons sounds are muted...
i'm working on a gallery that loads thumbnails from an xml file into 3 columns and when you click on a thumbnail it opens a new window with the fullsized image in.
I have modified code from a gallery tutorial to load the thumbnails from a xml file. They are going in 3 columns at the moment (I don't understand why but they are) but only the last image has a hand cursor when you rollover it, and then when you click on it, it traces "undefined" into the output box.
I have put
Code:
trace(images_arr[i].attributes.fullsize);
just below the bit where it loads the thumbnails and it traces the right path from the xml file for each image.
get it to trace the right path from the xml file when you click on ALL the thumbnails, not just the last one.
Code:
function GenerateThumbs() {
images_arr = images_xml.firstChild.childNodes;
gap = 10;
[Code]...
Exactly this doesn't work but is there a way to do it?
Code:
for ( var i = 0; i < 10; i++ )
{
var ["object"+i]:MyClass = new MyClass();
// would create object1, object2, object 3, object 4, ...
}
How would I make an object move right in a loop where it will not stop?
View 6 RepliesI'm trying to program this code:
public function enemiesDie(){
enemyLoop: for (var k:int = enemies.length -1;k>= 0; k--){
bulletLoop: for (var i:int = bullets.length -1; i>=0; i--){
if (enemies[k].hitTestObject(bullets[i])){
trace("hit");
[Code] ....
To detect when a bullet hits an enemy in a game I'm trying to make and I get this error:
TypeError: Error #1006: hitTestObject is not a function.
at Space_Hooligans/enemiesDie()
at Space_Hooligans/gameLoop()
Basically I would like to tween a retangular 2D image on the stage, but also make it look like it is wrapping round on itself.A visual example of the effect I mean is here: [URL]Imagine the above is a rectangular shape being tweened from Right to Left, but when it reaches the left it wraps round as in the picture.Is this possible with Flash CS4 & AS3 or does it require some special add-on?
View 0 RepliesI thought this would be simple but for some reason I'm having all kinds of problems. Why won't the for loop create a new c instance each time the loop increments, like it does for sHolder and s? ...And, assuming it is possible to make it do this, how can each instance be given an identifier that can be accessed dynamically, like sHolder and s in the traceSomething function?
Code:
package {
import flash.display.Sprite;
import flash.geom.ColorTransform;
[Code]....
i've been struggling with the following:
i am creating a list of buttons with an attachMovie. the AS is :
//as
var i = -1;
while(++i<userlist.length){
var user = userlist[i];
[Code].....
okay the problem is this: then i assign an on click function to every button right in the while loop that uses the data parameter of the "ob" object and when i play the movie the data parameter is always the parameter of the last object created for all the buttons. I know why this is happening- it overWrites the old "ob" with the new with every itteration of the loop.
But how would i go differently about creating an individual "ob" for each button created and still be able to have a function with a data parameter like this.onRelease.userClicked(data)?
Can anyone tell me why the following is taking 4 seconds for Flash to execute:
_moleHoles = new Array();
var countingMoleHoles:Boolean = true;
var holeCount:int = 0;
[Code].....
There are 9 object on the stage (but this number could go up or down, that is why I'm dynamically grabbing these this way). So in my test case, this loop runs 10 times.
I have narrowed it down to something to do with the following line:
if (this['moleHole' + holeCount])
Is using dynamic (array syntax) object lookup that much of a performance hit?