ActionScript 3.0 :: Flash - AddChild Dynamically Using A Variable?

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


Similar Posts:


ActionScript 3.0 :: AddChild Can't Add Dynamically Created Mcs?

Aug 30, 2009

I used a loop to create a series of instances of a class called "Ball": ball_0, ball_1, ball_2, etc.But then somewhere else I need to add them on the stage. When Iusestage.addChild(Ball("ball_"+ballNum)) it gives me this error:TypeError: Error #1034: Type Coercion failed: cannot convert "ball_3" to Ball.(ballNum was set to 3 at that time)it seems there's a new syntax (or something) that I don't get. I get the same type of errors when using other functions such as stage.contains()

View 9 Replies

ActionScript 3.0 :: Dynamically Name Objects In A For Statement Using AddChild?

Jan 26, 2009

I was wondering where did go the for statement with attachMovie from library in AS 3.I mean i was having in AS 2:

for (i=0; i<5; i++) {
attachMovie("sim", "sim"+i, i);
}

Now in AS 3:

for (var i=0; i<5; i++) {
addChild(new sim());
}

I can't figure out how to name every instance of the "sim" object from library that i add to the stage without using string.How do I dinamically name the added instances of the object from the library for future reference and usage throughout the code?

View 9 Replies

Addchild - Removal Of Dynamically Created Sprites?

May 24, 2010

import flash.display.Sprite;
import flash.net.URLLoader;
var index:int = 0;[code].......

I am relatively new to flash and action script as well and I am having a problem getting the sprite to be removed after another is called.I am making emission spectrum's of 3 elements by dynamically generating the mask over a picture on the stage. Everything works perfectly fine with the code I have right now except the sprites stack on top of each other and I end up with bold lines all over my picture instead of a new set of lines each time i press a button.I have tried using try/catch to remove the sprites and I have also rearranged the entire code from what is seen here to make 3 seperate entities (hoping I could remove them if they were seperate variables) instead of 2 functions that handle the whole process.

View 2 Replies

ActionScript 3.0 :: Dynamically Setting AddChild Reference Name?

Feb 10, 2009

I'm trying to dynamically set the addChild linkage identifier, but am having little luck.

Code:
for(i=0;i<6;i++){
if(i==this.myId){
var section:MovieClip = "section"+i
this.addChild(new section);
}}

In AS 2.0 I could simply do this:
Code:
attachMovie("section"+i, "section",0)

View 2 Replies

Flex :: Dynamically Create F4 AddChild Actions For States?

Dec 27, 2010

I have an application in which I need to create mx.states.State objects on the fly, as I'm reading external data in order to create the states. Each State only has a single child, so here's my code which I was using to accomplish this[code]...

View 2 Replies

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

ActionScript 3.0 :: AddChild With Variable Name And Access It Afterwards

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

ActionScript 3.0 :: Use A Variable Inside AddChild()?

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

ActionScript 3.0 :: Referencing Variable In AddChild?

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

ActionScript 3.0 :: Dynamically Creating Movieclip And Mask For It, Then Using Addchild Renders White Bg?

Sep 12, 2009

I am dynamically creating a movieclip,

[Code].....

Then when I add something else as a child in this class, the mask is still applied to the gallery and it crops it accordingly, however the background in it turns white and hides whatever was behind it. For instance, there is space between the rectangles in the gallery movieclip and then a backdrop from the main class's movieclip shows behind it. When I called "addChild", the space between the rectangles becomes white. The background of gallery renders totally white.

View 2 Replies

As3 :: Flash - Dynamically Name A Variable On An Object?

Feb 11, 2012

So, if I need to give a custom variable name to an object how would I do that?

For instance, if I have a gameID that is 12345 and its rating is 3 I want to save a variable called gameRatings_12345 thats value is 3 in my shared local object.

//share object
protected var mySavedData:SharedObject = SharedObject.getLocal("mySavedData");

I have the game id in a string

var gameID:String = "12345";

Then when I try to assign the value like this...

mySavedData.data.gameRatings_gameID = 3

I think it's literally reading it as "mySavedData.data.gameRatings_gameID" instead of "mySavedData.data.gameRatings_12345"

How can I give the variable a custom name?

View 2 Replies

