Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Array Of Loader Objects



Hi, I'm trying to solve a problem with garbage collection. I have a function that gets called for each line of XML read in. In the function it instaniates a new loader with var bgLoader:Loader = new Loader, adds event listeners etc etc etc. As the XML is read in the function will be called again and (correct me if I'm wrong) will destroy the reference to the loader ie bgLoader. If this is correct, I also assume that this is not ready for gargage collection, including and events attached to the object? Outside of the function, can I setup an array of loader objects? The function takes a num parameter (which is a row number) which can be used as an index to the array. Hope this makes sense to someone. Thank you



Adobe > ActionScript 3
Posted on: 10/16/2008 07:34:08 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Store And Retrieve Array Of Custom Class Objects From Shared Objects.
Hi,

I am stuck up with a problem in ActionScript 2. I am using Flash MX 2004 on windows XP.

I have created 3 custom classes say Parent, Child, and GrandChild. Parent class contains in it an array of its Child objects. Similarly each Child object contains in it an array of GrandChild objects. Also I do have one global array of all the Parent objects.

I want to store this array to the shared objects on specific events(say exiting the session) and then reload them from the shared object(on next session startup). I am able to store the global array to the shared object but when I try to retrieve the same array from shared object, I could not do it. The retrieved array is not of my custom class type [Parent].

Help needed to solve this problem urgently. Does anybody have idea how to do it??

Thanks in advance.



Cheers,
Naishadh Sevalia

Assigning Array Objects To Variables In An Array
how do i take an array with objects [orange, red, yellow, green, blue] and assign them to another array 5 random variables named [Slot1, Slot2, Slot3, Slot4, Slot5]

so i can get results such as

Slot1 = color*
Slot2 = color*
Slot3 = color*
Slot4 = color*
Slot5 = color*


thanks !

How To Sort An Array Based On A Value Of The Objects In The Array
hi,

i have a array containing many objects like this:

arr = [{id:6,val:"bla"},{id:3,val:"bleah"},{id:10,val:"bl o"}]

now i want to sort this array based on the id values of the objects.

any ideas ?

thanks

Pre-loader For Sound Objects
Hi All

Does anyone know of a tutorial for creating a preloader for a movie that contains Sound Objects?

I'm having trouble as in the Linkage properties, I am exporting the audio in the first frame and it is loading before the preloader

Thanks

How Do You Iterate Through Loader Objects?
Does anyone know if it's possible to:

From javascript (for questions 1-3)

1) is there a way to iterate through objects in a swf file? For
example, if the swf has a jpg or some control that I want to target, I
want to be able to iterate through the objects and find that object.
2) is there any way that I can get information about an object, such
as its name, current rect, etc. Also if it's like a jpg or a swf, can
I get the URL that it's pointing to?
3) is there a generic way to pass actionscript code into a swf file
and tell it to evaluate it (something like the eval() call in
javascript)? When I say generic, I mean for every single swf file out
there (of course with a version limit if needed).

Say I have 1.swf file that embeds another 2.swf file (for questions
4-5)
4) From the actionscript in 1.swf, can I iterate through objects in
2.swf? (this is basically question #1 from a different perspective)
5) From the actionscript in 1.swf, can I get information about objects
in 2.swf? (this is basically questions #2 from a different
perspective)


6) If you don't know or if it's not possible to do any of the things
in 1-5, do you know any other way to do it, where the only condition
is that the input file is a random swf that a flash developer can
make?

Loader Is Invisible Or Behind Other Objects?
Hi all,
I have a loader that is either not visible or behind some other display element that I have on stage, and am trying to figure out how to get it visible. I can get this to work fine when I isolate it, but when I implement this in my larger project, things appear to load fine, but it doesn't ever show up on the stage. I'm using addChildAt() to place it at what I think would be the top layer on the stage. In the code below, the disaster_load_complete is called, and I'm able to query the properties of the loaded object (such as it's position, size, parent-- which is the Document --, etc). But it's not visible on the screen! Can anyone help me to troubleshoot this, and help is greatly appreciated!


Code:
content_loader = new Loader();
trace('adding content loader at layer: ' + numChildren); // NUMCHILDREN = 27
addChildAt(content_loader, numChildren);
content_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, disaster_load_complete);
content_loader.load(new URLRequest('test.jpg'));

Loader Is Invisible Or Behind Other Objects?
Hi all,
I have a loader that is either not visible or behind some other display element that I have on stage, and am trying to figure out how to get it visible. I can get this to work fine when I isolate it, but when I implement this in my larger project, things appear to load fine, but it does'nt ever show up on the stage. I'm using addChildAt() to place it at what I think would be the top layer on the stage. In the code below, the disaster_load_complete is called, and I'm able to query the properties of the loaded object (such as it's position, size, parent-- which is the Document --, etc). But it's not visible on the screen! Can anyone help me to troubleshoot this, and help is greatly appreciated!







Attach Code

content_loader = new Loader();
trace('adding content loader at layer: ' + numChildren); // NUMCHILDREN = 27
addChildAt(content_loader, numChildren);
content_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, disaster_load_complete);
content_loader.load(new URLRequest('test.jpg'));

MC Loader Array?
q) How can I use an array for declaring the MovieClipLoader variable for 'X' number of these

i=2;
var this["mLoad"+i]:MovieClipLoader= new MovieClipLoader();//this way

