Simple Problem - Referencing Object Array Properties
Sure this is dead straightforward. My flash creates a bunch of objects with x and y properties. These all get pushed into an array and then my .NET aspx page gets the array as an argument. This seems to be an ArrayList (although the documentation seemed to say it would be a HashTable) of ASObjects. How do I then refereence the x and y properties of the ASObject - is this what is now referred to as a Key?
Adobe > Flash Remoting
Posted on: 03/12/2007 11:34:12 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Referencing MovieClip Properties From An Array
Code:
container_mc = _root.createEmptyMovieClip ("Page_Container_mc",100);
pageContent = new Array ();
for (var p=0; p<5 ; p++) {
pageContent[p] = container_mc.attachMovie ("Page Content "+p, "page_content"+p, 1000+p*100); // "Page Content 1"... are linked from library
pageContent[p]._y = 300; // won't work because ???
}
Hi all,
As you can see from the above code, I'm trying to create a set of MovieClips and save a reference to each in an Array so I can easily access them and their props/methods.
I must be having a brain-lapse because I can't get this to work. Any ideas on this or a better approach?
Any help is greatly appreciated. Cheers.
Referencing An Object In An Array
This is practically spam and I appologize. I think I can better articulate my problem now- and thought a new post would help.
If _inventory[2] = "a string" that is my Event.target I could:
trace(Event.target)
And it would trace "string".
trace(Event.target == "a string")
And it would trace true.
Same is true for:
trace(Event.target == _inventory[2])
Now, if I replace _inventory[2] with an instance of the class string_mc and it is my Event.target I can still:
trace(Event.target)
But now I get:
[object string_mc]
And I can still:
trace(Event.target == _inventory[2])
And get a true.
But if I try the equivelent of trace(Event.target == "string") I cannot make it work.
trace(Event.target == [object string_mc]) gets a syntax error.
trace(Event.target == object string_mc) doesn't work.
trace(Event.target == string_mc) comes back false.
Using === instead of == doesn't work either.
So, what do I put between the == and the closing paren to make this work?
Array Referencing Object
I have created an object that I wish to put into an array. I will have several objects with different commands that are going to be in this array. I would like to specifically reference the different variables in the objects. I thought I had everything going but when I traced the array the different variables are listed as undefined. How do I specifically reference a variable of an object that is placed in an array?
var MyObj = new Object();
MyObj.Title = "CTRLA.jpg";
MyObj.Command1 = "yeah";
MyOBJ.Command2 = "Nah";
objective = new Array();
objective[0] = MyObj;
trace (objective);
for(i =0; i < objective.length; i++){
trace(objective[0].Command1);
}
Thanks,
Sam
Referencing An Object's Variables In An Array?
I have created an object that I wish to put into an array. I will have several objects with different commands that are going to be in this array. I would like to specifically reference the different variables in the objects. I thought I had everything going but when I traced the array the different variables are listed as undefined. How do I specifically reference a variable of an object that is placed in an array?
var MyObj = new Object();
MyObj.Title = "CTRLA.jpg";
MyObj.Command1 = "yeah";
MyOBJ.Command2 = "Nah";
objective = new Array();
objective[0] = MyObj;
trace (objective);
for(i =0; i < objective.length; i++){
trace(objective[0].Command1);
}
Thanks,
Sam
Two Object Referencing Same Member 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?
Accessing Properties Of An Object In An Array
I'm trying to set a text field to a property of an object in an array and i cant seem to find the correct way to do this. I figured it would be something like Textfieldname = Array[0].propertyname;
Retrieving Object Properties In Array
Last edited by mr.b : 2003-07-13 at 18:54.
Hi all, I’m trying to get the properties of an object stored in an array and I can’t seem to figure out the syntax. I’m a bit rusty at the game. Thanks for any help!
Code:
test_array = new Array();
test_object = new Object();
test_object.testing_property = "test";
test_array.push(test_object);
// i thought this was right
trace(test_array[0].test_object)
Retreiving Object Properties From Objet Array
Hi, everyone, I'm new here. I've been checking out the Kirupa tutorials and the forums, looks really helpful.
I do have a question--I've been banging my head against this problem in a few areas. This is Actionscript 2 in Flash 8 and CS3.
I'm basically loading an XML file to assign instances of a movie clip a distinct value, which it uses to modify its height.
So, I'm looping through the xml and instantiating my class Object each time (Rect) and then placing that Object into an array:
Code:
function loadXML(loaded){
if(loaded){
var boxArray:Array;
xmlNode = this.firstChild;
sections = xmlNode.childNodes.length;
trace("sections = " + sections);
for(i=0;i<sections;i++){
var thisYear:Number = xmlNode.childNodes[i].firstChild.childNodes[0].nodeValue;
var coal:Number = xmlNode.childNodes[i].firstChild.nextSibling.childNodes[0].nodeValue;
contain.attachMovie("scalerBox", "scaler", i+100);
//"contain" is an empty movieClip on the stage.
var boxyGuy:Rect = new Rect(contain, i, coal);
// parameters in Rect are (targetMC, listPosition, value)
trace("boxyGuy"+i+" created");
boxyGuy.setCoalHeight();
boxyArray.push(boxyGuy);
}
}
}
The problem is, later, when I'm outside the for loop I'm trying to get back the values of Objects in the boxyArray and it keeps coming up as undefined. Btw, I'm trying make the object instance that is rolled over change to a textFormat that is in the Rect Object class.
So, I'm trying to run through the array this way:
Code:
for(i=0;i<sections;i++){
trace(boxyArray[i]);
boxyArray[i].onRelease = function(){
dosomestuff, etc.
}
}
the trace here always comes up undefined. "listPosition" in this bit is an Rect parameter, defined in the previous bit of code as "i", so I can keep track of the order of the stack.
I've found one or two examples of putting objects into an array and getting them back out, but it doesn't seem to work with this, maybe because I'm using a class. I don't know.
Any ideas? Could this be an area where I need to use the array access brackets, like around the movie clip the object is loaded into. I've tried everything I can think of -- referencing back to the movieclip, adding extra objectRef type parameters... nothing has worked yet.
Thanks, and I hope I can contribute to the community here!
Convert Shared Object Properties Into Ordered Array
I need to put the shared object data (that contains the client names) into an ordered array.
The following is NOT useful:
for (var i in _chatSO.data) {
if (_chatSO.data != null) {
var clientObj = _chatSO.data;
users.push(clientObj.username);
}
}
That doesn't solve my problem because each client will end up with an array of different order, e.g., [client1, client2, client3] and [client2, client1, client3] etc.
Context: Multiplayer game where I make 2 teams and assign a number and colour (color) to each player. Each client (player) that joins needs to create movie clips representing the previously joined players, each labeled with a number. Unless they have access to the same array, it can't be done.
Thank you,
Norm (new to FMS)
How To Create Simple Object Array
i need to create an array of 80 square objects that have the vars of color, size and ID number in them and i can't do that at all.
Can someone please help me with that task
Thank you ahead
Array Object Question, Simple One...
Hi folks, I need a little help with an XML project I'm doing. I have some code I'v created but I am not quite sure how to save Objects into an array and recall them for use.
Code:
var XMLfile:XML = new XML();
XMLfile.ignoreWhite = true;
var fileArray:Array = new Array();
XMLfile.onLoad = function() {
var nodes:Array = this.firstChild.childNodes;
for (i=0; i<nodes.length; i++) {
fileArray.push(new file(nodes[i].attributes.url, nodes[i].attributes.name));
}
};
XMLfile.load("text.xml");
trace(fileArray.file);
I have seen Lee do this in his MP3 player Part 3 tutorial but there was not a really detailed explanation on it.
Can some one help me out? I'm trying to puts new objects into my array and then call them for use.
ragscoon =<^_^>=
Thanks in advance.
Referencing A Sprite Subclass's Properties
Hi there allow me to begin explaining my confusing.
Class A extends Sprite {}
Say we want to create a list of A objects on screen. 1 below the other.
var array:Array = new Array();
for (var i:int = 0; i < 10; i++)
{
var a:A = new A();
addChild(a);
if (array.length > 0)
{
a.y = array[i-1].y + array[i-1].height;
}
}
Im not sitting infront of Flex or Flash just now, but you get the basic idea.
In my project, these are news Items loaded with XML, if i trace inside the A class, i can do
trace(this.height) //160;
however, when i do this on the same object outside the class
trace(a.height) //0;
Incredibly frustrating!!
The A class is on the stage, i physically can see it there and it looks about 200px high so why is its height property returning as 0?
Thanks
Problem Referencing Duplicated Movieclips And Changing Their Properties
Hello I am relativley new to action script and I am stuck on this problem.
I have a timer and data that creates a new ball whenever i want and to do so i created this function. I have been working off an example and I am using the same format yet when i reference them by using this["ball"+currentTick]._y it never registers. What am i doing wrong? Thanks
my function is below.
this.makeBall = function()
{
trace("newball")
_root.ball.duplicateMovieClip("ball"+this.currentT ick,i+100);
this["ball"+currentTick]._y = 0;
if(math.Random() > .5)
{
this["ball"+currentTick]._x = 150;
}else{
this["ball"+currentTick]._x = 250;
}
trace(this["ball"+currentTick]._y)
trace(this["ball"+currentTick]._x)
}
How Do I Trace The Properties Of An Object's Properties?
I forgot to put it in the title so I'll just place it here; I am using AS 2.0. I know that there are other ways to accomplish the goal that am after, but I was wondering if anyone knows of a way to access the properties of an object's properties?
Here is the code that I thought of, even though it doesn't work
var a:Object = new Object();
a.bproperty = 0; //lowerlevel properties
a.cproperty = 1; // lowerlevel properties
var d:Object = new Object();
d.e = a; // upper level properties
for(var i in d){
for(var j in d.i){
trace(i + " = higher level lower level= " +j);
}
}
I know that you can enter the following code to view the 'lower level' properties of d.e:
for(var i in d.e)
This really just boils down to how I am organizing the code(I have ideas on what do next, and i am 99% sure that I can get them to work), and if there is a way to dynamically access the properties of the objects properties, It will save me from creating yet another large block of code for my project. If you want to see the unfinished project, go to http://www.garrettchristopherson.com
Referencing Array Items With An Id Pulled From The Array
I have been modifying one of the Kirupa tutorials about loading external xml data and arrays. I have it successfully working, but i would like to figure out how to take it one step further. I want to be able to designate a each item in the arrays with an id rather than an iterative variable number and cannot figure out how to do it.
This is a snippet from the xml file:
<projects>
<item>
<id>13</id>
<projectname>First Project</projectname>
<location>Anytown, USA</location>
<units>60</units>
</item>
<item>
<id>33</id>
<projectname>Second Project</projectname>
<location>Sometown, USA</location>
<units>132</units>
</item>
</projects>
I am currently populating an array this way:
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
id[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
projectname[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
plocation[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
units[i] = xmlNode.childNodes[i].childNodes[3].firstChild.nodeValue;
}
but that just gives me references to: projectname1, projectname2 etc.
I would like to figure out how to get the <id> value from the loaded xml file connected to the variable name of each item in the array so that i can refer to the variables this way: projectname13, projectname33, etc.
Does this make sense? Can anyone help?
Targeting Object Properties Inside PopUp Object
In my project I am creating a window using the PopUpManager. The symbol used to create that window has several objects.
For the sake of discussion we'll discuss the object message_txt inside myWindow.
How do I reference message_txt.text from actionscript after the object is dynamically created?
Changing An Array Result From An Array Object To A MovieClip Object
Anyone know how I can do this?
I have 3 arrays.
Quote:
//set info into arrays
wpInstName = new Array();
for(i=0; i<_global.wpCount; i++); {
wpInstName[i] = _global.newWP;
trace(wpInstName.join(" + "));
}
wpPositionX = new Array();
for (i=0;i<_global.wpCount;i++); {
wpPositionX[i] = _global.wpXpos;
trace(wpPositionX.join(" + "));
}
wpPositionY = new Array();
for (i=0;i<_global.wpCount;i++); {
wpPositionY[i] = _global.wpYpos;
trace(wpPositionY.join(" + "));
}
I need to use the current value of wpInstName[i] to change the _x and _y properties of an attached movie clip.
I have tried allsorts but it still treats the data as an Array object.
I have tried making a new Object and gave it the wpInstName[i] as a value to add properties too but im not sure if I did it right(it didnt work so I guess not ).
If anyone could help it would be greatly appreciated
Thnx
Referencing An Object
I'm trying to identify which Object should be called by passing an arguement to a function
ActionScript Code:
function myAdd(imageUrl,xPos,yPos,myTransition:String) {
var myImage:LoadObject=new LoadObject(imageUrl);
var ExpandAPrimary:Object={scaleX:1,scaleY:1,time:.5,transition:"easeOutElastic"};
var mytest:Object = ExpandAPrimary;
trace("your test var is: "+ mytest);
myImage.scaleX=0;
myImage.scaleY=0;
myImage.x=xPos;
myImage.y=yPos;
Tweener.addTween(myImage, {base:mytest});
addChild(myImage);
}
When i try and replace
ActionScript Code:
var mytest:Object = ExpandAPrimary;
with the arguement myTransition:String
i get:
ReferenceError: Error #1069: Property base not found on String and there is no default value.
the initial call is
ActionScript Code:
var myclock1:ObjectTimer = new ObjectTimer(.5, 'nut1.png', 0, 50, 'ExpandAPrimary');
Referencing From Object
Hi!
Can anyone explain, how can I reference to a timeline from the object not using _root?! Is it posible?
For example:
ActionScript Code:
var someListener:Object = new Object();
someListener.onMouseMove = function() {
trace("_root "+_root); //_root _level0
trace("this "+this); //this [object Object]
};
Mouse.addListener(someListener);
Referencing An Object
I'm not sure if this is good scripting practice...anyhow... I have a constructor function that creates an object and then attaches a movie onto the stage that is referenced within the original object. Now, if I attach a onPress function to the movie, is there any way to reference the very very first object? I think I am seeing a hierarchy that really doesnt exist...
An example would be:
Code:
MainObject = function(){
this.ref = _root.attachMovie("mc","my_mc",1)
this.message = "hi!"
this.ref.onPress = function(){
trace(?***?.message)}
}
Is there anything I can put in ?***? that would reference the original object and display the original objects message? Sorry if this is a dumb quesion!
Array Referencing
please help
I'm playing around with buttons moving an object on the stage, I can get this working fine but I want to use an array to indicate the amount of pixles that the object moves.
this is the coding on the stage for the first frame:
MyPos = new Array("10", "20", "30", "40", "50", "60", "70", "80", "90", "110", "120");
var current:Number = 0;
the variable "current" I'm using as a counter to indicate what index of the array is to be requested.
here is the code on the button:
on (release) {
trace(current)
if (current < MyPos.length) {
trace(MyPos[current]);
sygArrow._x += MyPos[current];
current++;
trace(current);
}
}
I can get it working if I use the number '10' instead of 'MyPos[current];'
good luck and thank you for taking a look.
post a message of send as email to intract_6@hotmail.com
Referencing Another Array
well its amazing how stupid flash makes you feel sometimes...
all i want to do is have a bunch of Arrays like:
Code:
var colSet0 = new Array(0x7D8A2E, 0xC9D787, 0xFFFFFF, 0xFFC0A9, 0xFF8598);
var colSet1 = new Array(0xE6E2AF, 0xA7A37E, 0xEFECCA, 0x046380, 0x002F2F);
which are some Color Sets (taken from the (very nice) Adobe Kuler).
then i want to randomly use one of those sets to color something. So later in my coloring code i use the color set colSet for the coloring. Now ALL i want is to tell colSet to randomly reference one of the predefined color sets... The question is how?
i have tried things like:
Code:
colSet="colSet"+random(2);
but this of course just makes colSet a String...
the temporary solution i gave to my problem is using Switch:
Code:
var colSet = new Array();
function changeColorSet() {
k = random(6);
switch (k) {
case 0 :
colSet = colSet0;
break;
case 1 :
colSet = colSet1;
break;
case 2 :
colSet = colSet2;
break;
}
}
but this doesnt satisfy me, because for every new set i want to add i have to manually alter my code. The plan is for the sets to be loaded from an XML file or something...
So? any ideas?
edit: And while you are at it, is there a way to clear my whole stage from any movie clips i might have attached to it?
AS2 Class Object Referencing
Okay, so I have an object which is derived from mty DrawGrid3d class which works lovely. The draw3d class extends the movie clip class and has a constructor methos which believe it or not builds a 3d grid. Now I cant seem to be able to refer to the objects properties in any way. for example the code below traces out 'undefined'.
Any ideas?
Cheers
Code:
my_grid3d=new DrawGrid3D(_root,130,100,16,16,12,18,176,5.9,0xC5D7FE,0xFFFFFF)
trace("GRID IS:"+my_grid3d._x)
Object Referencing Question
if i've got an MC on the main stage named "mainContact", and this mc has the code:
ActionScript Code:
onClipEvent( load )
{
phpVars = new loadVars();
phpVars.load( "pages/contact.php" );
phpVars.onLoad = function( success )
{
if( success )
{
doneLoad = "true";
}
}
}
i'm wanting to check from within "mainContact" if doneLoad == true, but since it's in the phpVars.onLoad function, doneLoad is registered under phpVars. how can i make doneLoad be referenced under mainContact without using absolute referecing as in, "mainContact.doneLoad = true;"?
Variable Object Referencing
Hello, I just stumbled across your forums today looking for an answer to my question on Google.
I am in no way very knowledgable with ActionScript, so this might be very simple and I am looking in all of the wrong places... but basically here is my issue:
Instead of accessing an objects attributes like this, _level0.thumbnails.thumbnail0._width = 500;
I want to be able to access it with _level0.thumbnails. (this.id) ._width = 500;
where as (this.id) is a variable that could be equal to "thumbnail0" or "thumbnail99" depending on which object gets clicked. I have everything working to if I hardcode thumbnail0 it works fine, and this.id does get set to whatever thumbnail I click's "thumbnail" + ID
... any help?
Dynamic Object Referencing
Hi everyone,
i've built a accordeon like movie clip to present search form results for a web site. The results are "fed" into flash by .NET webservices and the "accordeon" itself is dynamic.
My question is i want to add a button to show further detail on each line of results, but i don't seem to be getting the button to be clickable inside the individual lines.
this is the code i use to build the "accordeon" display:
ActionScript Code:
// _y position
var y = 0;
// _depth
var d = 0;
for (i = 0; i < 13; i++) {
linesArray[i] = i;
d = d + 1;
y = y + 20;
// check for empty (undefined) results and stop adding lines
if (theResults.Collection[i].Referencia == undefined) {
i = numRegistos;
return;
} else {
attachMovie("acordeonLine", "line" + i, d);
// fill the line text boxes
txtRef = myresults.ref;
txtName = myresults.name;
}
// use the line it self as a button to slide open and show photos
this["line"+i].onRelease = function{
trace("HEY! YOU CLICKED ME!");
}
}
inside the each "accordeonLine" mc there's a button called btDetails i'm trying to use by adding this (or similar) code inside the for loop that adds line to the accordeon:
ActionScript Code:
this["line"+i].btDetails.onRelease = function{
trace("HEY! YOU CLICKED ME!");
}
the path this["line"+i].btDetails evaluates as undefined. its like its not even there.
i've tried other "tricks" but i simply can't get the click to work.
Any ideas?
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!
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
Array Referencing Question
Ok, i thought I had this figured out, but no.
Let's say I have an array : _root.stuff.thingy.myArray
it contains 10 names for MCs running around in _root.stuff ... MC1, MC2, etc...
Let's say there's a dude trying to use his teeth to eat those MCs: _root.dude.teeth
when i make the dude's teeth close, I want to do a for loop hitTest on all 10 MCs, so i started writing:
code: for(i=0;i<10;i++){
if(_root.dude.teeth.hitTest(_root.stuff.myArray[i]) {
_root.stuff.myArray[i].gotoAndPlay("open");
}
}
but this obviously won't work because it doesn't target the array. How do I write this?
[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.
Referencing An Existing MC Through An Array
Hey Peeps
ok so I've got a coupla MC's on the stage. I popped their NAMES into an array with the hope of accessing them through the array in a for loop. The problem is that I've entered them into an array using their names, which in essence makes a REFERENCE to their names but not the MC's themselves.
So I've got like this:
Code:
style.group=1;
riviera.group=2;
authenticity.group=1;
var myArray:Array = ["style","riviera","authenticity"];
the problem is that in the for loop when I try and access the property .group it says undefined.
Code:
trace(myArray[i].group); //undefined
This makes sense because I'm refering to the array name, not the actual MC.
SO... the question is. how do I refer to the real MC through the array?
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;
}
}
Array Name Referencing With A Variable
Hey all,
fairly simple question (with a long explaination). I have an array, created from the results of another array and it's position in that array. There are actually multiple arrays It can be created from.
Eg.
Array1: clientName1, clientName2, etc.
Array2: clientType1, clientType2, etc.
Second Array: [clientName1,0], [clientName2,1] OR [clientType1,0] etc.
The code for creating the second array is below:
Code:
for (i=0; i<names.length; i++) {
linkArray[i] = [names[i], i];
}
My issue is, I would like to be able to dynamically adjust the array that it is generating from. This would mean changing the bold bit of the code above.
I have tried declaring a variable (type = names+"[i]") and using it in the linkArray declaration, however it will not see this as an array reference, only as a variable.
What I want to know is, how do I reference the name of the original array as a variable so I can update it dynamically?
Array Name Referencing With A Variable
Hi,
I have several arrays that I am using to populate a listbox, the array to be used is dependent on user selection from a comboBox.
I am trying to figure out how to flexibly change the array used to populate the listbox using a variable, when a different comboBox selection is made.
All possible arrays have the same names as possible values from the combobox, so that if 'list1' was selected from combobox, this would call the array named 'list1.' I need to figure out a way to use the selectedArray variable in the for loop to populate the listbox correctly. (see bolded in code)
ActionScript Code:
var selectedArray = evt.target.getValue(); //selected array from comboBox selection. trace("current list contents: " + _global.listcontent); _root.listbox.removeAll();//clears listbox of previous contentfor(var i = 0; i < <b>selectedArray.length</b>; i++){ var item = new Object(); item.label = i + " - " + <b>selectedArray</b>[i]; item.data = i; _root.listbox.addItem(item.label, item.label);}
What I have there is not working, no array is called, but I'm not sure how to make the variable selectedArray reference a specific array simply by name...
I hope I am explaining what I am trying to do well enough. Any help would be greatly appreciated!
Thanks=]
Referencing An Array Value Globally XML.
Hi guys,
I have been trying to get this right for a few days now, but I am stumped. This code runs on the first frame of my movie:
Code:
_global.headingText = new Array();
_global.captionText = new Array();
_global.contentText = new Array();
_global.photos = new Array();
var spacing:Number = 20;
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success){
if(success){
checkLoad(this);
//_global.myVar = new XML(this);
}else{
trace("error loading");
}
}
my_xml.load("text.xml");
function checkLoad(xml){
for(var i:Number = 0; i<my_xml.firstChild.childNodes.length; i++){
//running through the XML structure to populate the arrays we created up top.
headingText[i] = my_xml.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
captionText[i] = my_xml.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
contentText[i] = my_xml.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue;
photos[i] = my_xml.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue;
//trace(headingText[i]);
}
for(var z:Number = 0; z<my_xml.firstChild.childNodes.length; z++){
duplicateMovieClip("content_mc","content"+z+"_mc",z);
_root["content"+z+"_mc"]._x = (100*z)+650;
content_mc.contentTxt.text = contentText[i];
}
}
evrything loads fine, and all is well. When i try to reference headingText[i] in a movie clips timeline ie myClip's timeline, it does not allow this. I have used _global when creating my variables, as you can see. When in myClip's timeline and I trace(headline) I get the three values for those specific nodes. When i try and trace(headingText[i]) I get an undefined.
I have also tried this:
Code:
_global.myVar = headingText[i] = my_xml.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
but then it only traces the last node value.
What am I doing wrong, this is really getting to me...
thanks in advance.
Array Name Referencing With A Variable
Hey all,
fairly simple question (with a long explaination). I have an array, created from the results of another array and it's position in that array. There are actually multiple arrays It can be created from.
Eg.
Array1: clientName1, clientName2, etc.
Array2: clientType1, clientType2, etc.
Second Array: [clientName1,0], [clientName2,1] OR [clientType1,0] etc.
The code for creating the second array is below:
Code:
for (i=0; i<names.length; i++) {
linkArray[i] = [names[i], i];
}
My issue is, I would like to be able to dynamically adjust the array that it is generating from. This would mean changing the bold bit of the code above.
I have tried declaring a variable (type = names+"[i]") and using it in the linkArray declaration, however it will not see this as an array reference, only as a variable.
What I want to know is, how do I reference the name of the original array as a variable so I can update it dynamically?
Referencing An Array Prob
I can't get this to work.
animal_0=["dog","cat","whale","kangaroo"]
animal_1=["tiger","lion","mouse","elephant"]
trace(animal_0); // this works i.e it traces the entire array
trace("animal_"+"1"); //this doesn't, I guess cus animal+"_1" is a string.
I guess i need the string to refer to the array object somehow. how do i get it to work?
thanks in advance....
Referencing Vars And Mcs W/an Array?
The task is to write an efficient function that will move similarly named child movie clips, which all exist on the same parent. I think an array would be the most efficient way, but I am unable to get it to work, perhaps it won't. This is what I tried, as always, any suggestions will be appreciated.Code:
_global.moveMe = function (who, fromX, toX, fromY, toY, take) {
var tw04:Tween = new Tween(who, "_x", Bounce.easeOut, fromX, toX, take, true);
var tw05:Tween = new Tween(who, "_y", Strong.easeOut, fromY, toY, take, true);
}
// FAILED ATTEMPT TO USE AN ARRAY TO ASSIGN A NAME TO A MOVIECLIP
//The following example uses for..in to iterate over the elements of an array:
var childDestAx:Number = -50;
var childDestAy:Number = 50;
var childDestBx:Number = -75;
var childDestBy:Number = 75;
var parent5Array:Array = new Array("A", "B");
for (var index in parent5Array) {
trace("parent5Array["+index+"] = " + parent5Array[index]);
trace ("Parent5 mc child is: parent5.childQ."+parent5Array[index]);
//I want to identify an existing movie clip using the current array element
var mcName = "parent5.childQ_"+parent5Array[index];
var whoC:MovieClip = mcName;// Name is assigned, but doesn't recognize the existing clip
trace("whoC is: "+whoC);
//I want use the element to get the value from the destination vars above,
// ie. childDest*x
var destX:Number = childDest+parent5Array[index]+x;//Fails miserably
trace("Value of testVar is: "+testVar); //Ends up undefined
moveMe (whoC, whoC._x, destX, whoC._y, -50, 1);
}
Thanks.
M
Sub MC Referencing From Dynamically Named Object
Hello All!
Here's what I'm trying to do. I have a base movie clip with 2 inner movie clips inside it. I am dynamically setting the color of one of the inner movies. Here is my code
code:
sqColor = new Color(_root["square" + j].filler);
sqColor.setRGB(thisColor);
This code sets the color of a movie labeled filler within my "square"+j MC.
Accessing the dynamic variable name through the _root array works fine. HOWEVER! I cannot use the _root array. I am using the loadMovie function in another MC to call this MC. So the _root array is no longer the same and it doesn't work.
Is there another way to do this? I've tried to access the "square"+j object with out the _root reference, but no luck.
Any suggestions? THANKS IN ADVANCE!!
AttachMovieClip - Referencing A Dyamic Object
I have begun using the attachMovieClip() recently to dynamically assign objects to movieclips. Up until now it has been excellent, and is perfect for assigning various enemy sprites to instances of a movieclip etc.
At the moment though i am having problems getting messages through to the 'attached' clip to tell it to stop() or play() etc. The info is a little unclear on this topic, but it seems that if i use code like:
dummy.attachMovie(cat, cat add i, 1);
and then say dummy.stop(), that it only targets the original 'dummy' clip and not the 'cat' movie i have attached. I have tried referencing it with the assigned name, but i must be missing something or doing it wrong, any ideas??
thanks!!
Referencing Object Using Variable Syntax
I'm having trouble referencing an object using a variable in Flash MX.
In this example, I'm dynamically loading jpegs and need to test that they have finished loading.
The img var contains the url of the image to load.
On the first frame:
for(i=0; i<number_of_images; i++)
{
//duplicate the holder
duplicateMovieClip(my_movie.holder, i, i);
//create reference for the img to load
img_to_load = "my_movie.holder." + i;
//load image into the duplicated movie
img_to_load.loadMovie(img_url);
}
On another frame:
if(img_to_load.getBytesTotal() >= img_to_load.getBytesLoaded() )
{
//image has loaded
}else{
//image still loading
}
My problem is that img_to_load is a variable that returns a string and not an object - what do I need to do?
Thanks in advance
[Help] Classes Object Ownership And Referencing
I want to access methods and data of an object A from another object B - which was created in the object A. However, using the _parent property doesn't work. I need an explanation why doesn't it work.
To futher clarify my question, I have a problem when using classes in this way:
code:
class MyClass
{
var Some_Data:MyOtherClass;
function MyClass
{
Some_Data=new MyOtherClass();
}
function DoSomething():Void
{
trace("Did something.");
}
}
class MyOtherClass
{
function MyOtherClass
{
SomeProcedure();
}
function SomeProcedure:Void
{
_parent.DoSomething();
}
}
When I create an instance of the MyClass there is no output. I need an explanation why this is so.
Edited: Have corrected some mistakes in this thread
Timeline Control & Object Referencing
Hi,
I'm wondering what the proper ActionScript is to control a timeline within an event handler function. In an xml.onLoad function I want to send the main playhead to a certain frame based on the content of the XML. The only way I have found to do this is using _root.gotoAndPlay within the {} of the onLoad function; using gotoAndPlay, this.gotoAndPlay, this._parent.gotoAndPlay etc. doesn't work. These would of course work if they weren't within the onLoad function -- thus something about being within an object function changes positioning/referencing of movie clips and timeline control.
_root is a workaround and it's not perfect. any ideas on how to properly control timelines from within functions such as xml.onLoad?
Thanks in advance!
[CS3/AS2.0] Need Some Help... (AS Tween/object Referencing Issue)
Hey guys,
Im trying to create a tween that will animate in any page that i give it. At the moment i have this.
PHP Code:
function pageTransitionIn(i:Number):Void {
new Tween(["big"+i+"_mc"][mask_mc],"_x",Regular.easeInOut,["big"+i+"_mc"][mask_mc]._x,-10,1,true);
}
function pageTransitionOut():Void {
new Tween(["big"+i+"_mc"][mask_mc],"_x",Regular.easeInOut,-10, 700,1,true);
}
pageTransitionIn(1);
My problem is that this code doesn't work, however when i try a specific big1_mc it does:
PHP Code:
function pageTransitionIn():Void {
new Tween(big1_mc.mask_mc,"_x",Regular.easeInOut,big1_mc.mask_mc._x,-10,1,true);
}
function pageTransitionOut():Void {
new Tween(big1_mc.mask_mc,"_x",Regular.easeInOut,-10, 700,1,true);
}
So im obviously just referring to the object wrong. Does anybody know the correct way to refer to big1_mc.mask_mc with i in place of the number so that i can use it for multiple pages? I've tried this and _root but i can't get it working.
Thanks
[F8]Path Independant Object Referencing
Is it possible to reference objects in flash independent of their path. I am using flash as an interface for an external system. The external system used channel messages (1-10000) that I wish to tie to buttons. The buttons may exist on any form within a movie so connecting each incoming channel message the appropriate button in code will be very time consuming. If I could just address the appropriate button via it alias irrespective of its path then I could simply alias my buttons B1 - B10000 and use a simple function to connect the channel message to the button. Any suggestions?
Thanks in Advance
Referencing An Object Created By A Function
Why can't I reference an object created by a function if it has been added to the stage?
For example, I write a function that creates a text field and adds it to the stage:
ActionScript Code:
function makeText():void
{
var myText:TextField = new TextField();
addChild(myText);
}
Now in another function I want to say myText.text = "Hello!", but I get the error "1120: Access of undefined property myText.".
I know it has to do with scope, but how do you access something that's been added to the stage outside of the function that created it?
Button Transparency And Referencing FLA Object From AS3.
I'm using the following graphic and animating the mouth when clicked. Problem is I don't want the CLICK event to dispatch when the transparency is clicked. I know using the flash file I can draw a graphic the shape of my image and place it behind the image and dispatch the click event for the drawn shape, but here's my question.
Is there a better way of doing this for buttons with transparencies?
If not how do reference a drawn graphic in my fla file from my as3 file?
Thanks
Flash Mx Object Referencing Problem
hi there:
I have
loadMovie("bridge1.jpg",_root.pict_dropzone);
in a.swf
this works fine. when a.swf tested alone.
but when b.swf uses code to load a.swf onto b's screen at runtime the line of code above doesn't work
I guess _root.pict_dropzone is the problem and has to be changed to this._root.pictdropzone
where this refers to a.swf
what's the correct syntax for this?
Referencing An Object Inside A Class
and I'm trying to add an event listener and a function to the class, but I keep getting errors of undefined,
I tried just about everthing to be able to refference obj0 can anyone please help?
objGroup.obj0.addEventListener(MouseEvent.CLICK, onClick)
private function onClick (event:MouseEvent):void{
trace ("Click");
}
any help or advice will be greatly appreciated sincerely newwave
---------------this is my complete code - above code-------------feel free to use as you wish----------------------
Attach Code
package {
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import org.papervision3d.core.proto.MaterialObject3D;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;
public class pv3dMyRotation2 extends BasicView {
private static const ORBITAL_RADIUS:Number = 300;
private var angle:Number = 0;
private var obj0:Sphere;
private var obj1:Sphere;
private var obj2:Sphere;
private var obj3:Sphere;
private var obj4:Sphere;
private var obj5:Sphere;
private var obj6:Sphere;
private var obj7:Sphere;
private var objGroup:DisplayObject3D;
public function pv3dMyRotation2() {
super(0, 0, true, false);
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
init3D();
createScene();
startRendering();
}
private function init3D():void {
camera.x = -200;
camera.y = 0;
camera.z = 0;
}
private function createScene():void {
var light:PointLight3D = new PointLight3D(true);
light.x = 400;
light.y = 1000;
light.z = -400;
var M1:MaterialObject3D = new FlatShadeMaterial(light, 0xFF0000, 0xFFCC99);
for(var i=0; i<8; i++) {
this['obj'+i] = new Sphere(M1, 50, 10, 10);
this['obj'+i].x = ORBITAL_RADIUS * Math.cos(angle);
this['obj'+i].z = ORBITAL_RADIUS * Math.sin(angle);
angle += (360 / 8) * Math.PI / 180;
}
objGroup = new DisplayObject3D();
objGroup.addChild(obj0);
objGroup.addChild(obj1);
objGroup.addChild(obj2);
objGroup.addChild(obj3);
objGroup.addChild(obj4);
objGroup.addChild(obj5);
objGroup.addChild(obj6);
objGroup.addChild(obj7);
scene.addChild(objGroup);
scene.addChild(light);
}
override protected function onRenderTick(event:Event=null):void {
objGroup.yaw(1);
super.onRenderTick(event);
}
}
}
Edited: 02/01/2009 at 08:58:22 PM by newwaveboats
|