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!
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 04-24-2008, 05:54 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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
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?
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.
Movieclip Naming
Someone has just told me that at some point they remember reading that if you end the name of your movieclip with _mc flash will recognise it as a movie clip and give you other properties (or something). Sorry for the vagueness but has anyone heard of this? I think it a bit bizarre and have tried it both on instance names and library items and can't find any difference!
If you have any views on naming convention I'd be intrested to hear them.
Naming MovieClip Instances?
I have converted a bitmap into over a hundred slices and converted them into graphic symbols in flash. I can do a select all and using the property inspector I can turn them all into movie clips but how do I name all of those instances (like mc1, mc2, mc3) so I can control them via actionscript? Anyone have any ideas?
Thank yuo in advance.
Ash
Naming A Button/movieclip With Node From Xml File.
HI all.
I have a movieclip that contains a dynamic textbox inside it. If i want an xml file that i loaded in _root, to populate the dynamic textbox inside... how do i go about that?
example:
xmlfile: <test><name>Button Name</name></test>
I want my symbol movieclip called Crusty to display Button Name. That way when some prick clicks on the movieclip, he know's that he's clicking on the Button Name movieclip.
How does one populate a dynamic textbox inside another movieclip from a xml file loaded into root?!
Dynamic Naming
how can I make the variable for a dynamic text box be dynamic?
translation: I want the variable for the text box to be random, is there a way to do this?
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
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?
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
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.
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
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?
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.
Dynamic Object Naming
A quick question for a guru...
Is it possible to dynamically name objects when instantiating them? If so (which I assume it must be) how do you do it?
...thanks for the help.
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?
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?
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
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
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
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
}
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.
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
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.
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?
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.
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
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?
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
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?
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
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
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?
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
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
[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
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
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,
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?
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.
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
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
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.
Dynamic Naming Of Movie Clips?
I'm trying to create a little pice of actionscript that will run through a while loop and create and populate a movie clip for each cycle.
this works, for a movie clip called pHolder:
createEmptyMovieClip("pHolder",1);
pHolder.loadMovie("http://pathtosourcejpg" + this.pName);
But what I need is the name pHolder to chage for each cycle throught he while loop it lives in. So I'd essentialy get:
createEmptyMovieClip("pHolder1",1);
pHolder1.loadMovie("http://pathtosourcejpg" + this.pName);
followed by:
createEmptyMovieClip("pHolder2",1);
pHolder2.loadMovie("http://pathtosourcejpg" + this.pName);
Does anyone know the syntax for this?
I have a variable that increments up each cycle called photoShowCount
So I was thinking something along the lines of:
createEmptyMovieClip(["pHolder" + photoShowCount],1);
["pHolder" + photoShowCount].loadMovie("http://pathtosourcejpg" + this.pName);
But that doesn't seem to work any better than any of the other variations I've tried. I'm very new to flash and actionscript so I might be missing something very basic. Pease help.
[CS3] AS/2 Naming Dynamic MovieClips Individually.
Code:
for(var i=0;i<10;i++){
var skeet:MovieClip = attachMovie("skeet", "skeet" + i, i);
//position randomly
skeet._x = Math.random()*500+20;
skeet._y = Math.random()*360+20;
//how much he can eat
skeet.capacity = 10;
//how fast he is (higher number = slower movement)
skeet.speed = 10;
// start with an empty stomach
skeet.ate = 0;
skeet.onEnterFrame = eat;
}
Hi i have a for loop that creates 10 of my skeet movieclips at random positions on the stage.
I then have a hitTest that traces a 1, to the output window if the skeet movieClip hits my food movieclip. My variables are then sent thru my server.
However i need to know which skeet out of the ten is hitting the food at that given time.
So that when skeet 1 hits food it sends variable 1 and traces a 1, the same for 2 and so on.
So basically i need to know how to name dynamic movie clips individually, or give them a variable name that they trigger upon creation. Thanks for any advice in advance.
Code:
if (this.hitTest(skeet)) {
trace(["1"]);
max.send("; var1 1;");
max.send("; var2 1;");
max.send("; var3 1;");
max.send("; var4 1;");
max.send("; var5 1;");
max.send("; var6 1;");
max.send("; var7 1;");
max.send("; var8 1;");
max.send("; var9 1;");
max.send("; var10 1;");
} else {
max.send("; var1 0;");
max.send("; var2 0;");
max.send("; var3 0;");
max.send("; var4 0;");
max.send("; var5 0;");
max.send("; var6 0;");
max.send("; var7 0;");
max.send("; var8 0;");
max.send("; var9 1;");
max.send("; var10 0;");
}
};
Naming Dynamic Class Instances
Hey Guys,
I've been trying to figure this out for awhile, it might be a syntax thing or it could be this isn't possible in OOP, or I'm plain going about OOP all wrong.
import MyClass.as
for(i:Number = 0;i<5;i++){
this["my_new_instance"+i]:MyClass = new MyClass;
}////SO GIMMIE 5 INSTANCES OF MyClass
This Doesn't Work Why? and How would you do somethign like this?
Dynamic Naming Of Multiple TextFields
hey all,
Trying to created multiple textFields, in order to make a clickable index page (like a table of contents):
ActionScript Code:
package {
import flash.events.*;
import flash.text.*;
import flash.utils.*;
import flash.display.*;
import flash.net.*;
import flash.media.*;
public class theIndex extends Sprite {
var theSections:Array=new Array("Creating a lesson","Choosing a lesson","Opening a lesson");
var doSections:TextField=new TextField();
var indexY=10;
public function theIndex() {
for (var i:int=0; i < 3; i++) {
var this["doThisSection"+i]:doSections=new doSections();
var chapter;
this["doThisSection"+i].x=100;
this["doThisSection"+i].y=indexY * i*30;
this["doThisSection"+i].text=theSections[i] + "
";
this["doThisSection"+i].addEventListener(MouseEvent.MOUSE_DOWN,checkChapter);
this["doThisSection"+i].name="p"+i;
addChild(this["doThisSection"+i]);
function checkChapter(event:MouseEvent) {
trace(this["doThisSection"+i].name);
}
}
}
}
}
But, when I compile it, I get:
HTML Code:
1084: Syntax error: expecting identifier before this.
What am I doing wrong??
Thx
Dynamic Variables' Naming From SendAndLoad
Hello,
Been chasing my tail for almost 2days now, I'm having problems on how to load dynamically named variables and place it on dynamically named movieclips. I'm loading variables from php/mysql query thru sendAndLoad (no problem with that). The loaded variables are names of swf files that i'm trying to load on dynamically numbered movieclips. The problem is it just wont load. I've searched the net for similar codes, but with no luck. I'm guessing that my error is in getting the exact variable name to load. Heylp...
Attach Code
//query result from php/mysql
myNum=2&mySwfname1=myfirstmovie&mySwfname2=mysecondmovie
myVars = new LoadVars();
myVars.action = 'getName';
myVars.sendAndLoad(php_file, myVars, 'POST');
myVars.onLoad = function(){
if (myVars.myNum > 0){
var sum:Number = 0;
for(var i:Number = 1; i <= myVars.myNum; i++) {
loadMovie(eval("jets/" + myVars.mySwfname + i + ".swf"), eval("_root.my_movieclip" + i));
}
}
}
//code should be executed this way
loadMovie("jets/myfirstmovie.swf", "_root.my_movieclip1");
loadMovie("jets/mysecondmovie.swf", "_root.my_movieclip2");
|