var mLoad2:MovieClipLoader = new MovieClipLoader(); //not this way

This is so I can load an 'x' number of pictures like this following code.
This works but I have to hardcode the number of pictures.
i get no flicker with this code either.


Code:

var aval:Array= new Array();
aval.push("50img2.jpg");
aval.push("8img1.png");
aval.push("98img1.jpg");

var txt2:String;
var txt11:String;

var mLoad:MovieClipLoader = new MovieClipLoader();
//var this["mLoad"]:MovieClipLoader = new MovieClipLoader();
var mLoad2:MovieClipLoader = new MovieClipLoader();

//var this["mLoad"+2]:MovieClipLoader= new MovieClipLoader();
var mLoad3:MovieClipLoader = new MovieClipLoader();


this.createEmptyMovieClip("mc0",this.getNextHighestDepth());

this.createEmptyMovieClip("mc1",this.getNextHighestDepth());
this.createEmptyMovieClip("mc2",this.getNextHighestDepth());


var tum:Number;
var swap:Number;
//var i:Number;
//var j:Number;
i=0;
j=1;
ii=0;
jj=1;
swap=0;
loadpics(ii,jj);
//trace(this["mc"+2]._x);
//trace(88);
tum=setInterval(fade,50,i,j);

function fade(i:Number,j:Number):Void
{

if (_root["mc"+i]._parent._x >=0)
_root["mc"+i]._alpha -=1;

if (_root["mc"+j]._parent._x <=100)
_root["mc"+j]._alpha+=1;

if (_root["mc"+j]._alpha >=100)
{
trace(i+" "+j);
_root["mc"+j]._alpha =100;
_root["mc"+i]._alpha =0;
//loadpics(1,2); flicker


i++;
j++;
if (j==3)
{

j=0;
}
if (i==3)
{
i=0;
}


clearInterval(tum);
tum=setInterval(fade,50,i,j);
}

}


function loadpics(ii:Number,jj:Number):Void
{

mLoad.loadClip(aval[0],mc0);
this["mLoad"].loadClip(aval[0],mc0);
mc0._alpha=100;

//mLoad2.loadClip(aval[1],mc1);
this["mLoad"+2].loadClip(aval[1],mc1);
mc1._alpha=0;

this["mLoad"+3].loadClip(aval[2],mc2);
//mLoad3.loadClip(aval[2],mc2);
mc2._alpha=0;
//trace(this["mc"+2]._x);
//trace(88);
}

Movie Array Loader (MAL Ver. 0.1.3)
Hello All,

This is probily going to be a onetime offering for anyone interested. Here's a beta test of the elusive multiple swf preloader that people keep asking about. Alot of people guard it as a close kept secret.

Here's the link to view it in a very basic form:
http://mc78.com/mac/exp/mal/mal.ver.0.1.3.html

If anyone is interested in knowing more about what it is, what it does, and where to get the source please respond to this post. By the way it is a smartclip so you don't even have to do the tough programming: just use it.

Walking Through An Array With A Loader
Hi, I need some help with dynamic content.

The end product I need is a series of pictures loaded and diplayed in sequence ( one fades in, then out, then another fades in & out etc. ) I have an XML connector set up which provides the filename to a loader which pulls up the first picture, no problem. But I can't work out how to get the following rows from the array & cycle through them each time the timeline returns to the start.

any help would be great,
best wishes
Robert.

Array And Loader Issues
ok, like alot of people i once was good with actionscript, but alas with 3.0 i am a newbie again. however, i am trying to embrace the new standard, and while i hate that it makes things that used to take me 5 minutes take 30 because i have to research the new methods, i DO understand how as3 improves things and am trying to learn it. so, with that said, heres my problem:

i have a swf file that is intended to load up to 4 swf's from an XML list of 9 files. the container swf loads the XML list into an array, then shuffles the list to create a random order in a new array. it then takes that new array and populates the first 4 entries into mClip_1 thru mClip_4. there is then a timer set up to randomly choose a new item in the array to populate into a randomly chosen mClip.

question number one: is there any way to target the layer that the external SWF files get loaded to? i notice it always seems to go into the top-most layer, which is a problem since i originally wanted to have an additional layer on top of the loaded SWFs that had graphic sectional dividers. if i cant target a layer, is there any way to target a specific blank movie clip like i used to be able to do in AS2?

question number two: is there anyway to remove an array object from the array once its been displayed? id like to ensure that if an item is being displayed, it doesnt get chosen by the randomizer to display elsewhere again as that makes its first instance disappear.

any ideas/help?

Array Objects
Can I use the values in an array to identify a series of movieclips ? say

Board = new Array("Clip0" "Clip1");

where Clip0 etc are the instance names of the movie clips.??

Can I also randomly position the clips by referring to the array instead of each individual clip as below.

Clip0._x = 25 * random(8),Clip0._y = 25 * random(8);

and if so ...

How do I do it!!!!!

Array Of Objects
Can I make an array of objects or multidimensioned arrays?


Count(Department,Item) ?? for example

Objects In An Array
Is it possible to sort an array of Objects, using a common property of all objects contained in the array?

cheers

Array Of Objects
Hello,
I would like to push several objects into an array, for example:

Code:
var arrayO:Array = new Array();
var test1:Object = new Object();
test1.building = "house";
test1.rooms = 5;
arrayO.push(test1);
var test2:Object = new Object();
test2.building = "office";
test2.rooms = 5;
arrayO.push(test2);
If I trace the array:

Code:
trace("arrayO "+arrayO.toString());
I get: arrayO [object Object],[object Object]
Is there some way that I can find out the names of the objects in the array, i.e. test1, test2 ?
Thanks

Array Of Objects
Hello,
I would like to send an array that is filled with objects(myBook) to .NET dll and send the first Object in the array back to Flash.
I have no problems sending remote for example array of strings or only Object, but when I try to send array filled with objects nothing works.
In Flash I get errormessage when I try to connect remote.


Code:
import mx.data.components.RemotingConnector;
import mx.remoting.debug.NetDebug;
NetDebug.initialize();
//---ArrayAso
var arrayAso:Array = [];
var myBook:Object;
myBook=new Object();
myBook.item = "crimi";
myBook.number = "1";
arrayAso.push(myBook);
var myBook:Object = new Object();
myBook.item = "history";
myBook.number = "2";
arrayAso.push(myBook);
var myRemConn_rc:RemotingConnector = new RemotingConnector();
myRemConn_rc.addEventListener("result", gotResult);
myRemConn_rc.addEventListener("status", gotStatus);
myRemConn_rc.gatewayUrl = "http://localhost:1368/.../gateway.aspx";
myRemConn_rc.serviceName = "sp_dll.Class3";
myRemConn_rc.methodName = "nameAso5";
myRemConn_rc.params = [arrayAso];
trace("Triggering...");
myRemConn_rc.trigger();
function gotResult(ev:Object) {
trace("Back "+ev.target.results);
}
The code in .dll (asp.net)

Code:
public ASObject nameAso5(ASObject[] aso)
{
ASObject myAs = new ASObject();
foreach (ASObject item in aso)
{
myAs=item;
}
return myAs;
}
I hope someone can assisst me with this.
Thanks.

An Array Of Objects
what is the best method, any samples out there.

this does not work. ........way too may hrs


Code:
// create a clip to draw to
_root.createEmptyMovieClip("mc", 1);

// set our line style
mc.lineStyle(1, 0x000000);
// draw the line based on handle locations
mc.moveTo(10,15);
mc.lineTo(100,100);
mc.lineTo(50,150);
mc.lineTo(200,200);
mc.lineTo(100,250);

//save the values in an array
myArray = new Array();
myArray[0] = new MYOBJ(10,15,11);
myArray[1] = new MYOBJ(100,100,25);
myArray[2] = new MYOBJ(50,150,35);


//print only the x and y values
for ( var i=0; i<myArray.length; i++) {
trace("x= " + myArray[i].locx) + " y= " + myArray[i].locy
};

function MYOBJ(a:Number,b:Number,c:Number){
var ObjectHolder:Object = new Object();
ObjectHolder.locx = a;
ObjectHolder.locy = b;
ObjectHolder.dist = c;
return ObjectHolder;
}

Array Of Objects, Help
im really new to actionscript, so pardon any nub mistakes here.

mp3Array is populated with objects received from an xml, and im trying to make a new array populated only with unique "albums" based on the mp3Array[i].album property. for instance trace(mp3Array[0].album); returns "Discovery".

Currently mp3Array.length is 32, and there are 7 unique album names

so here is the code i have so far, which goes into an infinite loop, any suggestions would help...

str:String;
var albumArray:Array = new Array();
albumArray[0] = mp3Array[0].album;

for ( i:Number = 0; i < mp3Array.length; i++ )
{

for ( j:Number = 0; j < albumArray.length; j++ )
{
if ( albumArray[j] != mp3Array[i].album )
{
albumArray.push ( mp3Array[i].album );
}
}

}

Array Of Objects
I need to create an array of objects, and the following works:


Code:
var objArr:Array = new Array();
objArr[0] = {Type:"Dir", Name:"dir1"};
objArr[1] = {Type:"Dir", Name:"dir2"};
objArr[2] = {Type:"file", Name:"file.txt"};

trace(objArr[1].Name);
The above outputs "dir2" as expected, but when I try this:


Code:
var obj1:Object = new Object();
obj1.Name = "Dir1";
obj1.Type = "Dir";

var obj2:Object = new Object();
obj1.Name = "Dir2";
obj1.Type = "Dir";

var obj3:Object = new Object();
obj1.Name = "file.txt";
obj1.Type = "file";

var objArr:Array = new Array();
objArr[0] = obj1;
objArr[1] = obj2;
objArr[2] = obj3;

trace(objArr[1].Name)
I get "undefined" from the trace. Any ideas?

Objects In Array...
Hi!

I have:

ActionScript Code:
//dataGrid is a DataGrid declared earlier
var cols:Array = dataGrid.columns;
trace(cols);

