Need Some Array Help W/ Dynamic Naming
I would like to know if there is a way to make this piece of code dynamic ex:
input1_txt, and yourAnswer1 would become whatever step you were on, if on step 2, yourAnswer1 would become yourAnswer2. but I also need to hold yourAnswer1 + the inputed info.
this is the code:
code:
input1_txt.onChanged = function() {
if (yourAnswer1 == correctAnswer) {
stepNum();
nextFrame();
} else if (input1_txt.text.length>=correctAnswer.length) {
assistant.alert.play();
}
};
I would just like to have this code once, and it would "count up" for each step you go to
input1_txt - is an input text field
yourAnswer1 - is the variable to hold the users input
correctAnswer - is defined in my xml
stepNum(); - is my function to display the step instructions
code:
stepNum = function () {
var z = stepCounter;
stepCounter++;
messageType = rootNode.attributes.Title;
theStepper = "Step "+stepCounter+" of "+maxSteps;
instructions = rootNode.childNodes[2].childNodes[z].attributes.TEXT;
stepScenario = rootNode.childNodes[2].childNodes[z].attributes.Scenario;
theScenario = rootNode.childNodes[1].childNodes[stepScenario-1].attributes.TEXT;
correctAnswer = rootNode.childNodes[2].childNodes[z].attributes.INPUT;
// trace ("step scenario number"+stepScenario);
};
right now I can hard code each input box, but that requires copying and pasting the code and changing the input1_txt and the yourAnswer1 for each input box, plus I have to declare all of the yourAnswer variables so they will hold the information, which isnt a problem, but can become tedious. I know with Arrays I can probably do this, but I can't get it to work.
make sense?
IMS
FlashKit > Flash Help > Flash ActionScript
Posted on: 03-30-2006, 05:21 PM
View Complete Forum Thread with Replies
Sponsored Links:
Dynamic Array Naming
Here's a simple requirement...
var arrayName:String = "tabAy_"+commTrayNo;
var this[arrayName] = new Array();
..but the second line gives an error: Identifier expected. How can I generate a valid identifier for my new array?
View Replies !
View Related
Dynamic Object Naming From Xml In Array
This is the object array target structure I am looking to create
myObject.myArray[0].data=value;
myObject.myArray[0].data2=value2;
myObject.myArray[1].data=value;
myObject.anotherArray[0].data=value;
myObject.anotherArray[0].data2=value2;
myObject.anotherArray[1].data=value;
myObject.anotherArray[1].data2=value2;
An Object (myObject) with an Array (myArray) of Objects;
I can do this fine manually, but what I am wanting to do is create this dynamically from xml data. All of which works fine done manually in code. This is my basic dynamic code:
var xml=xmldata;
do {
current:Object = new Object(); // the main object
var name:String=xml.nodeName; // ie - text
/// create an array in current with an object inside ie (current.text[i].data)
set("current." + name, [{}]);
var node=xml.firstChild;
var i=0;
do {
for (attr in node.attributes) {
// this is basically what I am trying to replicate
// current.text[0].attr=node.attributes[attr];
//or current.text[0].id=16;
// All the variables work, I just can't get them to be placed inside
//the object inside the array
set(current[name+"["+i+"]."+attr], node.attributes[attr]); //no worky
//current[name+"["+i+"]."+attr]=node.attributes[attr]; //no
//this[current+name+"["+i+"]."+attr]=node.attributes[attr]; //nope
}
i++;
} while (node = node.nextSibling);
} while (xml = xml.nextSibling);
Anyone have any suggestions?
Thanks, Dusty
View Replies !
View Related
Dynamic Association Naming While Building Array (with Named Elements...)
Hello Gurus,
I'm currently having to build an object/array like so:
Code:
for (var x = 0; x < myTableData.numRows; x++) {
_global.toStoreData.push({PKID:myTableData.dataArray[x].PKID,
account:myTableData.dataArray[x].account,
name:myTableData.dataArray[x].name,
});
}
It is fine to hard code this for small sets, but there are many more columns in the database table than just PKID, account and name. Also, If I change the table structure at all I have to go back to the app and change code which is not desirable.
The goal is to make the field names dynamic in the associative array. I have access to the column names in
Code:
CompanyData.Company.columnNames[x]
I think that if I use a for loop to iterate through the data object I can place these column names dynamically but I cannot find the right syntax to allow the following array creation with the associative name created dynamically:
Code:
for (var x = 0; x < myTableData.numRows; x++) {
for ( myFieldName in CompanyData.Company.columnNames )
{
_global.toStoreData.push({ myFieldName:myTableData.dataArray[x].myFieldName });
}
}
With this I get:
Code:
toStoreData
---->1
--------->myFieldName = undefined
---->2
--------->myFieldName = undefined
---->3
--------->myFieldName = undefined
Insead of the desired:
Code:
toStoreData
---->address = "123 anywhere data"
---->name = "Bill's Widgets"
---->PKID = "1"
I appreciate any help, and hope I've been clear. Thanks in advance.
Lizard
View Replies !
View Related
Naming An Array
I have 4 arrays. Their names are news1Ar, news2Ar, news3Ar, news4Ar.
When I push a 'next' button I want the next array to load its text.
Code:
news_mc.newsNext_mc.onRelease = function() {
newsShowing++;
this._parent.news_txt.htmlText = "<.news_txt_h1>"+ 'news'+newsShowing+'Ar'.title "</.news_txt_h1>"+ newline + "<.news_txt>"+ news2Ar +"</.news_txt>";
}
The bold part I'm having trouble with. I need to dynamically name the array to the next array name. Like news1Ar to news2Ar.
Thanks for any suggestions you might have.
View Replies !
View Related
Naming The Last Array Item?
Naming the last array item?
I've got a question about arrays, in the following AS script:
____
next_mc.onRelease = function() {
aImages[nCurrentIndex]._alpha = 0;
_root.background_mc._alpha = 0;
nCurrentIndex++;
if (aImages[currentFrame == totalFrames]) {
this.next_mc._visible = 0;
}
};
____
At the 'if' statement, you see the following:
[currentFrame == totalFrames]
Of course that doesn't work, but how to i mention:
last item of the array, so that i can say:
if (aImages[last_item_of_array]) {
// then the play button won't be usable anymore
this.next_mc.visible = 0;
// second question:
// _alpha = 0;
// the alpha-feature doesn't make the 'play button' unusable. What feature does make the 'play button' unusable?
The whole script works, except for the above mentioned:
so here is the complete script i created:
var aImages:Array = new Array(intro_mc3, one_mc, two_mc, three_mc, four_mc, five_mc, six_mc);
var nCurrentIndex:Number = 0;
next_mc.onRelease = function() {
aImages[nCurrentIndex]._alpha = 0;
_root.background_mc._alpha = 0;
nCurrentIndex++;
if (aImages[99]) {
this.next_mc._visible = 0;
}
};
prev_btn2.onRelease = function():Void {
for (var i:Number = 0; i<aImages.length; i++) {
aImages[i]._alpha = 100;
}
nCurrentIndex = 0;
};
// repeating with setInterval from left to right
function addToMask():Void {
var nDepth:Number = mcMask.getNextHighestDepth();
mcPiece = mcMask.attachMovie("maskPiece", "mcPiece"+nDepth, nDepth);
mcPiece._x = nX;
mcPiece._y = nY;
nX += mcPiece._width;
if (nX>=intro_mc3._width+mcPiece._width) {
nX = 0;
nY += mcPiece._height;
}
}
var nX:Number = 0;
var nY:Number = 0;
var mcPiece:MovieClip;
intro_mc3._width = 400;
this.createEmptyMovieClip("mcMask", this.getNextHighestDepth());
intro_mc3.setMask(mcMask);
mcMask._x = intro_mc3._x-25;
mcMask._y = intro_mc3._y;
var nStageWidth:Number = Stage.width;
var nAddMaskInterval:Number = setInterval(addToMask, 200);
updateAfterEvent();
// if you'd like to copy this script, try creating a MC to the library that links to the var movieClip: mcPiece. The self-made movieClip is then the puzzle piece size used for the puzzle AS script
View Replies !
View Related
Array And Naming Instances
Hi,
I am trying to duplicate a newly created movie. BUT, the instance names are created with a for statement that gets data from an array (aScreen). The array contains path for file to be imported to the newly created movieclips.
I do not know how the syntax to put variables in instance names in dot syntax...
mcXXXX.["mcImage"+i].whatever(); was my last try.
Code:
for(var i:Number = 0; i < aScreen.length; i++) {
// new numbered movieclip (mcThumbs is a mc that contains thumbnails)
mcThumbs.createEmptyMovieClip("mcImage"+i, mcThumbs.getNextHighestDepth());
// movie clip loader
mclImages.loadClip(aScreen[i], "mcThumbs.mcImage"+i);
// Until here everything works... duplicateMovieClip doesnt work
mcThumbs.["mcImage"+i].duplicateMovieClip("mcImage_reflet"+i, mcThumbs.getNextHighestDepth());
// here any code to move the new movieclip so they dont overlap ;)
anything
}
View Replies !
View Related
Naming A Function From An Array
im making a site that will have 5 main links, these link names are brought in from XML file and stored in an array, these names are then used to make the different links using a for loop.
what i am wanting to do is set an CLICK event for each link so that it runs a function which will have the links name in it eg. "create_Home()"
so during the for loop i would like to set a var to hold the name of this function eg.
ActionScript Code:
funcName = "create_" + linkName[i];
then....
ActionScript Code:
link.addEventListener(MouseEvent.CLICK, funcName);
my problem is that in order to use this variable as a function in my event listener the var type must be set to function, but this cannot work as i cannot include the string "create_" in the function var.
Is there a way around this?
View Replies !
View Related
[FMX] Naming The Mcs From An Array W/ AttachMovie
ok, that's some basic question but it's 4 am, I can't find the answer in the tutz and I'm starting to get a headache...
I'm creating some mc's on the stage with the attachMovie function in a loop. I have no problem naming them like that:
foo.attachMovie("myClip", "myClip"+i, 200+i);
But I need to name them with part of an array like that:
foo.attachMovie("myClip", "myClip"+array[i]+"_mc", 200+i);
I thought that would work but I guess my synthax is wrong... How do you mix strings and arrays elements inside the () of the attachMovie?
I need to get something like: myClipArrayElement1_mc for the name of the attached movies...
THX!
View Replies !
View Related
Custom Array Naming
How would I go about creating a newArray with a dynamic name?
For instance I have a menu of buttons which are duped movieclips that are assigned their own unique name when they are created. I have their names assigned to a variable called menuItemID, which pretty much is just a numeric value at this point.
I want to be able to click (out of order) these buttons or menu items and thus create a new Array for each button and assign the Array a corresponding name so I can then access those specific arrays from within the movie. I'm not exactly sure how to do this. I'm sure I can figure it out, but if someone out there has the knowledge already...why waste the time.
Help is appreciated!
Disclaimer: I know there's a Moderator status attached to my alias. That's because I'm moderator of the 3D section and not the Flash section.
View Replies !
View Related
Naming Array Elements For Interaction
The subject itself may demonstrate that I reall have no clue about FMX.
The problem: I have a number of elements in an array that directly correspond to MovieClips names, but now I need to be able to access those elements *as if they were the names themselve.* For example, I have an array element named say, "Clip01" and once the name is randomly taken from the array, I need to move the corresponding clip to an (x,y) coordinate. So how do I extract that name from the array as a variable and use it to control the clip?
The solution: Well, I was hoping you might help me with that...
Robert
View Replies !
View Related
Flash 8 Object And Array Naming Collisions
Hi all,
i am working on a project and have created several classes. now in one of those classes i have both an object and an array declared as priivate within the class
new instances of this class are created and each instance holds specific data particular to that class. now the problem i've noticed is that my Objects and arrays that are declared as properties do not remain within the scope of their class instance but rather take the value of the last instance that changed them.
now i am trying to access these object proerties from within the instance of the class and not from the outside so its all a mystry to me how this is happening.
if anyone knows of some bug or particular functionality of the Object and Array classes that i may have missed i would really appreciate it.
an alternative would be to store the properties in individual variables and not use Objects or Arrays to group them but i would prefer not to.
thanks again for the help.
sample object declaration:
Code:
private var _appliedRules:Object= { colorChange: false, dependents:false };
this is the only place the object is set:
Code:
_appliedRules.colorChange = true;
View Replies !
View Related
Dynamic Naming
I have to draw a bunch of shapes based on array data of the shape's size and position and each shape (or sprite, or MC) has to named so that I can attach onMouseOver events.
How do I name new Display List objects programatically? In AS2 you just loop them out and say:
myClip_mc.duplicateMovieClip("newClip"+i, nextlevel++);
TIA
View Replies !
View Related
Naming One Dynamic Mc
I have loaded one instance from the library under the class of circle.
Code:
var test:circle = new circle;
addChild(test);
test.x = 250;
test.y = 90;
test.name = "test_mc"
stage.addEventListener(MouseEvent.MOUSE_UP, TestThis)
function TestThis(evt:MouseEvent):void {
trace(evt.target.name);
}
The trace returns test_mc, but if I try to add script that refers to test_mc:
Code:
test_mc.addEventListener(MouseEvent.MOUSE_DOWN, strtdrg);
function strtdrg(myevent:MouseEvent):void {
test_mc.startDrag(true);
}
I get an “undefined Property” error.
Is it better just to have the mc already on the stage with an instance name? Can you only dynamically load mc’s and reference them through arrays?
View Replies !
View Related
Dynamic Naming
Hi want to send a form usign an array. My problem is the Var naming in the LoadVars. i can't use dynamic naming in flash.
i try this
ActionScript Code:
var textField_arr:Array = new Array("userName", "pass", "passConf", "lastName", "firsthName", "state", "country", "answer");
function envoyer() {
var sendFormVars:LoadVars = new LoadVars();
for (i=0; i<=totalTextFields; ++i) {
var tempNameField:String = textField_arr[i]+"_txt";
tempName = this[textField_arr[i]];
trace(tempName)
sendFormVars.tempName=_root[tempNameField].text
}
trace(sendFormVars)
}
and then
ActionScript Code:
var textField_arr:Array = new Array("userName", "pass", "passConf", "lastName", "firsthName", "state", "country", "answer");
function envoyer() {
var sendFormVars:LoadVars = new LoadVars();
for (i=0; i<=totalTextFields; ++i) {
var tempNameField:String = textField_arr[i]+"_txt";
tempName = this[textField_arr[i]];
trace(tempName)
sendFormVars._root[tempName]=_root[tempNameField].text
}
trace(sendFormVars)
}
none of those two let me assign dynamique name.
Does anyone know?
thanks
woyrz
View Replies !
View Related
Dynamic Naming
How would you go about dynamically generating names for text boxes, so that i could run through a loop naming each one individually, this way doesnt seem to work anyway: this.createTextField("myText"+i, layer, 10, 100, ...
Thanks.Sean.
View Replies !
View Related
Dynamic Movie Naming
Hi all,
i'm trying to create a number of duplicate movie clips using a for loop, managed to create them using dup clip and "opp"+n for the name, problem is trying to then access the new clips properties "opp"+n.value dosn't work at all...how can i access clips using a dynamic name?
setproperty works o.k. with dynamic names but i want to set variables i have placed in the clip myself
thx
View Replies !
View Related
Dynamic Naming Of Textfields
I am trying to set up a dynamic tab order. This requires that textfields in a source movieclip are named dynamically (that is with increasing numbers) as the source movieclip is copied into the main movie. How can I do that?
View Replies !
View Related
MX: OO: Dynamic Interval Naming?
SO, how do I dynamically name a setInterval()?
Code:
//////////////////////////////
// pause for X milliseconds
//////////////////////////////
pause = new Object();
pause.wait = function (name, milli) {
_root.stop();
/* so what do I put here? */ =setInterval(pause.interval, milli, name);
}
pause.interval = function (name) {
_root.play();
clearInterval(name);
}
I've tried this[name], this.name, eval(name), eval(this.name)... I'm getting bored with it now... help would be appreciated.
View Replies !
View Related
Syntax For Dynamic Naming
Hey there,
I'm trying to set a number of arrays dynamically using FOR... loops.
I've got to the stage where I need to run two FOR loops (one within the other, one has initial i=1, the other j=1)
If I want to set an array using these two variables then, how do I do it...
I'm trying:
this["variablename"+this.i][this.j];
But it doesn't recognise it as me wanting to set an array. Any ideas?
View Replies !
View Related
Dynamic Naming Of Object
in Actionscript 2 i have to distribute some xml to three different arrays. Now i would like to instantiate the array object in a dynamic way (because there can be any number of them). Like so:
for (x=0;x<3;x++){
"xmlArray"+x= new array(xml goes here);
}
This of course does not work - but how do i go about creating arrays in a dynamic way?
View Replies !
View Related
Dynamic Naming Problem...
I am trying to creating a NEW OBJECT() each time I loop through this:
Code:
for (i = 0; i < projTotal; i++) {
//create a new object for each project
//imageObject = ["imageObject" + i];
//trace("Object Names: " + imageObject);
imageObject = new Object();
etc...etc..etc....
}
I then just populate the data..
but I am ONLY populating the SAME object in each loop.
where as I am trying to (if you see the commented out lines/attempts) to create a new object on eacj iteration..called
imageObject0, imageObject1, imageObject2...etc..etc..etc
what am I missing? thanks
View Replies !
View Related
Dynamic Naming/assignment Help?
ok.. Im having some trouble here.. maybe you can help me sort it out real quick. First I explain what Im trying to do...
then I'll post a couple of the ways I have tried it..
summary:
Im attaching "a movieClip to the stage from the library "XX" amount of times.
this movieClip is made up of:
1.) 1 textField
2.) 1 empty movieClip being used to load an image into. (containerClip)
as I am attaching this clip to the stage.. I also pass variables/data into each clip as it is attached/initialized..
example:
PHP Code:
for (i = 0; i < totalLocations; i++) {
var locationClip = attachMovie("locationObject", xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[0].firstChild.nodeValue, 1000 + i);
var locName = xmlSource.firstChild.childNodes[2].childNodes[i].childNodes[1].firstChild.nodeValue;
locationClip.locationName_txt.border = true;
locationClip.locationName_txt.borderColor = 0x07268A;
locationClip.locationName_txt.background = true;
locationClip.locationName_txt.backgroundColor = 0xFFFFFF;
locationClip.locationName_txt.html = true;
locationClip.locationName_txt.htmlText = locName;
//onPress actions
locationClip.onRelease = function() {
trace("clicked: [release]");
};
locationClip.onRollOver = function() {
trace("rolledOver");
};
locationClip.onRollOut = function() {
trace("rolledOut");
};
}
my problem is coming into play when I am trying to assign a movieClipLoader() and a listener to each clip as it is being attached to watch for the image being loaded into it.. and when done (onInit)....do something.. (position the textField)..
but I cant seem to get it right.. it seems I can NOT dynamically create/name my objects
I tried adding this:
PHP Code:
//----- [image loader code] -----//
//locationImage listener/onInit function
var locationListener:Object = new Object();
locationListener.onLoadInit = function(target_mc:MovieClip) {
trace("init fired/location Object placed");
target_mc._x -= Math.round(target_mc._width / 2);
target_mc._y -= Math.round(target_mc._height / 2);
//set textField placement
locationClip.locationName_txt.htmlText = cityName;
locationClip.locationName_txt._y = Math.round(locationClip.imageContainer._y + locationClip.imageContainer._height);
locationClip.locationName_txt._x = Math.round((locationClip.imageContainer._x + locationClip.imageContainer._width / 2) - locationClip.locationName_txt._width / 2);
};
var locationLoader:MovieClipLoader = new MovieClipLoader();
locationLoader.addListener(locationListener);
locationLoader.loadClip(cityImage, locationClip.imageContainer);
//----- [image loader code] -----//
but this is just using the same instance (I believe..and NOT creating a new one on each iteration/loop).. I say this because only the LAST attached clip has the correct placement of the textField.....
I tried this:
PHP Code:
//----- [image loader code] -----//
//locationImage listener/onInit function
locationListener = locationClip.locationListener = new Object();
//var locationListener:Object = new Object();
locationListener.onLoadInit = function(target_mc:MovieClip) {
trace(locationClip._name+" locationListener init fired/location Object placed");
trace("I: "+i);
target_mc._x -= Math.round(target_mc._width / 2);
target_mc._y -= Math.round(target_mc._height / 2);
//set textField placement
trace("LOC NAME2: "+locName);
locationClip.locationName_txt._y = Math.round(locationClip.imageContainer._y + locationClip.imageContainer._height);
locationClip.locationName_txt._x = Math.round((locationClip.imageContainer._x + locationClip.imageContainer._width / 2) - locationClip.locationName_txt._width / 2);
};
locationLoader = locationClip.locationLoader = new MovieClipLoader();
//var locationLoader:MovieClipLoader = new MovieClipLoader();
locationLoader.addListener(locationListener);
locationLoader.loadClip(locImage, locationClip.imageContainer);
//----- [image loader code] -----//
same results..
even this:
PHP Code:
//----- [image loader code] -----//
//locationImage listener/onInit function
locationListener = this["locationListener" + i] = new Object();
//var locationListener:Object = new Object();
locationListener.onLoadInit = function(target_mc:MovieClip) {
trace("locationListener" + i +" init fired/location Object placed");
trace("I: "+i);
target_mc._x -= Math.round(target_mc._width / 2);
target_mc._y -= Math.round(target_mc._height / 2);
//set textField placement
trace("LOC NAME2: "+locName);
locationClip.locationName_txt._y = Math.round(locationClip.imageContainer._y + locationClip.imageContainer._height);
locationClip.locationName_txt._x = Math.round((locationClip.imageContainer._x + locationClip.imageContainer._width / 2) - locationClip.locationName_txt._width / 2);
};
locationLoader = this["locationLoader" + i] = new MovieClipLoader();
//var locationLoader:MovieClipLoader = new MovieClipLoader();
locationLoader.addListener(locationListener);
locationLoader.loadClip(locImage, locationClip.imageContainer);
//----- [image loader code] -----//
so Im at a loss here.. how can I dynamically create a unique movieClipLoader/Listener for each attached clip? so that when each image is loaded into it..it calls the required call back/function/actions?
thanks
View Replies !
View Related
Dynamic Instance Naming
Hello!
So I'm trying to finish a little image loading class and I'm having lots of trouble scoping the mc's that the images are being loaded into. Let me know if I should post all the files. Basically it seems to work fine, the images load properly, the first 'getChildAt' trace works fine, but a direct trace using the parent.child syntax is giving me 'undefined.' Of course I need to be able to scope those for further use.
Any thoughts or ideas?
Thanks!!
Quote:
code:
private function loadImages ()
{
for (var i:int = 0; i < xmlSrc.image.length(); i++)
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, onImageLoad);
loader.load (new URLRequest (xmlSrc.image[i].@url));
}
}
private function onImageLoad (e:Event)
{
clipImg = new MovieClip();
clipImg.addChild(e.target.content);
clipImg.name = "image"+counter;
++counter;
imageHolder.addChild(clipImg);
trace ("Get Child Trace " +imageHolder.getChildAt(0).name); // Traces as "image0"
trace ("Direct Scope Trace " +imageHolder.image0); // Traces as "undefined"
imageHolder.image0.x = 400; // Doesnt work
}
View Replies !
View Related
AS3 Dynamic Button Naming Help
Struggling a little bit with how to make this a bit more dynamic and scalable.
Essentially I have a simple xml driven slide show and a nav menu built by a symbol in the library that is placed on stage for as many slide nodes as the xml has. That all works fine but I'd like to dynamically reference each nav button rather than hardcode it.
This is what I've got. Any help would be gratefully appreciated:
PHP Code:
/////FOR LOOP CREATES / PLACES NAV ON STAGE//////
function sXmlLoaded(e:Event):void {
slidesXML = new XML(e.target.data);
var sl:XMLList = slidesXML.asset.slide;
for (var i:uint=0; i < sl.length(); i++) {
var _sList:String = sl[i];
_sListArray.push(_sList);
var nBtn:MovieClip = new navMC();//from Library
nBtn.name = "navButton"+i; //instance names for button access
addChild(nBtn);
navButton.push(nBtn);
nBtn.x = 0;
nBtn.y = 55+(49*i);
nBtn.btnTxt.mouseEnabled = false;
nBtn.btnTxt.text = (i+1).toString();
nBtn.buttonMode = true;
}
//HELP HERE Would be great, to make it more scalable and dynamic.//
//CLICK EVENTS//
navButton[0].addEventListener(MouseEvent.CLICK, bFunction0);
navButton[1].addEventListener(MouseEvent.CLICK, bFunction1);
navButton[2].addEventListener(MouseEvent.CLICK, bFunction2);
//OVER EVENTS//
navButton[0].addEventListener(MouseEvent.MOUSE_OVER, bFunct0Over);
navButton[1].addEventListener(MouseEvent.MOUSE_OVER, bFunct1Over);
navButton[2].addEventListener(MouseEvent.MOUSE_OVER, bFunct2Over);
//OUT EVENTS//
navButton[0].addEventListener(MouseEvent.MOUSE_OUT, bFunct0Out);
navButton[1].addEventListener(MouseEvent.MOUSE_OUT, bFunct1Out);
navButton[2].addEventListener(MouseEvent.MOUSE_OUT, bFunct2Out);
}
////////////WHEN CLICKED FUNCTION/////////
function bFunction0(e:MouseEvent):void {
slideTime.stop();
currSlide = 0;
sNum = 0;
initSlideShow(0);
}
///////////ROLL OVER FUNCTION/////////////
function bFunct0Over(e:MouseEvent):void{
navButton[0].navOver.alpha = 1;
}
/*I'm hoping it could be something as simple as:
[b]function bFunct[varNumName]Over(e:MouseEvent):void{
navButton[varNumName].navOver.alpha = 1;
}[/b]
*/
/*it would be great if I could have a single button function like the one above and use something similar to eval from AS 2 to get the button's id and be able to replace the hardcoded number with a var*/
So obviously a bit cumbersome. It works if I've got 3 buttons/slides, but what if I've got a hundred....? ugggh. I'd really like to set up a single function that each button can reference for their click/over/out/active states and simply pass their var value into rather than creating individual functions hardcoded for each button.
View Replies !
View Related
Dynamic Path Naming
I want to use a function to create a bunch of objects and object listeners when I have a million checkboxes on the screen. Cant seem to figure out how to write the code to do it... any help would be great.
// this is the code that DOES work!!!!!! BUT ITS STATIC
// I want to replicate this code into a loop so i dont have to write it so much.
// I put in into a function.. just because.
function createlistners(){_level3.set2_1listner = new Object();
_level3.set2_1listner.click = function (eventObj){if (eventObj.target.selected){trace('checked'); } else {trace('unchecked'); } }
// REPEAT this code like 10 times}
// THIS IS THE CODE IM TRYING TO GET TO WORK
function createlistnersNEW(b, c, v){ a = 1;
while(a <= c){
listpath = eval('_level3.set' + b + '_' + a + 'listner');
listpath = new Object();
listpath.click = function (eventObj){
if (eventObj.target.selected){
trace('checked');} else {
trace('unchecked');}}
a++;}}
// this works too.. just adds listners to all the objects i created.
function addlistners(b, c){
//adds listeners to checkboxes
a = 1;
while(a <= c){
listpath = eval('_level3.set' + b + '_' + a + 'listner');
box = eval('_level3.box' + b + '_' + a);
box.addEventListener("click", listpath);
a++;}}
PLZ HELP :P
View Replies !
View Related
Dynamic Naming Of Objects? Please Help...
why does this work:
var target_path = "_root." + target_name;
eval(target_path)._y = 100 ;
but the following returns the error "Left side of assignment operator must be variable or property":
for (i in the_array){
var some_var = "loader" + i;
eval(some_var) = new MovieClipLoader();
}
Please someone tell me how to dynamically name objects. Obvioulsly "variable variables" are not easy in actionscript, and it seems impossible for objects.
View Replies !
View Related
Dynamic Variable Naming
I'm instantiating objects in a for loop. The quantity instantiated varies depending on external content. I need to name each new object:
ActionScript Code:
for (var i:Number = 0; i < categoryArray.length; i++) {
var currCategory:String = categoryArray[i].categoryName;
var toBeCreatedOnTheFly:MenuBuilder = new MenuBuilder(menuHolder_mc.sectionMenu, currCategory, 20, 20, 10, false);
}
I want toBeCreatedOnTheFly to be dynamically named so that it's called currCategory + "Menu". Thus, if there are five turns through the loop, I'll have variables called catMenu, dogMenu, bearMenu, owlMenu and whaleMenu or whatever.
Is this possible? Or how else might I be doing this?
View Replies !
View Related
Dynamic Naming Problem
I've got two arrays, one called map_1_1, the other objectmap_1_1.
I've also got four variables, currentMap.x, currentMap.y, selectedMap, and objectMap.
I am using a function that calls selectedMap and objectMap to build a map for a game, those variables are created as so:
ActionScript Code:
currentMap={x:1, y:1};
selectedMap = "map_" + currentMap.x + "_" + currentMap.y;
objectMap = "objectmap_" + currentMap.x + "_" + currentMap.y;
When I trace selectedMap, I get map_1_1, and objectMap gets me objectmap_1_1.
The problem is that my function won't run with these for some reason, but if I manually put in map_1_1 and objectmap_1_1, it works.
I need to keep the currentMap x and y dynamic so that I can change them as the game runs, ie. with doors, ect.
So, rather than making a new door Object for every edge of every map I make, is there a way to fix my little problem here?
P.S. FLA available upon request.
View Replies !
View Related
Dynamic MovieClip Naming?
Hey guys I'm trying to run a loop to attach multiple movieclips to the stage, but I keep erroring out. Here's what I've got:
Code:
var i:int;
var s :int = 0;
for (i = 0; i < 5; i++) {
var "box"+i:box = new box();
addChild("box"+i);
eval("box"+i).x = s;
eval("box"+i).y = s;
s = s + 50;
}
Thanks for any help you can give me!
View Replies !
View Related
MovieClip Dynamic Naming
Hi guys,
I'm at a loss with this one: I have so many movie clips in my main movie that I don't want to manually assign names to them in design mode. Instead, I try to dynamically assign names to the movie clips like this:
ActionScript Code:
for (i=0; i<clipCount; i++) {
setProperty("instance"+i, _name, "clip"+i);
}
After doing this I can access the clips with their new names, such as
ActionScript Code:
clip4._x = 10;
However, if I move to another scene and then return to the main scene with all the movie clips, their assigned names are lost! They have names like "instance568", where the number does not match the number they had at the beginning of the main scene.
If I manually assign instance names to the movie clips in design mode, the names stay there even after moving to another scene and coming back.
Can anyone explain this weirdness to me? Or do you have an idea for a workaround? Have I made myself clear at all?
Thanks guys.
Fafner
View Replies !
View Related
OOP Dynamic Naming Of Objects
I'm creating an instance in this way:
var newhouse:House = new House();
But I need to create fourty of these objects named: "newhouse1","newhouse2",...,"newhouse40"
How can I name the var dynamicly, since the syntax won't allow brackets
View Replies !
View Related
Dynamic Naming Of Variables In AS3
Hello,
how can I name a series of Variables dynamically in a loop.in AS3 i.e.:
Attach Code
//instead of:
var container1:Sprite = new Sprite();
var container2:Sprite = new Sprite();
//something like
for (var i:int = 1; i<=10; i++){
var "container"+i:Sprite = new Sprite(); // which doesn't work off course
}
If you know how to do this in AS3 I would be glad to know.
greets
Didi
Edited: 12/17/2007 at 05:39:14 AM by didi.thinkpad
View Replies !
View Related
Dynamic Naming Question
ok, so i have this movie clip, that i am having duplicate and give the dynamic name of ("butt" + g), g being the variable. i need to later reference this number for that button name. so i was doing this
bigpic=String(this._name);
r=bigpic.charAt(4);
which was working fine, up until i got up to number 10, the first two digit number. since it was only pulling the 4th character, it was reading anything in the teens and 1 and anything in the 20's as 2. now is there a way to pull one, or two numbers from this string? or can i have it pull the string name - butt?
View Replies !
View Related
Dynamic Movieclip Naming
i've got 48 small movieclips named "1clip", "2clip", etc. all the way up to "48clip."
I want to do something with them all and use a loop to affect them all the same way.
i tried this:
Code:
stop();
for(i=0; i<49 ; i++){
_root.lClip = "clip"+i;
trace(lClip);
lClip.imageHolder.loadMovie("/images/one.jpg");
}
but that doesn't seem to work. are variables and instance names interchangeable? my lClip var traces out of course, but the lClip.imagHolder.loadMovie never happens (clip inside the clip).
any idears?
View Replies !
View Related
Dynamic NetStreams And Naming Them
Hi,
I have a video app that uses many cameras. I create netStream objects with a for loop and I put them all into an array - aNS[].
ActionScript Code:
for(var i:int=0; i<4; i++){ aNS[i] = new NetStream(aNC[i]); aNS[i].addEventListener(NetStatusEvent.NET_STATUS, netStreamHandler);}
Then I have the netStreamHandler function which is called when the NetStatusEvent.NET_STATUS is envoked - great all of this works perfectly.
ActionScript Code:
function netStreamHandler(event:NetStatusEvent):void { trace(event.target.name)}
except for the trace - How can I add a name to the netStream so when the netStreamHandler is called the trace kicks back the name of the netStream.
I do this all the time with other objects like buttons, videos, comboBoxes etc ... but when I try to do the same to the netStream I always get errors.
How is this done?
waffe
View Replies !
View Related
Dynamic Naming With AddChild() - I Still Don't Get It
Hi everyone. New to the boards here, stumbled upon them via some excellent tutorials on the site.
I've been working on a little program, basically a shell to allow miniature wargames (among other things) to be played via a play-by-email/messageboard. Basically, you have an XML file that stores your pieces (be they the black chess pieces, a deck of cards or a 1,500 point orcish army), another which stores all the pieces in play (a snapshot of how things look), and then the flash app which takes the second XML's data and puts everything down.
Anyway, this is the point where I hit a snag. I have what amounts to an army/deck builder, where you assemble the first XML. When you open an existing XML, it goes through, gets the name attribute (<unit name="whatever">), and makes a list of all of them, with an edit button beside each. Obviously, this is a for... each... in loop, for each unit in the xml file.
My problem is, I then need to refer to a specific one afterwards - when you hit the second Edit button, it needs to show the details for unit[1], when you hit the fourth, it shows unit [3]. I've searched this site, and gotten the following:
Code:
for each (i in input.category.unit) {
bUnit = new Button();
bUnit.x = 150;
bUnit.y = 185 + (25 * j);
bUnit.width = 25;
var unitIndex:String = String(bUnit.name.split("instance")[1]);
bUnit.name = "bUnit" + j;
bUnit.label = "";
bUnit.addEventListener(MouseEvent.CLICK,editUnit);
}
This works, it makes the right number and whatever, but I can't figure out how to reference them afterwards. j just becomes whatever it was last used, so I can't go ("bUnit"+j), and I must be missing something with the getChildByName that was recommended in other threads.
Can anyone help a slow-witted lad? The rest of the project's coming along nicely, until I hit this and everything stopped. Perhaps if you speak slowly, and avoid big words it'll sink in a little easier.
Cheers,
tic
View Replies !
View Related
Dynamic MovieClip Naming?
Hello,
I am just getting started with AS3 and have run into a problem. I had a way of attaching movieClips from the library to the stage in AS2 that used the old attachMovie() function where I would run a for loop and it would duplicate the moviclip to the stage and dynamically create new names for the new instances.
I now am using this:
var myCube = new cube();
addChild(myCube);
Then, I can access the myCube instance's properties like this:
myCube.x = 300;
The problem is that I can't figure out how to name the new isntances by concatenating strings like I used to. This is what I thought would work:
for(i = 0; i <= 10; i++) {
var mcName = "myCube" + i;
var eval(mcName) = new cube();
addChild(myCube);
}
I know that doesn't work, but hopefully somebody can see what I am attempting here.
Thanks!
Mike
PS: hopefully I'm getting Colin Moock's Essential ActionScript 3.0 book soon, I just don't have that resource yet.
View Replies !
View Related
Dynamic Naming Question
ok, so i have this movie clip, that i am having duplicate and give the dynamic name of ("butt" + g), g being the variable. i need to later reference this number for that button name. so i was doing this
bigpic=String(this._name);
r=bigpic.charAt(4);
which was working fine, up until i got up to number 10, the first two digit number. since it was only pulling the 4th character, it was reading anything in the teens and 1 and anything in the 20's as 2. now is there a way to pull one, or two numbers from this string? or can i have it pull the string name - butt?
View Replies !
View Related
Help On Dynamic Variable Naming
Hi,
I have a php script that echos out variables of the form:
newsVars.name1 = alpha
newsVars.name2 = beta
newsVars.name3 = gamma
newsVars.name4 = delta
and I have retrieved them in flash but I want to rename them so that:
newsVars.name1 = _global.name1
newsVars.name2 = _global.name2
newsVars.name3 = _global.name3 .... etc
I want to do this automatically and so that it stops after the last value, i.e. in the example above it will stop after newsVars.name4. I realise that there is a loop function involved somewhere but I can't get it to work.
I have had a good look around forums etc and haven't been able to find anything that helps. There is something about arrays but I don't want to use them.
Cheers,
Zor
View Replies !
View Related
Dynamic Naming Of Variables
Guys , i am trying to create a dynamic variable to use with the share object function . Basically i'm trying to create a login page that will generate an .sol (share object) file on clicking the submit button .
The code on the submit button is this :
ActionScript Code:
on (release) {
user = String(try1.text);
filename = "Save"+user;
init(filename);
}
The init function contains this script :
ActionScript Code:
function init(filename1) {
trace(filename);
squarepos_so = SharedObject.getLocal(filename1);
}
try1.text is the textbox where user types in their user name and the init function will generate different shared object files using the individual usernames .
However for some reason , it is not working .
I try hard-coding the filename variable like this , filename="joey"; , a joey.sol file was generated . But my dynamic method doesn't seems to be working .
Plz help ... Thanks You
View Replies !
View Related
[as][object]dynamic Naming
for some reason I always have problems with dynamic naming and once again I have come unstuck.
I cannot seem to be able to create a object dynamically, here is what I've got already
ActionScript Code:
gdad.BulArr.counter++;
theString = gdad.BulArr.counter.toString();
["bullet"+theString] = new bullet()
and it keeps flailing up " Scene=Scene 1, Layer=Layer 1, Frame=1: Line 107: Left side of assignment operator must be variable or property." and its blimming bugging me c'mon peeps how can I make a dynamic name for an object
Zen
View Replies !
View Related
Dynamic Naming Of Empty Mc's
I'm having A BRAIN FART MOMENT:
problems with my naming convention on empty mc i.e it doesn't work can anyone help?
ActionScript Code:
this.createEmptyMovieClip("EMC"+i, i);
"EMC"+i.attachMovie("Feedback", "FB"+i, i);
and ofcourse it doesn't work,
if it makes any difference its inside an object
please help cos I cannot get any further on this project until its sorted
View Replies !
View Related
Dynamic Variable Naming
ok...heres my code:
for (g=1; g<=this.num_pic; g++) {
var pic+"1"= new Array();
fl = eval("this.pic"+g);
files = fl.split(",");
c = files.length-1;
picname=files[0];
}
I'm trying to rename the variable up there "pic1" and make it an array, but dynamically increment and make new variables in the loop. Obviously this code does not work and I don't know how to accomplish this. Any help would be GREATLY appreciated,
View Replies !
View Related
Dynamic Mvieclip Naming
What is the best way to set a movie clips name dynamically?
Im trying to duplicate a movieclip. I wish for my code to duplicate a movieclip based on user input.
Code:
this.onPress = _root.thing = function () {
stopDrag();
this.onMouseMove = undefined;
_root.duplicateMovieClip("newClip", "thing_mc", 1);
newClip._x = Math.floor(_xmouse);
newClip._y = Math.floor(_ymouse);
};
I would like to have the possiblility of an infinate number of things in my movie, how is this possible?
View Replies !
View Related
Naming Conventions For Importing Dynamic Txt
Hi
Does anyone know if there are specific naming conventions for dynamic textboxes, targets etc when you import external txt file content.
My action works fine when I name the textboxes, targets 'text', but when I use the naming convention I'll need for the final movie (for example bl416z - it's a stock number), the content is not imported.
Bizarre.
View Replies !
View Related
Dynamic Textfield Re-naming In Attached MCs
Hello,
this post may be a bit long winded.
Take a look at these first:
Admin section:
http://www.alienmade.com/psu/dev/_admin/vip_admin.html
Web section:
http://www.alienmade.com/psu/dev/nav.htm
First heres what I am doing now:
Each name and its corresponding title and email are pulled from a database and used to populate my "pre-defined" textfields. This system works well and there are no glitches. All the connecting lines that show the heirarchy have been hand done for each of the web section and admin interfaces..A real pain.
Heres what I want to do..I can get through most of what I need to do, but am having a few set backs in a few critical areas.
For the next version of this interface, I need to build in the ability of, on the fly creation of a new name area, complete with moveable textfiled MC and user defined connecting line to the heirarchy.
Heres the concept Ive been messing with:
Admin clicks a button and an MC opens (editMC) up with a few options:
Add a new name
|
check box(Show title/department with this name)
Makes choice and hits continue:
A "representation" of the new button shows within editMC, at this point the admin can move the button to the location they want.
Click continue again and the admin can add the starting and ending points of the line that will connect the name to the heirarchy.
(first click would be x,y axis, second click would be y axis only to keep the line from skewing).
At this point the admin can save the new name and all of the data for the name and line x,y coords are added to the database.
The editMC closes and the database is querried to pull out the new user and place it on the stage.
Soooo,
I need to know how to dynamicly change a textfield variable name within a dynamicly created or attached MovieClip.
How do you remove a line created with lineTo? Or can you?
Im still having problems with the line creation, but I should be able to accomplish that when the time comes.
There is alot of work to be done, and a lot of bugs to be worked out before I am convinced this will even function the way I want it to. Any help, ideas or input would be greatly appreciated..
Thanks again
3PRIMATES
View Replies !
View Related
Dynamic Movie Attribute Naming
easy stuff yet brain malfunction here!
assume that you create movies named x1, x2,x3..
and they have a common variable attached to each named "id"
thus a newbie will name them as:
x1.id="2131"
x2.id="2132"
x3.id="2133"
however, there must be a prof. way to name movieclip using for-next
can you code me some plz?
thnx for your time
View Replies !
View Related
Question About Dynamic Naming, LoadVariablesNum();
Hello, i have a contact for of input text fields for the general info. And a bunch of checkboxes. The variabes are sent to a php file which works fine for the text boxes. It also works fine if i type out the code for each checkbox individually. Since there are a lot of checkboxes, i created a loop. The variables aren't getting to the php when using the loop. Can someone please help me figure this out! thanks alot:
i send the variable using:
code: loadVariablesNum(mailform, 0, "POST");
The loop for the checkboxes is:
code: for (c=1; c<=12; c++) {
this["checkListener"+c] = new Object();
this["checkListener"+c].click = function(evt) {
if (evt.target.selected) {
_level0["product"+c] = evt.target.label;
} else {
_level0["product"+c] = "";
}
trace(_level0["product"+c]);
};
this["speaker"+c].addEventListener("click", this["checkListener"+c]);
}
please help me figure out why the 'product1' 'product2' etc. varialbes are not sending with the loadVariablesNum(mailform, 0, "POST"). The loop works fine, the trace(_level0["product"+c]) is exactly what it should be. The loadVariablesNum is not sending these checkboxes though.
Thanks alot.
View Replies !
View Related
|