ActionScript 3.0 :: Using AddChild With A Variable
Jan 24, 2009
I am trying to use addChild on a current project I am working on, the only problem is that I have to add movieclips to the stage based on an array of movieclips given to me and a number (index).
At this point I am trying it like so:
Code:
var array:Array = new Array('Mc1', 'Mc2', 'MC3'); // etc.
var num:Number = 1;
addChild(array[num]);
[Code].....
View 2 Replies
Similar Posts:
Mar 29, 2009
I want to loop and put on several movieclips which are named Node1 to Node15. How do i add them and access them afterwards? Tried to give it a name and access it afterwards, but had no luck.
Code:
i++;
var newnode:Node[i] = new Node[i]();
newnode.name=i;
addChildAt(newnode,i);
newnode.1.x=10;
newnode.2.x=40;
....
newnode.15.x=440;
I still have lots of troubles with the syntax.
View 7 Replies
Nov 30, 2009
Here's my (simplified) code:
Code:
var doorType:String = "DT0";
var openType:String = "OT0";
var imagePositioner:Sprite = new Sprite(); //Places a Sprite that will "contain"
[Code]....
openType is defined on a previous screen, it will be equal to OT1 or OT2. I have two sets of images (movie clips) that each have a prefix of "ot1_" or "ot2_" (in their class name). Other than those prefixes the two sets of image names are the same. I think I could cut the amount of code in half if I could use a variable when I use addChild.
I am not very knowledgeable of AS3 and everything I've tried has failed. My theory is that addChild() needs to contain a movieclip, so putting a variable name in addChild() doesn't work.
View 6 Replies
Mar 16, 2010
First off I want to say that the resources on this site have been excellent
how to reference a variable when adding a new Movieclip?
Currently I am using this method:
Code:
var myVariable:String = "one"
if(myVariable == "one"){
var myMovieClip = this.addChild(new one())
[Cde]....
View 2 Replies
Apr 10, 2012
I want to addChild to stage dynamically using a variable. In AS2, i would have done it using eval().
In the attached page1.as file, I want to be able to use the for() loop instead of the commented out code.
View 5 Replies
Nov 24, 2009
I am working on a project where we are making a "wizard" where you answer a series of questions and in the end you are presented with a "parts list" based on your answers.There is also logic which decides which questions you are asked based on how you have answered certain questions so far. The outcome is a list of door control hardware (locks, mounting plates, handles etc. etc.). show a "live image" of the parts list as it builds. For example one of the questions is this: Door Type?
A) Aluminum
B) All Glass
C) Wood
Depending on which you choose I need to show an image of an aluminum, glass or wooden door.Then if the next question is about lock types then your new lock shows up and so on and so forth until you reach the end.The questions all relate to their own variable which are each defined at the beginning of the movie like this:
Code:
var doorType:String = "DT0";
The questions use radio buttons and each question (re)defines it's variable like this
Code:
DT1.addEventListener(MouseEvent.CLICK, doorTypeHandler);[code]....
Now the tricky part (for me at least) is figuring how in the world to use this in conjunction with the questions (more accurately, the variables they define) to produce this live image.Another thing to add complication to this whole mess is that there are basically two entire sets of images. Single doors or Double doors, they both have (nearly) all the same hardware but they are two different sets of images. They are differentiated by the ot1 or ot2 in front of the class name. The variable openType defines OT1 or OT2 in a previous question. I would like to be able to use the variable openType in the call for the image
Code:
//This is how I tested it
currImage = new ot2_wood_exit();
//I would like to use openType instead of hard coding ot1 or ot2
currImage = new openType_wood_exit(); //I KNOW this is wrong, but I don't know what is right!So that is my basic dilemma. I need to show or hide specific images based on the answers to previously answered questions AND questions currently being answered (live update).
View 3 Replies
Jun 15, 2011
I'm trying to have a class file which can add objects to the stage via addChild; however, when I call addChild from within the class file, I get the error "1180: Call to a possibly undefined method addChild." I've tried importing flash.display.* and that doesn't fix the problem. Does the class file have to extend Sprite or MovieClip to be able to add objects to the stage?
View 8 Replies
Jan 16, 2012
I have downloaded Box2d ([URL]) and created a project that looks like this: [URL]. catalyst is the green cube and it has the base class "shapes.box", it is inside "world" which has the base class "wck.World". What i want to do is to add another "catalyst" from the library inside "world" when i click on add_btn. I tried to accomplish this by this code:
[Code]...
Symbol 'buttons', Layer 'Actions', Frame 1, Line 41061: Call to a possibly undefined method addChild through a reference with static type Class.
View 9 Replies
Jan 20, 2011
I have the followings:
_p:Player (which is a MC)
a1:Animation1 (which is a MC)
_p.addChild(a1); //doesn't display anything
_p.stage.addChild(a1); //displays a1
Why won't the MC display a child without using his stage?
View 1 Replies
Aug 11, 2009
I'm trying to resolve an issue that reared it's ugly head yesterday.Frame one of main timeline I have the following code:
Code:
import flash.display.MovieClip;
import flash.events.MouseEvent;
[code]....
The newMC doesn't show up.If I add 'parent.' in front of the addChild then it appears.mc_LibItem has a base class of "flash.display.MovieClip" and is exporting for ActionScript and on frame one.For grins I created a new .fla and began messing around with the same addChild idea and it worked.
View 14 Replies
Mar 30, 2009
This is something I'm experimenting with, but haven't seemed to figure out... I have several MovieClips, basically the same, only different colors. As each one plays, I'd like it to "overlap" whichever one is already there. Right now I have each button linked to a gotoAndPlay function, but I don't think that will ever get me what I want. You can see how I have it now here: [URL]
Instead of having the content MovieClip go back to all white when a button is clicked, I'd like the preivious one to remain, and get "covered up" by the new one. You continue to see the old color, and the new color overlaps it. I have a feeling I need to use a variable and then addChild, with a removeChild for the old MovieClip after the new MovieClip has loaded, but I'm not getting any good results yet.
View 1 Replies
Oct 30, 2005
somewhat understood the basics of adding and removing children, however, I am facing another problem. After using the removeChild Function, I can't seem to add another child.For example:
ActionScript Code:
var attachedMC = new (getDefinitionByName("Content1") as Class)()
Page.addChild(attachedMC);
[code].....
View 3 Replies
Jul 29, 2009
I have a main "shell" swf which, by clicking several buttons, will load/unload various external swfs into a Placeholder_mc which resides on the main timeline in Shell.swf In the documentation and tutorials I've seen a couple different methods, and I'm not sure I quite understand the difference, or at least the reason you would use one over the other...In the 1st method, you can just add the Loader object using the addChild() method:
Code:
var myLoader:Loader = new Loader();
var myURLRequest:URLRequest = new URLRequest("ExternalFileA.swf");
myLoader.load(myURLRequest);
Placeholder_mc.addChild(myLoader);
This will apparently add myLoader to the display list once it has completely loaded.The 2nd method, you supposedly can add the Loader.content; however, it appears you can only do this once the content has completed loading, so you need to incorporate an event handler with the contentLoaderInfo object:
Code:
var myLoader:Loader = new Loader();
var myURLRequest:URLRequest = new URLRequest("ExternalFileA.swf");
myLoader.load(myURLRequest);
[code]....
What are the pros/cons of adding the entire Loader object, as opposed to the Loader.content and vice versa?
View 7 Replies
Jan 3, 2006
f you know PHP...then you know that you can create a string variable...and then use the value of that variable to declare another variable. like this:
PHP Code:
<?php$foo = "haha";$i{$foo} = "success";print $i{haha};?>
and it would display "success"...or like this:
PHP Code:
<?php$foo = "haha";$$foo = "success";print $haha;?>
and it would also display "success".
View 6 Replies
May 15, 2011
i have a variable take away another variable which makes answer1 variable i then want answer1 to be to the power of another variable how can i do this in flash
View 5 Replies
Jul 9, 2009
What I have is a function that occurs every second. Every time this function is called, it will add two movie clips from the library onto the screen. I am wondering if there will be a problem if my function keeps on continuously adding children to my scene?
Code:
import fl.transitions.Tween;
import fl.transitions.easing.*;[code].............
View 6 Replies
Jul 17, 2009
Im wondering if its possible to arrange movieclips with addchild in such a way like this?:[code]mc_1 and mc_2 is in my case a forward and back button (obviously these have to be on top all the time).. mc_3 - 6 is images rotating.
View 2 Replies
Mar 7, 2009
I'm new to programming in general, so not only are the basic concepts new to me but OOP and all of the various underlying rules are keeping me very frustrated in this learning process..I've reached a point that I'm simply stuck and can't find the solution through trial and error, and perhaps am not grasping how addChild works. traces just fine, but then when I try to run addChild I get "error 1023: stack overflow occurred: at Bullet$iinit()".Ignore the commented out lines, they're just for some testing and some trial and error).
//Bullet Class
package {
import flash.display.MovieClip;
[code].....
View 2 Replies
Jan 15, 2009
I have a movie clip that I add Bitmaps by using addChild(). I was wonding how would I go about displaying the next image that I added because as of now it is stuck on the first image.
View 3 Replies
Aug 1, 2009
where addChild comes from? Is it pre-built in or does it com from importing Flash.display. Sprite (and if it is from Flash.display.Sprite, does it mean it gets imported whenever you display *any* subpackage of Flash.display?)
View 1 Replies
Aug 29, 2007
Code:
var fruit1:String = "apples";
var fruit2:String = "oranges";
var fruit3:String = "grapes";[code]....
I need the variable fruit1, but for reasons I don't have time to get into, I don't know how to parse these two variables to make a parseable variable.
View 1 Replies
May 12, 2009
I am trying to add and remove children from the stage using a string. the string takes the instance name from the button pressed and i want to use that string to add a child from my library and its giving me:
"TypeError: Error #1034: Type Coercion failed: cannot convert "Floor2" to flash.display.DisplayObject."
I realize i have to make the string into the actual object but not exactly sure how.
Code:
var rollstr:String = this.toString();
var Floor1 = new floor1();
var Floor2 = new floor2();
[Code].....
View 2 Replies
May 6, 2010
I am looking at an xml file, and creating a big list of visible buttons for each "flag" via addchild().
One of the subsets of each "flag" button in the xml is "Content"
I've been reading a lot on this but I'm just getting more and more confused. Can someone break down for me:
How to pass the xml Content to each addchilded button, so it can then pass that Content to a function when it's clicked.
The Content is a string, like "Flag40.swf" which is the file I want my function to load when I click the button. I have everything working except for getting each button to tell my function which .swf to load.
View 1 Replies
Mar 29, 2011
I had a previous old script working with AS2 and have tried to convert it as the new system requires AS3 .the below script :
function displayItems() {
var xPos = 0;
var yPos = 0;[code].....
This gives me the following for the bolded line
Scene 1, Layer 'as', Frame 1, Line 44 1067: Implicit coercion of a value of type String to an unrelated type flash.display:DisplayObject.
This line used to be addmovieclip which worked. I'm not sure how to edit this to suit the new addchild method.
View 12 Replies
Apr 8, 2011
Is there a way besides pasting frames inside a layer to add an element into a timeline? I'd like to replicate the addChild functionality from actionScript into JSFL. So basically, I'd like to add a bunch of movieClips instances into another movie clip, does anyone know how to do this in JSFL?
View 1 Replies
Jun 26, 2009
I need to have five radiobuttons as a group, which needs be duplicated some n times.The following code works fine in Flash 8, But i dont know how to do it in Flash CS3, As i am new to this.thisFollowing is my code in flash 8:
for (i=1; i<6; i++) {
_level0.attachMovie("radioFiveGroup", "rg"+i, _level0.getNextHighestDepth());
this["rg"+i]._x = 200;
[code]......
View 2 Replies
Oct 15, 2009
I have an array with names referencing movieclips, how do I add them so that I can control them in a function? I want to control each one seperately.
If I wish to control the .x value of say myArray[1][6][12] do I have to call them individualy as in:
myArray[1].x+=128
myArray[6].x+=194
myArray[12].x+=236
Or can I control say the X coordinates of a bunch of movieclips in one line of code?
Here is my code:
ActionScript Code:
var myArray:Array = new Array();
var star:mcStar;
//var xpo:Number = new Number (Math.ceil(Math.random()* 400));//ignore
[Code]....
View 4 Replies
Jan 27, 2010
I am working on an Augmented Reality project .. This is the code that is called when the marker makes contact with the webcam.
[Code]...
Every time I remove the marker and put it back in view .. this script is called and is causing the action to duplicate itself over and over each time the marker is present. How can I do some sort of check to see if this is already added so that it wont duplicate ?
View 9 Replies
Feb 9, 2010
I am trying to addChild to Movie Clip by its instance name but can't do it.
Here is what I get when I trace my loader.name
MC_0
MC_1
MC_2
MC_3
Now I want to add a child to MC_2 but can't do it.
I tried
this[MC_2].addChild(player)
MC_2.addChild(player)
InfoMcHolder_mc[MC_2].addChild(player)
[Code]....
View 6 Replies
Jul 22, 2010
I still don't fully understand the way Flash works. (or both) I've made this class, objWipeable. It has three properties
wipeContainer is a Sprite that has a mask attached to it. Any display object passed in via addChild is added to wipeContainer because I've overridden addChild.
wipe is a MovieClip animating a blackboard being wiped clean - it is wipeContainer's mask. hand is a MovieClip showing the hand doing the erasing. It should be ObjWipeable's only child.
If I create a new ObjWipeable and add something to it:
[Code]...
View 6 Replies