If I test/debug this I get:
Code:
[object DataGridColumn],[object DataGridColumn],[Obje...
But I want to access the 'dataField' property of each DataGridColumn in the array 'cols'.

How do I do that?

How Many Objects Are There In Array?
I have tried the obvious: looked here for allready answered question, Googled it - I even RTFM'd Obviously I have missed something because I cannot find this one out...


Code:
v = new LoadVars();
v.load("list.txt", "_root");
v.onLoad = function(success) {
if (success) {
picAr = v.files.split("|");
}
};
Works fine, I get a list of files from the file as an array (picAr) and I can access them by using picAr[i].

What I want to know is, how many objects there are in this Array. How do I find out this?

If I use

Code:
objCount = picAr.length;
trace ("Objects:" + objCount);
I get "undefined" error. So how do I get objCount to be a number (such as 2 or 57 and so on)?

Array Of Objects
Hi,

I am creating an array of objects like:
var colors:Array = new Array();
............
colors.push({color:rgb, count:1});

However, before I push a new object into the colors array, I would like to check if the value 'rgb' exists first, else I simply want to increment 'count.'

Is there an elegant way of accessing the color property of the object in the colors array without going though a for loop checking for every single object?

Thanks for any help!

Associated Array Of Objects
While reading a tutorial about movieclips, textfields, and Drawing API, one of the instructions was to write this code:

Code:
var linkageArr:Array = ["A", "B", "C", "D", "E", "F", "A", "B", "C", "D", "E", "F"];
var clips:Object = new Object();

var clip:MovieClip;

for(var i:Number = 0; i < linkageArr.length; i++)
{
depth = this.getNextHighestDepth();
clip = this.attachMovie(linkageArr[i], "clip" + depth, depth, {_x: x, _y: y});

//drawRectangle function creates a filled rectangle and returns a movie clip
card = drawRectangle(Math.random() * 0xFFFFFF, clip._width, clip._height, x, y);
clips[card._name] = {id: linkageArr[i], clip: clip};
}

function drawRectangle(color:Number, width:Number, height:Number, x:Number, y:Number): MovieClip
{
var depth:Number = this.getNextHighestDepth();
var clip:MovieClip;

clip = this.createEmptyMovieClip("clip" + depth, depth);

clip.lineStyle(0, 0, 0);
clip.beginFill(color);

clip.lineTo(width, 0);
clip.lineTo(width, height);
clip.lineTo(0, height);
clip.lineTo(0, 0);

clip.endFill();

clip._x = x;
clip._y = y;

return clip;
}
clips[card._name] = {id: linkageArr[i], clip: clip};
Now my problem is, just when did I every declare an object array named clips? And why does Actionscript allow me to create variables that were never declared?

I read the documentation of Objects but never dealt with what happens with the array. This question might sound a bit primitive because I mainly focusing on C++ so the syntax and implicit effects of Actionscript is unfamiliar to me.

Objects Into Array?
Is it possible to put objects into an array? Basically I'm after something like this:


ActionScript Code:
var pNum:Number = 10;
var myPArray:Array = new Array(pNum);
for(i=0;i<pNum;i++){
    myPArray[i] = new Particle();
}


Particle is a class I've defined which has all sorts of different variables and then some prototype functions added to it. It all works fine if I have one Particle running

e.g.


ActionScript Code:
var myParticle = new Particle();
this.onEnterFrame = function(){
myParticle.run();
}


But nothing happens when I try to create an array of them. How's it done?

Array Of Objects
ActionScript Code:
myArr = [];
for (var i = 0; i<5; i++) {
    myArr[i] = i;
    myArr[i].y = 100+i;
    trace(myArr[i].y) // traces undefined
}


what is wrong here ?

{CS3} (AS2) Problem With Random Array Loader
Hello All !
I have an Array Randomly loading images on to the stage, there is a 'splice'
so no 2 images repeat. the problem is - once the images all get 'deleted' there are
no more images the array can pull. I want the images to be recreated in the array.
That way It will load the 29 images I have Randomly, with out repeating them
and after all 29 appear it will start over again.
If I remove the 'splice' I can load as many images as I want however some load twice
or more before the batch is complete.

Code:
var images:Array = new Array();
for (var i:Number = 0; i < 29; i++) {
images.push("image" + i + ".jpg");
}

images[0]="image0.jpg";
images[1]="image1.jpg";
images[2]="image2.jpg";
images[3]="image3.jpg";
images[4]="image4.jpg";
images[5]="image5.jpg";
images[6]="image6.jpg";
images[7]="image7.jpg";
images[8]="image8.jpg";
images[9]="image9.jpg";
images[10]="image10.jpg";
images[11]="image11.jpg";
images[12]="image12.jpg";
images[13]="image13.jpg";
images[14]="image14.jpg";
images[15]="image15.jpg";
images[16]="image16.jpg";
images[17]="image17.jpg";
images[18]="image18.jpg";
images[19]="image19.jpg";
images[20]="image20.jpg";
images[21]="image21.jpg";
images[22]="image22.jpg";
images[23]="image23.jpg";
images[24]="image24.jpg";
images[25]="image25.jpg";
images[26]="image26.jpg";
images[27]="image27.jpg";
images[28]="image28.jpg";

var picture:MovieClip = this.createEmptyMovieClip("picture",1);
picture._x = -167;
picture._y = 86;

btnRand.onPress = function() {
var num:Number = Math.floor(Math.random() * images.length);
picture.loadMovie(images[num]);
images.splice(num, 1);
};

Array Of Sound Objects?
Anyone out there know if its possible to have an array of Sound objects? that way I would just be able to do something like

soundArray[1].start();
soundArray[78].start();

The reason for all this being that I'm using Generator to dynamicly load in MP3s and i gotta figure ona way to do the attach sounds....

Referencing Of Array Objects
Hello!
I don't know how many ties I've had this d*mn problem but it never fails - I can't get it to work. Lemme tell you what I am TRYING to do.

I have an array that randomly generates numbers (14). No problem. I call the array alpha cause it controls alpha levels and such (this doesn't matter). I also have a MC on the stage called mc_oval. After each loop (14 of them) - count has one added to it. I want to be able to able to duplicate the mc_oval MC and call each new MC "mc_oval" + count. Each new level is count +1 (so we don't replace level0.

the problem comes when I go to position the dynamic clip. Here is my code:


Code:
n = 14;
count = 0;
alpha = new Array();
while (count<n) {
alpha[count] = randomNum=Math.round(Math.random()*99+1);
//
duplicateMovieClip (_root.mc_oval, "mc_oval_"+count, count+1);
setProperty ("mc_oval_"+count, _x, "25");
count++;
}
Now I have tried this eval() sh*t but it works werid and doesn't fix the problem. I've tried:

eval("mc_oval_" + count);
and
"" + eval('mc_oval_' + count);

I'm lost - please help me!

Can An Array Be Used To Hold Objects?
I want to create an array with 26 sound objects in it. These sound objects will hold sound files of the different tones created by an engine so that they can be used with a variable '_root.revs', which can hold a value of anything between 0 and 260, supplied by my engine clip. This is the AS attached to the 'rev sound' clip:

onClipEvent(enterFrame){
if (!_root.idle){
revPlay = int(_root.revs / 10);
if (revPlay > 0){
rev[lastRevPlay].stop("rev" + lastRevPlay);
rev[revPlay].start("rev" + revPlay,4);
lastRevPlay = revPlay;
}
}
}

onClipEvent(load){
for (i=1;i<27;i++){
rev = new Array();
rev[i] = new Sound();
rev[i].attachSound("rev"+i);
}
}

Problem is it doesn't do anything! I get no sound... I know the soundclips are fine and are identified properly in the linkage within the library so I'm thinking maybe you can't have objects in an array?

GP
gp@1lg.com

Referencing Objects Via An Array
hello

i am trying to create a fake email inbox for an eLearning simulation. the brief is thus:

the inbox lists emails. emails are added as the user progresses through the game. for each email, its variables are displayed (from, subject, date received).

i have an array to store the emails in, and an index to keep count:


Code:
// Keeps track of number emails so that they can be put into an array
//and referenced.
emailCount = 0;

// Array to store emails in.
emails = new Array();


i have a constructor to create a new email object:


Code:
function email(newID, newFrom, newSubject, newBody, newDate) {
ID = newID;
emailCount ++;
from = newFrom;
subject = newSubject;
body = newBody;
thisDate = newDate;
read = false;
emails.push(ID);
}


i also have a function to display the emails:

Code:
displayEmails.onPress = function() {
for(i = 0; i < emails.length; i++) {
attachMovie("emailListMember", ["emailListMember" + i], i);
with(["emailListMember" + i]) {
from = _root.emails[i].from;
subject = _root.emails[i].subject;
thisDate = _root.emails[i].thisDate;
ID = _root.emails[i].ID;
_x = 30;
_y = 30 * i + 10;
}
}
}


after creating a couple of email instances, and trying to display them, i find their variables are not set. i think its because the array values do not point to the email instance itself, and merely holds a string.


cheers in advance

HELP PLEASESound Objects In Array@#$%^
Somebody please tell me how to use sound objects in an Array.
This is so important and useful...yet I can't find a single clear answer anywhere. How do I define sound objects in an array so i can work with the list easily. The objects will be linked to external mp3s. THANKS THANKS THAnks

Accessing Objects In An Array
I have a card matching game I'm working on. My idea is that when two cards are turned over, they are placed in an Array. The array then checks to see if they are a match. The issue is that the card instance names will not match since both cards need to have different instance names onstage. I've tried just having the cards dump a number into the array, so then the numbers will match; but if it's not a match, I can't make the specific cards that were selected turn back over.
I could use two arrays, one for numbers and one that will hold the card MCs, but I was hoping there was a more elegant, streamlined solution.

To sum up, i guess my question is this...
When i've put an object like a movie clip instance into an array, can I use the array to access the objects' variables, functions, or anything so I can use THAT information to compare the cards other than their instance names?

Access Array Of Objects
I need to fill an array with objects, access the information stored in the array and use it to duplicate a movie
clip. I am an avid programmer new to actionscript so any tips and pointers are welcome.

Here I am attempting to fill the array array_Calendar (initialized as: var array_Calendar:Array;) with DateCell objects.


code:
for (var dateNum = 0; dateNum < 42; dateNum++)
{
array_Calendar[dateNum] = new DateCell(dateNum);
}


This is the DateCell class:

code:
class DateCell
{
var dateCell;
var dayNumber;
var eventText;
var eventList;

function DateCell(dateNum)
{
dateCell = (typeof dateNum == "number") ? "calendarDate" + dateNum + "_mc" : "";
dayNumber = (typeof dateNum == "number") ? "_root.calendarDate" + dateNum + "_mc.dayNum.text" : "";
eventText = (typeof dateNum == "number") ? new Array("_root.calendarDate" + dateNum + "_mc.eventText0_mc.eventText_dt.text", "_root.calendarDate" + dateNum + "_mc.eventText1_mc.eventText_dt.text", "_root.calendarDate" + dateNum + "_mc.eventText2_mc.eventText_dt.text") : "";
eventList = new Array();
}
}


This is the line I'm trying to use to duplicate the movie clip:

code:
duplicateMovieClip("calendarDate_mc", array_Calendar[day].dateCell, day);


After the loop that is supposed to fill the array with DateCell objects I used the trace function to see if the array
was indeed filled with objects. Trace returns "undefined", so either I'm not using the trace function correctly
(I used it like so: trace (array_Calendar[day].dateCell);) or the array isn't getting filled correctly. I'm guessing
it's the latter of the two.

I need to fill an array with objects, access the information stored in the array and use it to duplicate a movie
clip.

Adding Objects To An Array
Hi

I'm trying to create a 2 dimensional array where each value is within 2 objects. I want to access the final thing like this:

foo = grid[i][j].book.title;
bar = grid[i][j].car.colour;

What I don't want to do is access it like this:

foo = grid[i][j][k][l];

I've tried:
grid[i][j].book = new Object();
grid[i][j].book.title = new Object();

Syntax For Array Of Objects
Version: Flash MX 2004

Question: I'm trying to instantiate a class to an array. However, I can't figure out the syntax to make it work.

Here is what I used to generate an object:

Code:
var goodWeapon:CurrentWeapon = new CurrentWeapon("0","Food","100","-10","This is a test");


I'm trying to get something like this:

Code:
var goodWeapon[i]:CurrentWeapon = new CurrentWeapon("0","Food","100","-10","This is a test");



Thanks!

Array Not Recognizing Objects
I have a code to create an array, then fill it with objects c1,c2,c3,c4,c5.......,cN.

objectcount = 14
for (myarray=new Array(objectcount), objectnumber=0; objectnumber<objectcount; objectnumber++) {
myarray[objectnumber] = ("c"+(objectnumber+1));
}

that seemed to work just fine. I used trace() and found the array to contain c1 through c14. btw, c1 through cN are movie clips.

then i have a code to change _x and _y for each object in the array.

for (i=0; i<objectcount; i++) {
myarray[i]._x = somenumber;
myarray[i]._y = someothernumber;
}

the behaviour of my movie and a trace action i tried made it evident that my code was unable to set the _x and _y properties on my array objects. a trace action asking for the _x coordinate of one of my objects returned blank.

trace("the _x value is " + myarray[5]._x)

that returned the _x value is

It seems as though it is treating my objects as something other than movieclips.

help please

Tracing Array Objects
Hey people,
this one may be pretty easy but seem to have a mental bock. I need to trace a value inside an array that is inside an object.

I am tring to trace this value using a dynamic parameter in script. This trace will happen in side a for loop.

The Object's name is myObject

the array inside the object is called value

The dymanic parameter is accountName. This parameter vaule inside the loop is myObject.

so with that being said why won't this work.


Code:
for (var i:Number = 0; i<=3; i++) {
trace(_root[accountName][value][+i]);
}

Sorting An Array Of Objects
Hi,

I have this array of objects, each element of the array contains 3 properties, (link:String, level:Number, Count:Number). I want to sort my array ascendingly based on the 'level' property. Any idea how to do that?

Best Regards

[F8] Referencing Array Of Objects
Ive done this before, but I forget teh notations. I have objcts date1,date2..... save as a movieclip dateBoxes. I cant remember how to referencec them, say, in a for loop.

for (i=0; i==10; i++) {
dateBoxes.["date" + i].text = i;
}

Like that but it has to work lol.

thanks in advance.

Randomizing Array Of Objects
Ok, I am building an E-learning website. I have draggers and hit areas. If you drag the word to the right sentneces it sticks you get points and happy sounds happen and what not. Anyways, I have some problems with randomizing the Array of Objects so that every stage is different, I want the to swap the locations of the hit, pictures, draggers, ect... I'm in the testing process now, the pictures, sounds, sentences and words are loaded from folders dynamically.

var myStruct:Array = [
{myText:textArr[0], mySentence:sentenceArr[0], myHint:hintArr[0], myDragger:dragger0, myHit:hit0, myLine:line0, myImage:img_container0, mySound:soundArray[0]},
{myText:textArr[1], mySentence:sentenceArr[1], myHint:hintArr[1], myDragger:dragger1, myHit:hit1, myLine:line1, myImage:img_container1, mySound:soundArray[1]},
{myText:textArr[2], mySentence:sentenceArr[2], myHint:hintArr[2], myDragger:dragger2, myHit:hit2, myLine:line2, myImage:img_container2, mySound:soundArray[2]},
{myText:textArr[3], mySentence:sentenceArr[3], myHint:hintArr[3], myDragger:dragger3, myHit:hit3, myLine:line3, myImage:img_container3, mySound:soundArray[3]},
{myText:textArr[4], mySentence:sentenceArr[4], myHint:hintArr[4], myDragger:dragger4, myHit:hit4, myLine:line4, myImage:img_container4, mySound:soundArray[4]},
{myText:textArr[5], mySentence:sentenceArr[5], myHint:hintArr[5], myDragger:dragger5, myHit:hit5, myLine:line5, myImage:img_container5, mySound:soundArray[5]}
];

file is to big to attach!

Anny Ideas?

Variables As Array Objects
im creating a script and what it does is allow variables to do all the work.
however, is it possible to list an array object as a variable?

for example:


car = "mercedes";

mercedes = new array("luxurious", corporate blue", "leather seats", "smooth ride", "v12 5.7ltr");

car[0];

but if it was written like this it would work because the variable car is an expression:

car = mercedes;

mercedes = new array("luxurious", corporate blue", "leather seats", "smooth ride", "v12 5.7ltr");

car[0];


is there a way for me to use a variable where the car is not an expression but a string?

Removing Objects From An Array
Hi There

I'm having a few issues removing an object from an array. I've used the push method from a game class which places an object into an array called Inventory. I'm trying to use the startDrag and StopDrag methods to place it on the stage. Could anyone tell me where may be going wrong.BTW the drag methods are in my main class file and I'm trying to call an object from a different class file.

Many Thanks

Prooster

Retrieving Objects In An Array
Okay i have an array storing what i have found out to be objects.
Is there anyway i can return the value of Score or Player from the array?


Code:
wormscores = new Array();
wormscores.push({Player:"Unknown", Score:10});

TIA,
Turbs

Sorting An Array Of Objects
I've got an array of objects. I need to know the most efficient way to sort the array. I only need to be able to sort by integers.

For example...


Code:
playerPass = new Array();

playerPass[0] = new Object();
playerPass[0].Name = "T. Bag";
playerPass[0].Att = 3;

playerPass[1] = new Object();
playerPass[1].Name = "A. Nus";
playerPass[1].Att = 5;
Of course i've got way more objects and way more properties inside each object. I need to be able to choose which object property to sort the array by. Your help is appreciated, thanks.

by the way I'm using flash 8

Duplicating A Array Of Objects
how can i duplicate an array that contains object of myType ?
And it must be FAST code...

I only manage to copy references and ..that fails..HELP !

A Question On Array Of Objects
If I make an array of objects from XML

Code:

var aArms:Array = new Array();
for (var xmlArms:XMLNode = xmlBody.childNodes[0]; xmlArms != null; xmlArms=xmlArms.nextSibling) {

var oArms:Object = {
left_hand: xmlArms.attributes.left_arm,
right_arm: xmlArms.attributes.right_arm};
aArms.push(oArms);
}
}
Considering there I have a collection of arms, can loop for their values like this?


Code:
for (var k:Number = 0; k<aArms.length; k++) {
trace(" Hex: "+_root.aArms[k]['right_arm']+" Times: "+_root.aArms[k]['left_arm']);
}
Well I know can't because I tried and it doesn't work, but how can I?

Two Objects Referencing Same Array?
I'm working a neural network project and my basic architecture is this:
1. Neurons
2. Neuron Layer (basically an array of neurons)
3. Neural Network (basically an array of Neuron Layers)

When I reference the first Neuron Layer's array.length it gives me the total number of neurons in the network rather than what the number of neurons in the first layer should be. The same thing happens for the second layer and each subsequent layer should there happen to be more. I've added trace statements to the Neuron Layer constructor that tells me a neuron has been added and I've also added a trace statement after the first neuron layer is added and the second neuron layer and I get the correct number of "neuron added" statements before the "first layer added" statement and the correct number for the second layer as well. This pretty much assures me that the actual number of neurons in each layer is correct when the first layer is created but somehow the number of neurons in the first layer and subsequent layers is actually becoming the number of neurons total. The only thing I can figure out is that somehow, the first neuron layer object is referencing the same neuron array member as the second neuron layer object. Is this possibly what is happening?

Here's the code for the Neuron Layer class:

Code:
import Neuron;

class NeuronLayer{
//number on neurons in layer
private var numNeurons:Number;
//array of neurons
private var neurons:Array=new Array();
//number of inputs per neuron
private var numInputsPerNeuron:Number;

//constructor
public function NeuronLayer(numOfNeurons:Number,numOfInputsPerNeuron:Number)
{
numNeurons=numOfNeurons;
numInputsPerNeuron=numOfInputsPerNeuron;
for(var i=0;i<numNeurons;i++)
{
var neuron:Neuron=new Neuron(numInputsPerNeuron);
neurons.push(neuron);
trace("Adding Neuron");
}
}

//function to get the num of neurons in layer
public function getNumNeurons():Number
{
return numNeurons;
}

//function to get the num inputs per neuron
public function getNumInputsPerNeuron():Number
{
return numInputsPerNeuron;
}

//function that returns a copy of the neuron array
public function getNeuronArray():Array
{
var neuronArray:Array=new Array();
neuronArray=neurons.slice();
return neuronArray;
}
}
And here's the code for the Neural Network Class:


Code:
import Neuron;
import NeuronLayer;

class NeuralNetwork{
//number of inputs for network
private var numInputs:Number;
//number of outputs for network
private var numOutputs:Number;
//number of hidden layers
private var numHiddenLayers:Number;
//neurons per hidden layer
private var numNeuronsPerHiddenLayer:Number;
//array of neuron layers
private var neuronLayers:Array=new Array();
//activation response constant
private static var P_SETTING:Number=1;

//constructor, initializes private members for this class and call createNet
//function
public function NeuralNetwork(inputs:Number,
outputs:Number,
hiddenLayers:Number,
neuronsPerHiddenLayer:Number)
{
numInputs=inputs;
numOutputs=outputs;
numHiddenLayers=hiddenLayers;
numNeuronsPerHiddenLayer=neuronsPerHiddenLayer;
createNet();
}

//function that gets the number of inputs
public function getNumInputs():Number
{
return numInputs;
}

//function that get the number of outputs
public function getNumOutputs():Number
{
return numOutputs;
}

//function that gets the number of hidden layers
public function getNumHiddenLayers():Number
{
return numHiddenLayers;
}

//function that gets the number of neurons per hidden layer
public function getNumNeuronsPerHiddenLayer():Number
{
return numNeuronsPerHiddenLayer;
}

//function that returns a copy of the neuron layer array
public function getNeuronLayerArray():Array
{
var neuronLayerArray:Array=new Array();
neuronLayerArray=neuronLayers.slice();
return neuronLayerArray;
}

//builds network from neurons
private function createNet():Void
{
//create layers of network
if(numHiddenLayers>0)
{
//create first hidden layer
var firstHiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numNeuronsPerHiddenLayer);
//push it into the neuron layer array
neuronLayers.push(firstHiddenLayer);

trace("Added first layer");

//create other hidden layers as necessary
for(var i=0; i<numHiddenLayers-1; i++)
{
var hiddenLayer:NeuronLayer=new NeuronLayer(numNeuronsPerHiddenLayer,
numInputs);
neuronLayers.push(hiddenLayer);

trace("Adding Additional layers");
}

//create output layer
var outputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numNeuronsPerHiddenLayer);
neuronLayers.push(outputLayer);

trace("Added output layer");
}
else
{
//create output layer
var defaultOutputLayer:NeuronLayer=new NeuronLayer(numOutputs,
numInputs);
neuronLayers.push(defaultOutputLayer);
}

}

//function that returns all the weights in the network as an array
public function getWeights():Array
{
var weightArray:Array=new Array();
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
weightArray.concat(neuronLayers[i].getNeuronArray()[j].getWeights());
}
}
return weightArray;
}