Actionscript 3 :: Dynamically Get A Variable From HTML In Flash

Feb 27, 2012

I have a case where I have a "drop-down box" in an HTML webpage with some JQuery calculations, looks something like this:[code]What I'm trying to do is have this Flash ActionScript 3 Application (embedded on the same HTML page) grab a variable from the drop-down box. Now, using FlashVars is fine, except it doesn't account for when the selection is changed (obviously), but..Is there a way to reload the variable into Flash real-time when the user changes the drop-down box selection?

View 1 Replies

ActionScript 3.0 :: DisplayObject And AddChild - Use The Variable OpenType In The Call For The Image??

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

ActionScript 3.0 :: Assign Value To A Dynamically Created Flash Variable?

Jun 27, 2009

I want to change the value of a variable which is inside another flash movie .I have loaded the swf file.Inside the 'onLoadInit' function i wrote the code like below.

[Code]...

View 2 Replies

Javascript :: Dynamically Assign Variable From HTML To AS3 Variable

Sep 12, 2011

I have an HTML button that I need to dynamically assign to an AS3 variable when clicked (in order to load an .mp3). I am using externalInterface.call to collect javascript variables - I am just unsure how to change these dynamically when a button is clicked.

View 2 Replies

ActionScript 2.0 :: Adhere A Variable To A Variable, Dynamically?

Sep 19, 2009

I have 14 buttons, and each one declares a variable; example:

[code]...

On the next frame I have another 14 buttons, and on Release I want to create a new variable with the content of _root.competencia; example:

[code]...

Instead Flash tells me this: Left side of assignment operator must be variable or property.Its what Im trying to do possible? Hope somebody can help me, has been 2 days, and I cant understand what is going on, I have tried a lot of ways without positive results, I know I have a long way to go to learn actionscript, Im to new in this!

View 2 Replies

ActionScript 3.0 :: AddChild From A Class - Get The Error "1180 : Call To A Possibly Undefined Method AddChild?

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

ActionScript 3.0 :: Box2d Addchild - 41061: Call To A Possibly Undefined Method AddChild Through A Reference With Static Type Class

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

ActionScript 3.0 :: Difference Between Mc.stage.addChild And Mc.addChild?

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

ActionScript 3.0 :: Difference Between AddChild And Parent.addChild?

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

Use A Variable And Then AddChild With A RemoveChild For The Old MovieClip After The New MovieClip Has Loaded

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

ActionScript 3.0 :: AddChild, RemoveChild And AddChild?

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

ActionScript 3.0 :: Load External SWFs, AddChild(Loader) Versus AddChild(Loader.content), Etc?

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

ActionScript 3.0 :: Change Variable Value Dynamically?

Apr 13, 2011

[code]....

need a way to change from tile0 to tile1 through variable [code]....

View 3 Replies

ActionScript 3.0 :: Loading Variable Dynamically Through XML

Jul 22, 2009

How to add a child to the stage dynamically? I can get a child to add to the stage but not using dynamic variables. Is it possible?
Example:
var firstRoundWinner:String = "Redsquare";
var mc:MovieClip = new firstRoundWinner();
// want it to say = new RedsquareaddChild(mc);
With Redsquare as one of my movieclips and the linkage is working. I can add it if I hard code it. But I want to load the variable dynamically through xml.

View 1 Replies

Flex :: Dynamically Embed Variable In It?

Dec 14, 2011

My requirement is not to dynamically embed fonts in Flex, but to dynamically embed variable in Flex.[code]...

View 3 Replies

ActionScript 2.0 :: Change Variable Name Dynamically?

Jan 8, 2010

how can i change variable name dynamically

ActionScript Code:
i=2
vari + "i" = 7 //these don't work
//i need to trace these code
trace(vari2)

i allways get error. i've tried the bracket none worked for me like these quotation

View 1 Replies

ActionScript 2.0 :: Change The Variable Dynamically?

Aug 23, 2004

how do i change this variable dynamically?

[URL]

View 6 Replies

ActionScript 2.0 :: Creating A New XML Variable Dynamically

Dec 19, 2006

Is there a way to create a new XML object dynamically? i need to do this because i don't know how many xmls there will be.[code]

View 12 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved