Strange [] (array Access)
Hi,
Im using Flash MX
i put this line in my script, but it doesn't work:
ii=1;
_parent.imageList.imageMC[ii].gotoAndPlay("down");
The next line does work:
_parent.imageList.imageMC1.gotoAndPlay("down");
The difference is "[ii]" and "1".
Ofcourse i want to use "[ii]", what im i doing wrong?
(I didn't include the rest of the actionscript, because i thinks the problem comes down to what i just told)
FlashKit > Flash Help > Flash ActionScript
Posted on: 07-09-2005, 09:53 AM
View Complete Forum Thread with Replies
Sponsored Links:
[f8] Array Access Notation To Access A MC Within A MC?
Hi,
can one access the contents of a movieclip - that contains another mc - using Array Access notation??
I am loading a bunch of similar (ie, based on the same template) external swfs individually on level0 on the main timeline. because there are many swfs, i want to control the button/mcs in those external swfs from the main timeline. i have a different number of buttons in each swf, and each button goes to a different label. so i am trying to figure how to dettermine the name of the loaded swf, in order to get to the buttons inside that swf...
I was thinking to name each label the same name as the corresponding button object name. and each button/label name be derived from the name of the containing swf... I could put the name of the swf in a variable, and use it as a gotoAndStop() argument...,
i can provide code, but i'm lost and it's gotten messy...
Any ideas GReatly appreciated.
View Replies !
View Related
Strange Linked Array?
hi,
i'm currently doing some stuff for a flash game and have come across an odd problem...
heres the relevent lines of code...
var statsAry = new Array();
statsAry[1] = {utype: "tank", movespeed: 2, ap: 100, hp: 250, mcost: 50, fcost: 50, damage: 75};
_root["unit"+numunits].stats = _root.statsAry[1];
there can be multiple units with the same stats, so i thought the above would be a nice clean way of generating their details
thing is though, when you get into the game and start changing the values e.g.
_root.unit5.stats.ap = 50;
it not only changes that unit, but all other units of the same type *and* the initial root array?? why?? :/
View Replies !
View Related
Strange Array Issue I Think
i have the following code which loads the values from an xml,
what happens is that it appears that every call to polys[i].Points[0] = someValue makes every other element in the polys array Points[0] object = someValue
Code:
//sets the arrays to the loaded lengths
polys = new Array(parseInt(meshXML.firstChild.firstChild.firstChild.nodeValue));
//loads the polygons
for(var i:Number = 0;i<polys.length;i++)
{
//gets the polygons points indexes
polys[i] = new Polygon();
polys[i].PointsI[0] = new Number();
polys[i].PointsI[0] = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.p1);
polys[i].PointsI[1] = new Number();
polys[i].PointsI[1] = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.p2);
polys[i].PointsI[2] = new Number();
polys[i].PointsI[2] = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.p3);
//gets the texture coords for the points
polys[i].tCoords[0] = new Vector2();
polys[i].tCoords[0].x = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.tx1);
polys[i].tCoords[0].y = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.ty1);
polys[i].tCoords[1] = new Vector2();
polys[i].tCoords[1].x = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.tx2);
polys[i].tCoords[1].y = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.ty2);
polys[i].tCoords[2] = new Vector2();
polys[i].tCoords[2].x = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.tx3);
polys[i].tCoords[2].y = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.ty3);
//sets which texture it uses
polys[i].TextureI = parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.texture);
}
for(var i:Number = 0;i<polys.length;i++)
{
trace(polys[i].PointsI[0] + " : " +parseInt(meshXML.firstChild.childNodes[4].childNodes[i].attributes.p1));
}
and you get this output
the numbers on the left are the values stored in polys[i].PointsI[0] and the
values on the right are the values in the XML
Code:
5 : 0
5 : 0
5 : 1
5 : 1
5 : 2
5 : 2
5 : 0
5 : 3
5 : 0
5 : 1
5 : 4
5 : 5
how do i make a call to polys[i].Points[i] = someValue not effect every other polys[].Points[i] value?
View Replies !
View Related
Array How To Access
after initializing an Array we need to add values to them
then access them back. my array[0] but it's difficult on the
real world is it ? we need a little bit description for
can some one do that ? plz some one do as bulid a students and their marks how to intili and Declare and access them if some can ?
View Replies !
View Related
Array Access
I've created an array and everytime you click a button it inserts a value at the end. but how can I use the last entry of the array?
I thought I could do something like this:
varTest = mainArray.length
mainArray[varTest]
and this would access the last entry? but it doesnt seem to work
View Replies !
View Related
Access Array By Name
Hi,
I need to access array by name. Could anyone suggest how to do it. Accessing Object by name works fine with eval:
Code:
myObject = new Object();
myObject.myVariable = "this is variable";
trace(eval("myObject.myVariable"));
But this is not working:
Code:
myArray = new Array();
myArray[0] = new Object();
myArray[0].myVariable = "this is variable";
trace(eval("myArray[0].myVariable"));
Thanks
View Replies !
View Related
Can't Access Array
I have a MovieClip "tableCell_mc" that is added to the stage via AS3. This MovieClip has a few variables that I have declared within it. These variables are as follows:
var tableCellHomeX:int;
var tableCellHomeY:int;
var myChildren:Array = new Array();
stop();
I use these to store unique data to each instance of tableCell_mc.
I can access the tableCellHomeX and tableCellHomeY vars no problem. It's the myChildren:Array that I'm having trouble with. It's an empty array but as I go through my for loop I try to add values to that array like so.
ActionScript Code:
function makeTable(theXMLList:XMLList) {
var theXMLListAttribs:XMLList = theXMLList[0].attributes();
for (var i:int = 0; i < theXMLListAttribs.length(); i++) {
tableHeader = new tableCell_mc();
tableHeader.width = stage.stageWidth / theXMLListAttribs.length();
tableHeader.x = 0;
tableHeader.y = 100;
tableHeader.tableCellHomeX = tableHeader.width * i;
tableHeader.tableCellHomeY = 100;
tableHeader.cellValue_text.text = theXMLListAttribs[i].name();
tableHeader.addEventListener(Event.ADDED_TO_STAGE,slideToRight);
tableHeader.addEventListener(TweenEvent.MOTION_FINISH, dummyFunction);
addChild(tableHeader);
for (var j:int = 0; j < theXMLList.length(); j++) {
var myAttribs:XMLList = theXMLList[j].attributes();
tableHeader.myChildren[j] = String(myAttribs[i]);
}
}
}
I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SpreadSheet_fla::MainTimeline/makeTable()
at SpreadSheet_fla::MainTimeline/frame2()
Help anyone?
Thanks,
Rich
View Replies !
View Related
Access To Array
I have duplicated 10 movies and give them different instance names. I also create an array called myArray which hold 10 elements. Now I want it to be like this... when I place the mouse over a movie, says "box1", I want it to show myArray[0]; "box2" shows myArray[1]; and so on.. how can I do that?
i tried..
on(rollOver){
_root.x = 1;
if (this._name == "box1"){
_root.popUp1.popText = explanation[0];
} else {
_root.popUp1.popText = explanation[1];
}
}
but it didn't work. please help.
thank you.
View Replies !
View Related
Can't Access Value In Array - Please Help
I have written the following code, and the function called by mcListener.onLoadComplete is returning the current value in the array as "undefined." I want the current image that has finished loading to fade in, but "i" seems to have no meaning within the function. If i replace the [i] with a number, it works fine. I think this is a scope issue but I can't figure it out. Any help is much appreciated.
HTML Code:
var thumbArray:Array = new Array;
var mcListener:Object = new Object;
var photoHolderLoader:MovieClipLoader = new MovieClipLoader;
photoHolderLoader.addListener(mcListener);
function creMenu(){
for (i=0; i<total; i++) {
var smallIm:MovieClip = smallPic.attachMovie("thumb","thumbNail"+i,i);
thumbArray[i] = smallIm;
thumbArray[i]._x = xPos[i];
thumbArray[i]._y = 0;
thumbArray[i]._alpha = 0;
photoHolderLoader.loadClip(image[i], thumbArray[i].inner_mc);
mcListener.onLoadProgress = function(){
trace("LOADING");
};
mcListener.onLoadComplete = function(){
trace(thumbArray[i]);
};
smallIm.picVal = i;
//THUMBS ROLLOVER/RELEASE
thumbArray[i].onRollOver = function(){
this.alphaTo(50,1,"easeOutExpo");
};
thumbArray[i].onRollOut = function(){
this.alphaTo(100,1,"easeOutExpo");
};
thumbArray[i].onRelease = function(){
largePic.workPicMask.scaleTo(100,.5,"easeOutExpo");
smallPic.alphaTo(0,.5,"easeOutExpo");
p = this.picVal;
largePic.picture.loadMovie(large[p], 1);
largePic.desc_txt.text = caption[p];
picture_num();
};
};
}
View Replies !
View Related
Access Array By Name
Hi,
I need to access array by name. Could anyone suggest how to do it. Accessing Object by name works fine with eval:
ActionScript Code:
myObject = new Object();
myObject.myVariable = "this is variable";
trace(eval("myObject.myVariable"));
But this is not working:
ActionScript Code:
myArray = new Array();
myArray[0] = new Object();
myArray[0].myVariable = "this is variable";
trace(eval("myArray[0].myVariable"));
Thanks
View Replies !
View Related
Is This Strange Array Related Result A Bug ?
Try the following code in Flash CS3
Code:
var myArray:Array = [-9.1];
while(myArray[0]++ < 0){
trace (myArray[0]);
}
var i = -9.1;
while(i++ < 0){
trace (i);
}
The result is two identical set of values. Now try this
Code:
var myArray:Array = [-9.1];
while(++myArray[0] < 0){
trace (myArray[0]);
}
var i = -9.1;
while(++i < 0){
trace (i);
}
Now the results are different. The array values are converted into integer values. Is this a bug or is it supposed to be like this ?
Edit:
This only happens when compiling as AS3. When you compile the same code as AS2 in both cases the sets are identical
View Replies !
View Related
[mx04] Strange Problem With For(i In Array)
I wasted several hours yesterday while trying to change the depths of a couple of MovieClips stored in an array:
Code:
for(i in bug)
{
bug[i].swapDepths(4000+i);
trace(i + " depth " + bug[i].getDepth());
}
As I hadn't used swapDepths() before, I assumed I was doing something wrong with it. But nothing seemed to work - their original depths remained unchanged. Then, just in case, I changed to a normal for loop:
Code:
for(i=0; i<no_bugs; i++)
{
bug[i].swapDepths(4000+i);
trace(i + " depth " + bug[i].getDepth());
}
And suddenly everything works like expected... Can someone please explain this?
View Replies !
View Related
Strange Array Sort Problem
Hi,
I am trying to randomly fill an array with 36 numbers 1-36.
I have some code that works but when I try to wrap around an if statement with a randomise on or off boolean the sorting will not work - i.e. the array just fills sequentially whether randomise is set to true or false. It seems the array fills but the sort code is not being executed.
THIS WORKS
-------------------------------------------------------
//
//
for (var i:Number = 1; i<=36; i++) {
myArray.push(i);
}
myArray.sort(shuffle);
function shuffle(a, b):Number {
return Math.round(Math.random()*2)-1;
}
-------------------------------------------------------
BUT THIS DOESNT
-------------------------------------------------------
var randomise:Boolean = true;
//
if(randomise==true){
for (var i:Number = 1; i<=36; i++) {
myArray.push(i);
}
myArray.sort(shuffle);
function shuffle(a, b):Number {
return Math.round(Math.random()*2)-1;
}
}
------------------------------------------------------
No doubt its something easy to solve but I am really confused.
Any Help Appreciated
Paulie
View Replies !
View Related
Array Of Objects - Strange Problem
Hello everyone,
I posted earlier for the first time, but deleted my message as it wasn't giving a clear picture of what is going on.
I am having some very strange problems concerning accessing an array of objects. First of all, let me tell you what I am doing. Please bear with me here.
I have a class called Player, which has a public property Array called points. I create an array of Player objects from within the Demo class, and that works fine.
The points array is initialized for each Player object in a the Demo class as an empty array of a given length. From within Demo, I fill parts of points with data. This data is of a class called XYPoint, so what I do is
Code:
players[x].points[y] = new XYPoint();
Later, I try to access this data using players[x].points[y]. I either get undefined or null, depending on some other factors. When I trace points, I seem to get an array of the correct length but without any values.
Now, I'd be inclined to think that I'm having troubles adding data to the array. However, when I run the debugger, I can see for each element in players a correct array length, and the correct value (XYPoint) for those elements that should have data. Not only that, but the XYPoint has the correct data too.
If the debugger confirms that there is data of the correct type in this array, why do I get null or undefined when I try to access the data?
Note: To access the data, I am using
Code:
var myPoint:XYPoint = players[x].points[y];
I hope this has made some sense, and someone at least understands why this is confusing me. Hopefully there is a simple explanation.
Many thanks in advance!
View Replies !
View Related
Strange Problem Referencing Array
flash mx 2004
i an array created which references an number of objects.
for some reason i can't get the length of the array or reference any of its elements.
When i test the movie and check the variables, the damn thing exists! See....an array located on _level0 with 3 objects stored in it
Variable _level0.box_ref_array_full = [object #62, class 'Array'] [
0:[object #63, class 'Box'] {
path:[movieclip:_level0.box1]
},
1:[object #64, class 'Box'] {
path:[movieclip:_level0.box2]
},
2:[object #65, class 'Box'] {
path:[movieclip:_level0.box3]
}
]
but when i run the following traces on it, all of them return a big 0;
trace ("box_ref_array_full.length=" + box_ref_array_full.length);
returns 0
trace ("_root.box_ref_array_full.length=" + _root.box_ref_array_full.length);
returns 0
trace ("_level0.box_ref_array_full.length=" + _level0.box_ref_array_full.length);
returns 0
This makes no !@$!@#$!%@$% sense!!!!!
Any ideas?
Thanks for any help
View Replies !
View Related
Dynamic Array Access
Hi,
I'm trying to take a sentence and break it into an array of words (done) then take the words and break them into arrays of letters. I was able to do a sloppy bit of code and make a buch of variable but I'd kinda prefer to do it with arrays cuz it's a whole lot cooler.
anyway here is the mucked up code for the variable generation just so you can see what I was trying to do
on (release) {
words = v_1.split(" ");
for (i=0; i<words.length; i++) {
for (l=0; l<words[i].length; l++) {
set ("word"+i+"["+l+"]", words[i].charAt(l)
);
}
}
}
and here is the array generation code as it stands now
on (release) {
words = v_1.split(" ");
for (i=0; i<words.length; i++) {
set ("word"+i, []
);
for (l=0; l<words[i].length; l++) {
set ("word0"+[l], words[i].charAt(l));
}
}
}
I can create the arrays OK but it's the last line of code where I try to populate them that's not working - where it says "word0"... I had tried "word" + i + [l] and it disregards the [] so it I know there is something I'm doing wrong with the syntax
Thanks to all who give this some thought
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
View Replies !
View Related
How To Access Array Elements?
hi, i'm currently trying to use arrays for the first time, and i've made a simple array myArray with 50 elements 1, 2, 3... 50. but i encounter a problem that makes me suspect that i don't understand the array concept at all: how can i access the value of an element in the middle of the array?
failed attempt #1: why is trace(myArray[x]) undefined and not simply x?
failed attempt #2: i tried to make a new array with the slicing method (referred to in flash help), like myArray.slice(x,x+1). then i reckoned i could access the element from this new array by the pop or shift method. but where on earth IS this new array, and what's the name of it??
failed attempt #3: an expression like
secondArray=myArray.slice(x);
myVariable=secondArray.shift();
didn't work either.
EXTRA QUESTION (OPTOINAL...) what i'm planning to make is an application that jumps between 50 frames, just one visit in each, in a random order. i will use the array to accomplish this, by deleting one element after each frame is visited, in order to avoid a condition for testing whether a frame has been visited (don't know if this was understandable). am i on the right track by using arrays or is there another/simpler way?
View Replies !
View Related
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.
View Replies !
View Related
Urgent - Array Access
I can load the variables I need into an array with the following, BUT...outside of the success function, how can I access the array variables?
code: var navVars = new LoadVars();
navVars.load("variables1.txt");
navVars.onLoad = function(success) {
if (success) {
//trace that the variables have loaded
//trace("success")
//trace the type of object you are dealing with
//trace(typeof (this.level1));// string
//split the varibles into their respective arrays
this.navArray1=this.level1.split(":");
this.navArray2=this.level2.split(":");
trace(typeof (this.navArray1));
trace(this.navArray1.length);// 4
trace(this.navArray1[0])
array_length = this.navArray1.length;
for (i=0; i<array_length; i++) {
trace(this.navArray1[i]);
}
}
};
View Replies !
View Related
Urgent - Array Access
I can load the variables I need into an array with the following, BUT...outside of the success function, how can I access the array variables?
code: var navVars = new LoadVars();
navVars.load("variables1.txt");
navVars.onLoad = function(success) {
if (success) {
//split the varibles into their respective arrays
this.navArray1=this.level1.split(":");
this.navArray2=this.level2.split(":");
trace(typeof (this.navArray1));
trace(this.navArray1.length);// 4
array_length = this.navArray1.length;
for (i=0; i<array_length; i++) {
trace(this.navArray1[i]);
}
}
};
View Replies !
View Related
XML And Array Access Issues
I'm learning to work with XML files in Flash, and making some headway. But here's an issue I've come up against hard.
I'm dynamically creating buttons on stage based on the number of certain childNodes; then placing text into these button instances. This works fine. However, I have childNode data related to these buttons. When the user clicks a particular button, text fields will be populated with data related to that button.
I've got all the XML data stored in an array, and naturally my buttons are created using an array. I'm sure there's a way to correlate the info from one array to the other, but I just can't seem to puzzle it out.
Can anyone point in the right direction?
View Replies !
View Related
Array Access Notation
Im trying to be dynamic here in creating movie clips on the fly with
Code:
var source[inc]:MovieClip = this.createEmptyMovieClip("source"+curX, this.getNextHighestDepth());
inc is incrementing each time to make source0, source1 etc
syntax error though??
View Replies !
View Related
How To Access Dynamic Mc In An Array?
Hi,
I'm creating instances of a movieclip in the library dynamically, then i want to animate them (make them drop from the top to bottom). But I can't figure out how to access them in my array.
They are in there, they come up in a trace, but using a loop through them (on enter frame) and trying to change y value doesn't work? I have my array registered at the top of the class, and get no errors..
Code:
// randomly create treasures with timer (WILL MOVE TREASURES WITH TIMER ASWELL)
public function createTreasures(){
var rand:Number = (Math.ceil(Math.random()*2000))
var timer:Timer = new Timer(rand);
timer.addEventListener(TimerEvent.TIMER,timerF);
timer.start();
treasures = new Array();
function timerF(event:TimerEvent):void{
var treasure:MovieClip = new Treasure();
treasure.x = (Math.ceil(Math.random()*800));
treasure.y = 0;
//random treasure type
treasure.type = Math.ceil(Math.random()*5);
treasure.gotoAndStop(treasure.type);
treasure.speedY = Math.random() * 5 + 2;
treasure.inAir = true;
treasure.width = 20.0;
treasure.height = 40.0;
//keep treasures with min/max boudary
if (treasure.x<100){
treasure.x = treasure.x + 100;
}
else if(treasure.x>700){
treasure.x = treasure.x -100;
}
//add to stage
addChild(treasure);
//push into array
treasures.push(treasure);
}
}
//loop through treasures
public function moveTreasures(timeDiff){
for(var i:int=0;i<treasures.length;i++){
// add to treasures y value
treasures[i].y = treasures.y + 100;
}
}
http://www.actionscript.org/forums/i...s/rolleyes.gif
View Replies !
View Related
Array Access In An Object
I've encountered another problem.
The following code does not mention that I have a MovieClip in the Library set up with its class as my_class. I drag it onto the stage and name it my_object. When I try to use the my_array property it does not work.
The class includes a boolean property that works fine, so I concluded that my arrays must be discombobulated. I also tested a string property and it works.
Plz help?
Attach Code
/////---------
class my_class extends MovieClip
var my_array:Array;
}
/////---------
//my_object <- is instance of my_class
my_object.my_array[0] = "rasin";
trace(my_object.my_array[0]) // returns undefined. why?
View Replies !
View Related
How To Access This Array Element
Here's the function :
Code:
var curItem;
function disableAll(){
for (var i=0;i<buttonArray.length;i++){
trace(buttonArray[i])
}
}
Here's the problem/question :
- I want to assign the var curItem into the onRelease function throughout the buttonArray. How?
View Replies !
View Related
Array Access Notation In AS3
how to make something like this work
Code:
var i:uint;
for(i=0;i>3;i++){
var test[i]:Sprite = new Sprite();
test[i].graphics.beginFill (0xff000000);
test[i].graphics.drawRoundRect (0, 0, 50, 50, 0, 0);
test[i].graphics.endFill ();
addChild(test[i]);
test[i].y = 55 * i;
};
Code:
1086: Syntax error: expecting semicolon before leftbracket.
var test[i]:Sprite = new Sprite();
View Replies !
View Related
Variables With Array Access ?
hello
pretty new to actionscript 3.0 and was wondering why this doesnt work
Code:
var bonkers:Array = new Array(i);
bonkers[0] = new oldie();
bonkers[1] = new chtv();
bonkers[2] = new every();
bonkers[3] = new jerkwtv();
bonkers[4] = new hawtv();
var i:int;
var myTimer:Timer = new Timer(delay, repeat);
var delay:uint = 30000;
var repeat:uint = 6;
//-- MovieClips & Sprites --\
for (i = 0; i < 5; i++);{
addChild(bonkers).name = "bonkers" + i;
bonkers.x = 320;
bonkers.y = 214.5;
}
and i have tried this many different ways with the addChild()
Code:
for (i = 0; i < 5; i++);{
bonkers[i].addChild();
bonkers.x = 320;
bonkers.y = 214.5;
}
Code:
for (i = 0; i < 5; i++);{
addChild(bonkers[i]);
bonkers.x = 320;
bonkers.y = 214.5;
}
I get different ranging errors 2007, 1010 and others. Any help would be great.
View Replies !
View Related
How To Access Data In An Array?
I need to move my targets in the "onBubblaKlick"-function to the x and y positions defined in the bubblaData-Array (marked in red). But I can't figure out how to access them? Any solutions out there?
Code:
var bubblaArray:Array = [];
var bubblaData:Array = [[56, 432, .5, "picknick", "Text", 1, 34],
[ 182, 408, .6, "restaurang", "Text", 70, 789],
[ 322, 245, .7, "vindkraft", "Text", 63, 300],
[ 334, 427, .8, "varutransport", "Text", 70, 150],
[ 522, 636, .9, "dagvatten", "Text", 70, 542],
[ 605, 489, 1, "cyklist", "Text", 20, 300],
[ 735, 185, 1.1, "lagenhet", "Text", 70, 150],
[ 880, 159, 1.2, "solceller", "Text", 70, 150],
[ 935, 422, 1.3, "kollektivtrafik", "Text", 200, 300]];
// Animera in bubblorna
for (var i:Number = 0; i < 9; i++)
{
var a:Bubbla = new Bubbla();
var placeBubbla:Object = { _scale:1, time:2, transition:"easeoutelastic", delay:bubblaData[i][2] }
var bubblaX = bubblaData[i][0];// x-position
var bubblaY = bubblaData[i][1];// y-position
var bubblaName = bubblaData[i][3];// vilket scenario
var infoText = bubblaData[i][4];// scenario-rubrik
var moveX = bubblaData[i][5];
var moveY = bubblaData[i][6];
a.scaleX = a.scaleY = 0;
a.filters = [shadow];
a.x = bubblaX;
a.y = bubblaY;
a.name = bubblaName;
a.bubblaText_txt.text = infoText;
a.bubblaText_txt.alpha = 0;
Tweener.addTween( a, placeBubbla );
addChildAt ( a, 1 );
bubblaArray.push(a);
a.addEventListener( MouseEvent.CLICK, onBubblaKlick );
a.addEventListener( MouseEvent.ROLL_OVER, bubblaStor );
a.addEventListener( MouseEvent.ROLL_OUT, bubblaLiten );
}
// Klick på bubblorna
function onBubblaKlick( evt:Event ):void {
var target = evt.currentTarget;
Tweener.addTween( target, { _scale:2.5, x:moveX, y:moveY, time:1, transition:"easeoutlinear" } );
for ( var p in bubblaArray ) {
if ( bubblaArray[p] != target ) {
Tweener.addTween( bubblaArray[p], fadeBubbla );
}
}
target.removeEventListener( MouseEvent.CLICK, onBubblaKlick );
target.removeEventListener( MouseEvent.ROLL_OVER, bubblaStor );
target.removeEventListener( MouseEvent.ROLL_OUT, bubblaLiten );
var myRequest:URLRequest = new URLRequest ( "scenario/"+target.name+".swf" );
myLoader.load ( myRequest );
}
View Replies !
View Related
How To Access Dynamic Mc In An Array?
Hi,
I'm creating instances of a movieclip in the library dynamically, then i want to animate them (make them drop from the top to bottom). But I can't figure out how to access them in my array.
They are in there, they come up in a trace, but using a loop through them (on enter frame) and trying to change y value doesn't work? I have my array registered at the top of the class, and get no errors..
Code:
// randomly create treasures with timer (WILL MOVE TREASURES WITH TIMER ASWELL)
public function createTreasures(){
var rand:Number = (Math.ceil(Math.random()*2000))
var timer:Timer = new Timer(rand);
timer.addEventListener(TimerEvent.TIMER,timerF);
timer.start();
treasures = new Array();
function timerF(event:TimerEvent):void{
var treasure:MovieClip = new Treasure();
treasure.x = (Math.ceil(Math.random()*800));
treasure.y = 0;
//random treasure type
treasure.type = Math.ceil(Math.random()*5);
treasure.gotoAndStop(treasure.type);
treasure.speedY = Math.random() * 5 + 2;
treasure.inAir = true;
treasure.width = 20.0;
treasure.height = 40.0;
//keep treasures with min/max boudary
if (treasure.x<100){
treasure.x = treasure.x + 100;
}
else if(treasure.x>700){
treasure.x = treasure.x -100;
}
//add to stage
addChild(treasure);
//push into array
treasures.push(treasure);
}
}
//loop through treasures
public function moveTreasures(timeDiff){
for(var i:int=0;i<treasures.length;i++){
// add to treasures y value
treasures[i].y = treasures.y + 100;
}
}
http://www.kirupa.com/forum/images/smilies/sonic.gif
spank you
View Replies !
View Related
Access Random Array
Hi,
I have some arrays as below:
Code:
var Q1 = new Array("What Colour is the sky",1, "blue", "green", "black");
var Q2 = new Array("What Colour is the grass",2, "pink", "green", "yellow");
var Q3 = new Array("What Colour is the road",2, "blue", "green", "black","yellow");
I know how to access a certain array and element i.e. Q1[0]
But how can I access an array at random e.g Qi[0];
I have generated a random number, just need to know how to use it in accessing the array, ive tried this "Q"+num[0] where num is the random number.
Any help will be great thanx
View Replies !
View Related
Strange Multidimensional Array Logic Error
Hello all, long time lurker, first time poster...
I was trying to build an array containing arrays of coordinates.
After reviewing many posts on this board and other places on the web I figured out how to make this piece work like this:
ActionScript Code:
var multiArray:Array = new Array;
for (var i:uint = 0; i < 3; i++) {
multiArray[i] = new Array;
for (var j:uint = 0; j < 2; j++) {
multiArray[i][j] = Math.round(Math.random()*10);
}
trace("i = " + i);
trace("multiArray = " + multiArray);
}
/*
Output is:
i = 0
multiArray = 9,10
i = 1
multiArray = 9,10,7,8
i = 2
multiArray = 9,10,7,8,4,9
*/
However, I cannot for the life of me figure out why this doesn't also work. Why does it go back and change position 0 and 1 of the multiArray?
ActionScript Code:
var multiArray:Array = new Array;
var holderArray:Array = new Array;
for (var i:uint = 0; i < 3; i++) {
for (var j:uint = 0; j < 2; j++) {
holderArray[j] = Math.round(Math.random()*10);
}
trace("i = " + i);
trace("holderArray = " + holderArray);
multiArray[i] = holderArray;
trace("multiArray = " + multiArray);
}
/*
Output is:
i = 0
holderArray = 9,4
multiArray = 9,4
i = 1
holderArray = 3,2
multiArray = 3,2,3,2
i = 2
holderArray = 5,3
multiArray = 5,3,5,3,5,3
*/
I am standing by waiting for the doh! headslapping moment...
View Replies !
View Related
Strange Array Problem + MaxValue Tutorial
Hi everyone,
I've run into a weird problem with regards to my maxValue function (http://www.kirupa.com/developer/acti...ay_max_min.htm) and an array.
In one scenario, I am using an array that was populated with data from an XML file. I am going to pass that data to my maxValue function. Prior to passing the array to the maxValue function, I trace my array to make sure that all of the values have been loaded. When I pass that array to the following maxValue function:
ActionScript Code:
maxValue = function (array) {mx = array[0];for (z=0; z<total; z++) {if (array[z]>mx) {mx = array[z];}trace(z+" "+mx+" "+array[z]);}return mx;};
I get the following output:
Quote:
0 43 43
1 54 54
2 99 99
3 99 234
4 99 223
5 99 432
6 99 405
7 99 151
The first number is the index number, the second number is the value of the mx (maximum) number, and the third number is the current number in our array. Obviously, this isn't correct for the value for maximum does not change beyond 99. For example, 99 is not greater than 234 as shown by the output.
What is strange, though, is if I pass the same data from an array I declare with values manually filled in as opposed to being filled in from an XML file, I get the correct output:
Quote:
0 43 43
1 54 54
2 99 99
3 234 234
4 234 223
5 432 432
6 432 405
7 432 151
What I don't understand is that both arrays contain the same value, and they both are completely filled prior to the call to maxValue, yet the array filled with data from the XML file is giving me erronous results.
Does anybody have any idea as to why that is occuring? I can post an FLA + XML file if you all want.
Thanks!
Kirupa
View Replies !
View Related
Strange Array Behaviour- Seems To Be Dumping Values
Hey guys,
Meet my new app- a WIP flash site that builds it's nav and content from a DB:
http://www.chrisdidthis.com/warnerph...rnerphoto.html
I've set up a slideshow that runs in loop- it's not very elegant at the moment, but before I go on working to refine it's functionality, i've run into a problem-
I'm pulling values for my image names from an array of names- I have a value( i ) that increments up and determines the array index to pull the infromation from. This value resets to 0 when it reaches the end of the array and starts from zero again.
Everything works perfectly the first time that i is climbing towards it's reset value, however, when i reset it back to 0, the array stops returning values for [i]images_array- it returns undefined for my image names. If you view the link above, you'll see that the slideshow just stops after it's cycled through all the images. = |
I'm totally stuck on this one, anyone heard of this before? I've pasted in my code here, highlighting the important (i.e not working) bits in black.
Thanks in advance everyone
++counter;
if (counter == frequency) {
counter = 0;
++loader_depth;
loader_name = "loader_"+i;
trace ("changing image, array length = "+images_array.length+", i = "+i);
duplicateMovieClip (image_loader_mc, loader_name, loader_depth);
this[loader_name].image_name = images_array[i];
//
if ((i+1) == images_array.length) {
i = 0;
}
++i;
}
gotoAndPlay (2);
Also, here are my image creation lines that happen a few frames previously- just in case
images_array = new Array ();
var frequency:Number = 90;
var counter:Number = frequency - 5;
var i:Number = 0;
var loader_depth:Number = 1
View Replies !
View Related
Array Access Difficulties - Tell Me What I'm Doing Wrong...
Hi,
I'm drawing a line chart that takes its data from a .txt file, converts that data into arrays, and is supposed to draw a line chart from duplicated movie clips....but doesn't.
OK, converting the data from the .txt file into arrays and duplicating movie clips works dandy - Flash Player can see the arrays and the duplicated movie clips show up exactly as I want them - but the chart doesn't draw out.
I want the script to take a cloned movie clip and to send it to frame X, where X is a value in an array, thus:
for (n=0; n<NavDot.length; n++) {
bnav = "NavDot" add n;
duplicateMovieClip ("NavDot", bnav, n+250);
if (Number(n) == 0) {
// Positions the clip on stage
setProperty (bnav, _x, NavDot._x);
bnav.gotoAndStop(NavPlot[n]);
} else {
//Positions the clip on stage
setProperty (bnav, _x, Number(getProperty(bnav, _x)+Number((n-1)*(getProperty(bnav, _width))));
bnav.gotoAndStop(NavPlot[n]);
}
}
...I also tried
for (j=0; j<NavPlot.length; j++) {
tellTarget ("NavDot" add j) {
gotoAndStop (NavPlot[j]);
}
}
But they don't work. The script has no syntax errors, all the movie clip instances are named correctly on stage, so I can't tell what I'm doing wrong...but it sure don't wanna go to frame (NavPlot[n]). The movie clip is simply a little square, motion tweened over 1000 frames(I've used this before so I know it works), and the value in the array should tell that movie clip where to go, but they all remain in frame 1.
Any clues?
Thanks
Lassi
View Replies !
View Related
Help With Syntax (array Access Operator)
Hi,
I am trying to address a ""clipC" + n " without "dot" operator and identifyier. The problem is, it lives in a clip whose name I can't write out either.
I tried this
--------------------------------------------------------
clipA["clipB"+n][clipC" + n].doSomething
--------------------------------------------------------
but to no avail. Can anyone help me with the syntax?
View Replies !
View Related
Access Nested Clip From Array
aMCs = ["movieClipA","movieClipB","movieClipC"];
a = aMCs[0];
b = aMCs[0] +"."+ aMCs[1];
trace(typeof b + " B " + b); // movieClipA.movieClipB
goto(a); // i work
goto(b); // i fail
goto(movieClipA.movieClipB.movieClipC); // i fail
function goto(clips){
trace(typeof clips +" IN "+clips);
_root[clips].gotoAndStop(2)
};
//movieClipA.movieClipB.gotoAndStop(2); //ok
how can i access the timeline of a nested clip
using the array of movie clip instance names ??
tia
a_void();
View Replies !
View Related
Dynamic Array Access String
My apologies if this is the wrong term, Don't know what to call it thus making it difficult to search for!
I am trying to do make NewVar return "three" (myArray[3])
myArray = ("one","two","three","four");
YourArray = ("A","b","c","d");
WhichArray = "myArray";
i="3";
ArrayString = (WhichArray + "[" + i + "]");
trace(ArrayString); //output = MyArray[3]
trace(eval(ArrayString)); //output = undifined
NewVar = ArrayString
trace(NewVar) //output = MyArray[3], desired result = Three
Any help would be much appreciated as well as make my brain stop hurting.
MrKicks
View Replies !
View Related
How Can I Access The Value Of An Array Index (or Key) Number?
how can i access the value of an array index (or key) number?
I know how to get the value of the array (large_array[0], but I can't find how get the actual number, i.e., 0, 1, 2, etc. I want to access corresponding values in other arrays, as in: if btn2_mc (of the btn_array [btn0_mc, btn1_mc,...] ) is clicked, it hides redGraphic2_mc (of the redGraphic_array [redGraphic0_mc, redGraphic1_mc, ...]) and so on for other arrays. Using Flash 8...
Thanks!
View Replies !
View Related
Array Access Operator Output
I'm using this code so set the onrollover/out behaviour of 15 clips at once, using the array access operator:
Code:
for (var i:Number = 1; i<=14; i++) {
this["btn"+i].onRollOver = function() {
this.gotoAndStop(2);
};
this["btn"+i].onRollOut = function() {
this.gotoAndStop(1);
};
}
That works fine, but the problem is getting the i value back, so I can get the number back depending on which clip receives the onRollOver.
I tried this:
Code:
for (var i:Number = 1; i<=14; i++) {
this["btn"+i].onRollOver = function() {
this.gotoAndStop(2);
trace(i);
};
this["btn"+i].onRollOut = function() {
this.gotoAndStop(1);
};
}
But that always traces 15 back. How can I get the right number back? So when btn10 gets the onrollover I want it to trace 10.
View Replies !
View Related
Create Array On Load To Access Everywhere
i need to create an array within an onload function that is accessibly everywhere in a script. how can i do this? i think i could create the array outside of the function, then fill it inside the function, and use it elsewhere. what is the syntax for the initialization and passing of the array?
View Replies !
View Related
Access Array In Document Class
Hi all - I've created an array in my document class as public:
public var colourArray:Array = new Array(0x0000FF,0xFF0000,0x00CC00,0xFF00FF,0xFFFF00 ,0xFF9900,0x9900FF);
then, another class is trying to access that array:
newColour.color = colourArray[randomColourNumber];
but I'm getting the folowing error:
1119: Access of possibly undefined property colourArray through a reference with static type flash.displayisplayObject.
any thoughts?
View Replies !
View Related
How To Access Array In External Class
I'd like to store a bunch of arrays in an external file. I'm not sure if this is the only approach, but I created an external class which I think import:
Code:
import Glossary;
(and in one of the functions refer to the array this way)
tField.htmlText = glossaryArr[0].term;
tField.htmlText += glossaryArr[0].definition;
And I'm setting up the external class like this:
Code:
package {
public class Glossary {
static public var glossaryArr:Array;
public function Glossary() {
glossaryArr:Array = new Array();
//TERM 1////////////////////////////////////
glossaryArr[0] = new Object();
glossaryArr[0].term = "Food and Drug Administration (FDA)";
glossaryArr[0].definition = "The FDA is an agency of the U.S. Department of Health and Human Services (HHS), which is responsible for ensuring the safety and effectiveness of all drugs, biologics, vaccines, and medical devices.";
}
}
}
But I get an error from the main file:
Code:
1120: Access of undefined property glossaryArr.
Is this the right way to approach this?
View Replies !
View Related
Eval And Array Access Operator(?)
Trying to make things easy for myself by setting up an access variable to a movie eg:
ActionScript Code:
theTarget=myMovie.innerMovie.innerMovieofThat
etc
so that I could give a command like
ActionScript Code:
theTarget._visible=false
However this option is no longer available to me as theTarget is now going to change when the Timeline goes to a new frame on which will be another (differently named) movie. So I thought I'd define 'theTarget' on the main timeline from within each new movie based on it's name eg:
[as]_parent.theTarget=this._name+"innerMovie.innerMovi eofThat"
There is something wrong with the above script and I don't know what it is, cos although a trace command returns the right 'theTarget' path, I can't get anything to happen to it from the main timeline when doing this:
ActionScript Code:
this[theTarget].gotoAndPlay(2);
It seems the only way I can get it to work is by using the good old 'eval' method by defining theTarget as
ActionScript Code:
_parent.theTarget = String(_parent._name+".selectionmovie.selectionsquare");
and referencing it as
ActionScript Code:
eval(theTarget).gotoAndPlay("move");
This is fine cos it works, but I don't like having different (sometimes deprecated) methods for doing the same thing scattered around my scripts.
I don't know what I'm doing wrong to make the first method not seem to work properly!
Hope all this makes sense.
View Replies !
View Related
What You Think About This Object Array Access Class
This is kind of my first script in Actionscript and wanted to get some input.
/*
By Sean Levy Dec 14, 2006
Description:
This is a Dataset object.
You pass to it an obecjt which holds an array of data which is constructed of:
myData[0] = "prim_key value, field1 value, field2 value, field3 value ... etc
.
You can access any field of any primey key (i.e.: HH101) directly
WITHOUT doing a for loop, saving time and resources !!!
The for loop only happend doing init of the object but not every time
you read or write to the object making it super fast ...
The best way to think of this object is as of its a virtual grid
where you can access any recoed using a row and column identifier ( i.e.: part_number / field )
where the part number is always a unique prim. key
The "Magic" of the code is that we use two objects with mapped array indexes
so we can always retrieve the primary's key index and thus pull the proper
hash table equivelant member
Enjoy.
=========================================================================
Sample to copy and paste below:
=========================================================================
var myData:Array = new Array();
myData[0] = "part_number HH101,quantity 11,stock 20,description cool stuff";
myData[1] = "part_number HH102,quantity 12,stock 200,description hello world";
myData[2] = "part_number HH103,quantity 13,stock 20,description a realy good tail motor for Piccolo (Qty x 2)";
// Create Dataset Object and populate with myData
var myData:Dataset = new Dataset(myData);
var part:String = "HH102";
trace("Showing part: " + part);
trace(part + " Stock " + myData.getValue(part, "stock"));
trace("Changing inv " + part + " to 150"); myData.setValue(part, "stock", 150);
trace(part + " Stock: " + myData.getValue(part, "stock"));
trace(part + " Description " + myData.getValue(part, "description"));
*/
class lib.Dataset {
private var _aKeys:Array = new Array();
private var _aKeysExtended:Array = new Array();
private var _index:Number = null;
// Get Value from dataset
public function getValue( partNumber:String, column:String ) {
_index = _aKeys[partNumber];
return _aKeysExtended[_index][column]
}
// Set Value at dataset
public function setValue( partNumber:String, column:String, value:String ) {
_index = _aKeys[partNumber];
_aKeysExtended[_index][column] = value;
}
public function showAll() {
var sElement:String = null;
for(var z:Number = 0; z < _aKeysExtended.length; z++) {
sElement = "";
for(var key in _aKeysExtended[z]) {
sElement += _aKeysExtended[z][key] + " ";
}
trace(sElement);
}
// _aKeysExtended.sortOn("description");
}
// Constructor
public function Dataset( myData:Array ) {
for ( var i:Number = 0 ; i < myData.length ; i++ ) {
// trace(i + " " + myData);
var sLine:String = myData;
var aSingleLine:Array = sLine.split(",")
var nCounter:Number = 0;
var sPrimKey:String = ""
for ( var x:Number = 0 ; x < aSingleLine.length ; x++ ) {
// trace("A" + " " + i + " " + aSingleLine[x]);
var theData:Array = aSingleLine[x].split(" ")
var theColumn:String = theData[0];
// trace("The Column: " + " " + theColumn);
var columLength:String = ( theColumn.length + 1 );
var lineLength:String = ( aSingleLine[x].length );
// trace("C" + columLength + " " + lineLength );
var dataOnly:String = aSingleLine[x].substr(columLength, lineLength);
// trace(nCounter + " " + theColumn + "=" + dataOnly);
if ( nCounter == "0" ) {
_aKeys[dataOnly] = i;
_aKeysExtended.push({key: dataOnly});
} else {
_aKeysExtended[theColumn] = dataOnly
}
nCounter++;
}
}
}
}
View Replies !
View Related
Array Access Notation With Strings?
I may be confused, but I thought you could use array access notation with strings. Can someone tell me why this code doesn't work (or suggest new code):
the code is meant to rewrite the block of text in tText at a rate of one character per frame... (when the function is called once per frame) but it doesn't work.
Attach Code
function swapText():Void {
var sWorkingText:String = tText.text;
var sNewText:String = oPhotoText[sPageFocus];
var nIndex:Number = oPhotoText.nIndex;
if(oPhotoText.nIndex < sNewText.length) {
trace("sNewText[nIndex] = " + sNewText[nIndex]);
sWorkingText[nIndex] = sNewText[nIndex];
} else if(sWorkingText.length > sNewText.length) {
sWorkingText = sWorkingText.slice(0, -1); //takes 1 character off the end.
} else {
oPhotoText.bSwapText = false;
}
oPhotoText.nIndex++;
tText.text = sWorkingText;
}
View Replies !
View Related
Trouble With Array Access Operators
Hello all:
I have been trying to pick apart this long string to see why it does not change the rollover color. I replaced the string with these array operators but things fell apart and stopped working. I did confirm with a couple of trace statements that the content inside the operators yields the correct string names.
----------------
(new Color(_level0.gridFrame.gridObjects[_level0.objectName + _level0.objectLevel]["lines_" + _level0.objectName + _level0.objectLevel])).setTransform({ra:0, rb:21, ga:0, gb:64, ba:0, bb:146});
----------------
I have been staring at this thing for more time that I care to admit. Any help would be greatly appreciated.
Thank you!
- Garrett
View Replies !
View Related
Get Access To A Stored Sprite In A Array
i'm not getting how to do this, I create a sprite and then store it's refence in a array, what I want is to use that refence to call it later... but really don't know what's wrong...
here's the code:
ActionScript Code:
// place a moviclip on stage with instance name of: "container"var storeGraf:Array = new Array();// draw something in a spritevar target1:Sprite = new Sprite();target1.graphics.beginFill(0xCCFF00);target1.graphics.drawRect(0, 0, 100, 100);target1.name = "target1";storeGraf[0] = target1 as Sprite;container.addChild(target1);//container.getChildByName('target1').alpha = .5;container.storeGraf[0].alpha = .5;
thanks
View Replies !
View Related
Obj Props Via Assoc. Array Access
hi - how would one loop the following
Code:
this.addProperty("rb", function(){return new Color(this).getTransform().rb}, function(a) {new Color(this).setTransform({rb:a});
above works find, but when i try to loop it im unsure how to access the object property directly, altough the value's available
Code:
for (var i in new Color(this).getTransform()) this.addProperty(i, function(){return new Color(this).getTransform()[i]}, function(a) {new Color(this).setTransform({i:a});
it's that last bit {i:a} that's wrong, but i've no idea how to make it un-wrong :/
View Replies !
View Related
|