//function that returns the total number of weights in the network
public function getNumWeights():Number
{
var total:Number=0;
for(var i=0; i<neuronLayers.length; i++)
{
for(var j=0; j<neuronLayers[i].getNumNeurons(); j++)
{
total+=neuronLayers[i].getNeuronArray()[j].getWeights().length;
}
}
return total;
}

//replaces old weights with new weights
public function putWeights(weights:Array, newWeights:Array):Void
{
//empties array that's passed
weights=[];

weights=newWeights.slice();
}

//sigmoid response curve applier
public function applySigmoid(activation:Number,responseSetting:Number):Number
{
return 1/(1+Math.pow(Math.E,(-activation/responseSetting)));
}

//calculate outputs from set of inputs
public function update(inputs:Array):Array
{
//stores the resulting outputs from each layer
var outputs:Array=new Array();

var weightCounter:Number=0;

//check for correct number of inputs
if(inputs.length!=numInputs)
{
//just return empty vector if incorrect
return outputs;
}

//for each layer
for(var i=0;i<numHiddenLayers+1; i++)
{
if(i>0)
{
//copies elements into the array
inputs=outputs.slice();
}

//clears array of values
for(var a=outputs.length;a>=0; a++)
{
outputs.pop();
}

weightCounter=0;

//for each neuron sum the inputs*corresponding weights
//throw the total at the sigmoid function to get the output
for(var j=0;j<neuronLayers[i].numNeurons;j++)
{
var netInput:Number=0;

var numOfInputs:Number=neuronLayers[i].neurons[j].numInputs;

//for each weight
for(var k=0; k<numOfInputs-1; k++)
{
//sum of the weights*inputs
netInput+=neuronLayers[i].neurons[j].weights[k]*inputs[weightCounter++];
}

//add in the bias
netInput+=neuronLayers[i].neurons[j].weights[numOfInputs-1]*-1

//we can store the outputs from each layer as we generate them.
//The combined activation is first filtered through the sigmoid
//function
outputs.push(applySigmoid(netInput, P_SETTING));

weightCounter=0;
}
}
return outputs;
}
}

Inserting Objects In An Array.
Hello Guys,

I am facing some problems while inserting the objects in the array. I have linked my custom class to the flash MovieClip which extends it, so my custom class looks like:

class CustomClass extends MovieClip {
function A() {
}
};

now i am making an array of the objects of this CustomClass, the array is made as follows:

var ccArray = new Array();
var ccObject;

for (var index = 0; index < 10; ++index) {

ccObject = _root.attachMovie(arguments); // This will create the object of CustomClass since Custom Class is linked to flash MovieClip.
ccArray.push(ccObject);
......
...
}

Now when i want to access some function of Custom class like ccArray[0].A(), it does not gets called. i am confused. Can objects be stored in arrays?
Please Help.

Dynamic Array Of Objects
Hi guys istuck

ActionScript Code:
var expenses:ArrayCollection = new ArrayCollection([
                                                {expenses:"Proteins",Amount:"30"},
                                                {expenses:"Vitamins",Amount:"20"},
                                                {expenses:"Carbs",Amount:"40"},
                                                {expenses:"Fat",Amount:"10"},
                                                ]);
how to create this array collection dynamic thats the values Amount
are dynamic and values to expenses are dynamic

Copyright © 2005-08 www.BigResource.com, All rights reserved