Children Referencing
I am making a Jewelry Builder, where there is a certain number of slots created at runtime, these movie clips are created in a sprite called "frames". There are two other sprites called "jb" for jewelry box, and "bracelet".
basically what needs to happen, is if you drop a bead on a slot that a bead already occupies, if the next slot over (next movieclip in the "frames" sprite) is unoccupied, the bead slides over. the problem im having is checking the ".assigned" variable assigned to the slot next to it in "frames"
With this:
trace(frames.getChildByName(event.target.dropTarge t.parent.dropTarget.parent.name).x);
i am able to get the x cord value for the slot under both both beads, but a variable declared earlier in the script ".assigned" cannot be called.
the bead you drop is the event.target, and bead you dropped it on is the dropTarget.parent, and then the frame underneath that bead is the second dropTarget.parent.
there has to be a better way to call child movie clips and access all the variables assigned to them can anyone help?
FlashKit > Flash Help > Actionscript 3.0
Posted on: 03-19-2008, 11:21 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Referencing Added Stage Children
I am trying to reference a child I added named "userInfo_mc" with nested inputText named "inputEmail". But I am getting this error when compiling referencing the line inside the userInfoSubmit function :
1120: Access of undefined property userInfo_mc.
Any Ideas? Any help is appreciated
Attach Code
function individualAccount():void
{
var userInfo_mc:UserInfoMC = new UserInfoMC();
addChild(userInfo_mc);
userInfo_mc.emailInput.addEventListener(MouseEvent.MOUSE_OVER, showEmailInfoBubble);
userInfo_mc.emailInput.addEventListener(MouseEvent.MOUSE_OUT, hideInfoBubble);
userInfo_mc.continue_btn.addEventListener(MouseEvent.CLICK, userInfoSubmit);
}
function userInfoSubmit(event:MouseEvent):void
{
if (userInfo_mc.emailInput.text == ""){
trace("Fill this out!");
}
}
How Do I Reference A Objects Children's Children?
I have a movieclip buttons_mc
it contains many movie clips that it adds at runtime.
each one of this movieclips has a textfield called num_txt.
if I try buttons_mc.getChildAt(j).num_txt.text = 5
I get an error. but I know I am referencing the movieclip correctly because I can move it my buttons_mc.getChildAt(j).y = 50;
So how do I change the objects textfield?
I can change the text when I added the movieclip:
Code:
mybtn = new btn();
mybtn.num_txt.text = String(i);
buttons_mc.addChild(mybtn);
but sometimes I need to rechange the text later....how can I do that?
THanks
Accessing Children Of Children?
Hello,
How do i access the child of a child in the display list of my flash AS3 program?
if for instance i have a container with lots of other movie clips inside, which each then have 2 children, a text field (place 1) and and a shape. (place 0)
do I go:
Code:
container.getChildAt(12).getChildAt(1).name
to retrieve the name of the text field?
any help is greatly appreciated.
thanks,
AS3: Removing Children Of Children
I have created a container movieclip called gameCanvas which I've added to the stage. I then have a large number of movieclips which have been added as children of gameCanvas. The reason I did this is because I thought that I would be able to get rid of all these children in one go by removing gameCanvas. Obviously I was wrong! gameCanvas is removed successfully, but all the child movieclips remain.
Is the only way to remove all the children of a container movieclip to loop through each one of them in a for loop?
And what happens to all those orphaned children - do they become children of their grandparent - ie. the parent of gameCanvas (in my case, the stage)?
Targeting Children Of Children
I thought i had this worked out....
menuCont is a MC on the maintimeline with 4 children... which trace correctly with the code I have below. the children are all instances of a custom class. Within each there are more children. I have tried a bunch of different combos to target these children. such as:
ActionScript Code:
menuCont.getChildAt(1).getChildAt(1).mouseEnabled = false;
but i keep getting this:
Quote:
1119: Access of possibly undefined property menuCont through a reference with static type flash.displayisplayObject.
ActionScript Code:
if (menuCont.getChildAt(1).alpha > 0) {
imgContainer.alpha = 0;
for (var i:int=0; i< menuCont.numChildren; i++) {
menuCont.getChildAt(i).menuCont.getChildAt(i).x = 34;
// this traces all 4 children's names
trace(menuCont.getChildAt(i).name);
// I am having trouble targeting the children of this
if (menuCont.getChildAt(i).name == "web_bm") {
//trace(this.target.numChildren);
}
//
/*if (menuCont.getChildAt(i) is GenWorkBtn && menuCont.getChildAt(i).name.substr(0,1) == "w" ) {;
//menuCont.getChildAt(1).getChildAt(1).mouseEnabled = false;
menuCont.getChildByName("pr").getChildByName("pr");
}*/
}
Adding Children To Children
Just to double-check, is it possible to do something along these lines?
ActionScript Code:
mc1.mc2.addChild(mc3);
Basically I want to dynamically add a child within a child clip that has been added to a content area. Does the Display List support this?
Thanks in advance as always.
Children Children
Hi All,
First post so many thanks in advance for this fine website and service.
The problem i have is that my navigation is on the root timeline, and i use this to load in differnt movies with the loadMovie command (relatively simple). I am wondering though, is it possible to control the timelines of the movies i load in from the root swf? basically, i want to be able to send the movie which is loaded in, to an outro when i click a button on the root timeline. Hope this makes sense, if anyone can tell me how, or if this is possible that would be fantastic.
Cheers people.
ID Of Children
Hello ....
I have a VBox that I am dynamically adding checkBoxs to. Each checkbox has a unique ID. That works fine.
Now I need to have access to each of those checkbox's ids so I can tell which ones where checked, disable and enable them, etc.
Can someone help me with that?
Thanks
Help With Children
i have a minor issue im trying to work out. i have a bunch of swf's that get loaded from an XML file into an array in the container swf. that array then shuffles itself and places a child swf (1 of 9, loaded from the XML file) into one of 4 movie clips randomly, which are on the stage of the container swf. i have mouse over, down, and out actions, when the user clicks down on one of the movie clips id like to load and display some text dynamically in a text field named "textBox". its very basic, but just in case you need it the mouseDown code is below:
if(e.type == "mouseDown"){
trace ("mouse has clicked "+e.currentTarget.name);
textBox.text = "place holder";
}how can i determine what array object is currently the child of the e.currentTarget MC? if i could determine that i believe i could use it to then grab the related xml text and display it.
[AS3] Get All Children
Hi guys,
Is it possible to get all of the children in a display list, or would I need to override addChild and removeChild etc and keep references to them in an array (or Dictionary)?
Accessing Children Of MC
i want to write a function that clears all input - textfields in a movieclip automaticlly. it should iterate through all objects within a movieclip, find out if it is a dynamic textfield and if then it should set it's text to "". is this possible?
thanx
_visble On Children MCs
Hey all, I wonder what is the quickest way to set the _visible property of all the children of a Movie Clip.
Eg: I have a movie clip called mc1 which contains mca, mcb and mcc.
I want to set mca, mcb and mcc visibility to false
Must I use for...in or something?
Thanks for answering ^^
Removing Children
Hello,
I have an empty MC on my stage, and throughtout my movie several different functions and buttons are loading a different jpg each into it at different times. I am having a problem where each of these jpgs has a different URL they are linked to, and when I do a trace it seems like each jpg is appearing over the top of the other one, so when I click on one of them I simultaneously click on all the jpgs below it.
Seeing I have no way of knowing what jpg is currently in the MC on the stage at any given time, is there any way to unload any jpg that just may happen to be in it?
Thanks!
[as3] Getting Xml Elements/children?
my xml file
Code:
<cookbook>
<recipe>
<type>string</type>
<name>string</name>
<serves>int</name>
<ingrediant amount="int" unit="string" name="string"/>
<ingrediant amount="int" unit="string" name="string"/>
<ingrediant amount="int" unit="string" name="string"/>
<step>string</step>
<step>string</step>
<step>string</step>
</recipe>
</cookbook>
how do I access the amount, unit and name of the ingrediants?
atm I got
Code:
for(i=0;i<cookbook.recipe[mealNumber].ingrediant[i].length();i++){
ingrediants.appendText(cookbook.recipe[mealNumber].ingrediant.amount[i] + " " + cookbook.recipe[mealNumber].ingrediant.unit[i]);
}
That's not working
Some Children Not Being Masked
I have a Sprite containing several DisplayObjects. All of the various Bitmaps and Sprites contained within are masked just fine. But I have several TextFields that are ignoring transparency, and are being masked by the bounds of the mask object.
My mask is a rounded rectangle Shape (the text is being masked as if it were a regular rectangle fill).
I have already encountered several instances, where incorrect order of my code has caused problems. If I declared everything about a TextField, and then set 'text.defaultTextFormat = format' last, none of the TextFormats were applied. But simply moving that line towards the beginning of my TextField declarations fixed the problem.
Is this a similar case? How can a TextField ignore the mask that every other child is following just fine? Where should I look for problems? Are there certain procedures which must be followed, and how would you break those?
Thanks in advance.
Problems With Var's And Children
So I got my movie to almost work like I want it to. Three buttons each draw three different boxes with different names, each button first removes any other instances of another box already on the stage before drawing a new box.
This seems to work fine, but if you keep clicking each button they stop removing the boxes and just draws the new one over the previous box.
can somebody please have a look at my class file and tell me if you can see anything funny there (apart from my newb way of coding)
This is the link so you can get an idea of what I'm talking about
www.crystal-concept.com
Remove All Children
ello
well I'm starting to really enjoy AS3, my next question then is this:
in AS2 I'd often remove all movieclips with something like this:
PHP Code:
for(var i: String in container) {
container[i].removeMovieClip();
}
is there something similar in AS3 that I can do without resorting to maintaining an array of references to each child of my container?
thanks
CopyPixels() On Top Of Children ?
Hi guys,
I have a basic game engine where I use copyPixels() to blit all my objects. The problem is that I also need to blit text and since I have to use a TextField that is a child it always gets rendered on top of what I blit. The same thing happens if I want to put a button on the gamescreen.
It would be nice if I could create the text and interactive objects without making them children and somehow use copyPixels() to render them.
Any ideas ?
Thanks.
Trace( All Children ) ?
Is there a way to print the instances and their positions of all children of a movieclip? I want to attach a movieclip with the attachMovie funciton, but am not sure where it has gone to so it would be nice to call a function of its parent to let it spell out all its children.
For now:
Code:
trace(comicstrip.contentMain);
theComic = comicstrip.contentMain;
theComic.attachMovie("logo", "comication_logo", 747);
theLogo = comicstrip.contentMain["comication_logo"];
trace(theLogo);
for now, the first trace returns the correct path, but the second trace is 'undefined'
Remove All Children
Is there a code to remove ALL children, ive done a little search but can't find anything?
Cheers
Get Root Children?
Hello
Is there any way around then this below, because it aint working
var arr:Array = ['step1']['step2'];
trace(TopLevel.root.arr)
Thanks in advance...
List Of Children
Is it possible to get a list of children of a displayObject? or at least the number of children. At the moment i'm using the below but it feels awkward.
ActionScript Code:
do {
childArray.push(this.content.getChildAt(i));
i++
}
while (this.content.getChildAt(i) != null);
Difference Between * And Children()
What exactly is the difference between using * and children() when accessing and XML object?
ActionScript Code:
var xml : XML = <main>
<item>foo</>
<item>bar</>
</main>
trace(xml.*, xml.children());
They both return an XMLList containing the children of the XML object. Is there any performance gain over one versus the other when working with large XML trees?
Deleting All Children?
Im new to actionscript 3 and havent used flash in a long time but anyway im sort of making a few pages with buttons on them that when pressed will go to anouther page. To make the pages ive used indevidual movieclips and ive set the linkage for the to export for actionscript.
The problem im having is with displaying them and then deleting them when you go to a new page.
ActionScript Code:
//On a layer in the scene ive got this code:
this.addChild(new MainMenu());
//then in the movieclip's actions ive got this:
p1wb.addEventListener(MouseEvent.MOUSE_DOWN, loadphase1);
function loadphase1(e:MouseEvent):void {
this.parent.addChild(new phase1());
}
Ofc with this everytime you go to a new page the last page is still there so after abit of navigating it start to lag. Im wondering if it possible to delete all children from the scene before adding the new child? ive looked around but could only find removeChild() which im not sure how to use as they dont have names.
thanks in advance
Removing Children
I'm creating a menu using the code below (site uses drupal with a services module and amfphp - to explain the bits hanging on to the code). A class menu is defined elsewhere in the code, drupal is an included class:
Code:
private function cbConnect():void {
// send request
drupal.service(cbArticles, onFault, "views.getView", "gallery");
}
private function cbArticles(result:Object):void {
for (var i = 0; i < result.length; i++) {
menu.addItem(result[i].nid, result[i].title, result[i].body, null);
}
}
Items are added like so:
Code:
public function addItem(id:Number, title:String, body:String, image:String) {
mTitle[id] = title;
mBody[id] = body;
mImage[id] = image;
var obj:MenuItem = new MenuItem(id, title, mWidth, mStyle);
obj.x = 0;
obj.y = mNum * obj.previewHeight;
obj.addEventListener(MouseEvent.CLICK, onclick);
obj.addEventListener(MouseEvent.ROLL_OVER, onrollover);
obj.addEventListener(MouseEvent.ROLL_OUT, onrollout);
obj.buttonMode = true;
addChild(obj);
mItem[id] = obj;
mNum++;
}
If i want to rebuild the menu with a new request how do i clear all those items added to the menu so far?
E4x Finding Any Vs. All Children
Hi,
Seems simple enough but I am having a bear of a time parsing some XML and no tutorial that I have seen has been over this issue.
Here is some XML:
Code:
<item>
<filters>
<Categories>
<type>Classes</type>
</Categories>
<Keywords>
<keyword>Agency</keyword>
<keyword>Mutation</keyword>
<keyword>Selection</keyword>
</Keywords>
</filters>
</item>
<item>
<filters>
<Categories>
<type>Instances</type>
</Categories>
<Keywords>
<keyword>Fitness</keyword>
<keyword>Awareness</keyword>
<keyword>Intelligence</keyword>
</Keywords>
</filters>
</item>
Now this works no problem:
ActionScript Code:
var filterList:XMLList = parItem.item.(filters.child("Categories").* == "Classes");
trace(filterList); // returns the items that contain "Classes"
but as soon as I look at a node like "Keywords" with more than 1 child I get nothing. here is an example:
ActionScript Code:
var filterList:XMLList = parItem.item.(filters.child("Keywords").* == "Awareness");
trace(filterList); //returns nothing
I think the .* is indicating that ALL children have to have "Awareness", not just one. Is there a way to use E4X without having to put this stuff into Arrays? Thanks for taking a look!
P.s. I have also tried .*, children(), and child("*") ~ they all mean the same thing.
Removing The Children
First off, I'll show you my code:
ActionScript Code:
var ballTimer:Timer = new Timer(500);
ballTimer.addEventListener(TimerEvent.TIMER, addBall);
function addBall(event:Event):void
{
var ball:Ball = new Ball();
ball.y = Math.random() * 480;
ball.x = -50;
addChild(ball);
ball.addEventListener(Event.ENTER_FRAME, updateBall);
}
function updateBall(event:Event):void
{
event.target.x = event.target.x + 5;
}
ballTimer.start();
Basically, I'm adding and moving circles on the x axis after randomly placing them on the y axis. It works great, but after a while the flash starts lagging due to the balls not being removed. I know I'm supposed to removeChild(ball) when their x = 650, but I don't know how to assign that to every ball that gets added on the stage. Can someone help please?
Children Under Container
I have a Sprite defined as container, and I have children under them; how would I find all the children's names under the container?
New DisplayObjectContainer Contains Old Children?
I'm using a sprite as a container for various DisplayObjects, but there come a time when I need to clean the screen of them and load new ones.
Lets assume the container is s: So, I removeChild(s), and then set s = new Sprite();, Since nothing "points" to its children anymore I assumed they are gone. But when I add it again, instead of being empty (because I assigned a new Sprite in there), the old DisplayObjects pop out again.
So I've tried another approach - iterating using numChildren and removeChildAt(i), but not all the DisplayObjects are removed this way. Do I have to set a depth for them manually when I add them to the stage, or is there another way to solve this out which doesn't involve iterating on the container?
XML Counting Children
kk guys, me again here...
I tought out a pretty easy script to parse my XML files, but now I need to count the times there are links in a category withour making too many changes to my script...
(exept the counting part of course!)
here's my xml:
Code:
<?xml version="1.0"?>
<webdesk>
<deskname>Sandshark's Test WebDesk</deskname>
<deskdescription>On this webdesk we will test create the flash menu</deskdescription>
<category>
<catname>Eerste categorie</catname>
<link>
<description>WebAssistant WebSite</description>
<location>http://www.webassistant.com</location>
</link>
<link>
<description>Ecotopia WebSite</description>
<location>http://www.ecotopia.be</location>
</link>
<link>
<description>Google WebSite</description>
<location>http://www.google.com</location>
</link>
</category>
<category>
<catname>tweede Categorie</catname>
<link>
<description>Cnn</description>
<location>http://www.cnn.com</location>
</link>
<link>
<description>Microsoft</description>
<location>http://www.microsoft.com</location>
</link>
<link>
<description>Apple</description>
<location>http://www.apple.com</location>
</link>
</category>
</webdesk>
U can see that in this example i got 2 category's and 3 links in each category...
How can i tell flash to count the amount of links in that category???
Here's what i currently got for Flash MX:
Code:
urlholder = new Array();
desholder = new Array();
catname = new Array();
catlength = new Array();
catTempLength = new Array();
var deskname = "";
var deskdes = "";
j = 0;
k = 0;
l = 0;
z = 0;
s = 0;
function loadingDone() {
show(this, "", "");
}
// function to display xml object
function show(node, indent, prefix) {
var i, a, currentSpaces;
if (node.firstChild != null) {
for (i=0; i<node.childNodes.length; i++) {
if (node.childNodes[i].nodeValue != null) {
//get link descriptions
if (node.nodeName === "description") {
desholder[j] = node.childNodes[i].nodeValue;
//trace('DESCRIPTION = '+desholder[j])
j++;
}
//get link url's
if (node.nodeName == "location") {
urlholder[z] = node.childNodes[i].nodeValue;
//trace('LOCATION = '+urlholder[z]);
z++;
}
//get the webdek name
if (node.nodeName == "deskname") {
deskname = node.childNodes[i].nodeValue;
}
//get the webdek description
if (node.nodeName == "deskdescription") {
deskdes = node.childNodes[i].nodeValue;
}
//get category names
if (node.nodeName == "catname") {
catname[k] = node.childNodes[i].nodeValue;
k++;
}
//get lengh of the category's
if (node.nodeName == "category") {
if(node.nodeName == "link"){
catTempLength[s] = node.childNodes[i].nodeValue;
catlength[s] = catTempLength[s].length;
s++;
}
}
}
//trace ('value='+node.childNodes[i].nodeValue);
currentSpaces = indent;
//NEVER DELETE THIS PART, becouse otherwise all of the above will fail!
show(node.childNodes[i], indent+" ", prefix+"childNodes["+i+"].");
}
}
}
extXML = new XML();
extXML.ignoreWhite = true;
extXML.onLoad = loadingDone;
extXML.load("menu2.xml");
That's the complete code, and it all works except for this peace:
Code:
//get lengh of the category's
if (node.nodeName == "category") {
if(node.nodeName == "link"){
catTempLength[s] = node.childNodes[i].nodeValue;
catlength[s] = catTempLength[s].length;
s++;
}
}
Anyone knows how i can count the amount of links in those category's???
(the amount of the links and category's are dynamic, so can't put a locked value on that :S)
LoadClip XML Children
loadClip is not working... What is the reason for this:
trace(nodes.childNodes[1].firstChild); // images/IMG_01.jpg
loadClip(nodes.childNodes[1].firstChild, mc); // dosn't work
loadClip("images/IMG_01.jpg", mc); // does work
If I were to use loadMovie it would work... but I need to use loadClip because I need listeners.
In other words, if I used loadMovie then I could just make a for loop and load them all at the same time... but I need to load them one at a time, in order.
Attach Code
myG = new XML();
myG.ignoreWhite = true;
myG.onLoad = function(success) {
allimages = this.childNodes.length;
var nodes:Array = this.childNodes;
thisHome.createEmptyMovieClip("targetMC",this.getNextHighestDepth());
thisHome.targetMC._x = 17;
thisHome.targetMC._y = 369;
loadImages(nodes);
};
i = 0
var thisHome:MovieClip = this;
loadImages = function (nodes:Array) {
var mc:MovieClip = thisHome.targetMC.attachMovie("imageThumb","img"+i,i+1,{_x:i*27});
var imgLoader:MovieClipLoader = new MovieClipLoader();
mc._width = 25;
mc._height = 17;
var earl = nodes[i].childNodes[1].firstChild;
imgLoader.loadClip(earl, mc.fullThm);
trace(earl)
i++
if (i<allimages){
loadImages(nodes);
};
};
Removing Children ?
hello, a newbie question please:
I have an intro page with a number of sprites,movieclips.
When the user clicks "enter", a new page is loaded which covers up the old one.
Should I at this stage, as a matter of good housekeeping, remove all the children on the initial intro page, or can I just disregard them from now on ?
thanks for any advice
LoadClip XML Children
loadClip is not working... What is the reason for this:
trace(nodes.childNodes[1].firstChild); // images/IMG_01.jpg
loadClip(nodes.childNodes[1].firstChild, mc); // dosn't work
loadClip("images/IMG_01.jpg", mc); // does work
If I were to use loadMovie it would work... but I need to use loadClip because I need listeners.
In other words, if I used loadMovie then I could just make a for loop and load them all at the same time... but I need to load them one at a time, in order.
Attach Code
myG = new XML();
myG.ignoreWhite = true;
myG.onLoad = function(success) {
allimages = this.childNodes.length;
var nodes:Array = this.childNodes;
thisHome.createEmptyMovieClip("targetMC",this.getNextHighestDepth());
thisHome.targetMC._x = 17;
thisHome.targetMC._y = 369;
loadImages(nodes);
};
i = 0
var thisHome:MovieClip = this;
loadImages = function (nodes:Array) {
var mc:MovieClip = thisHome.targetMC.attachMovie("imageThumb","img"+i,i+1,{_x:i*27});
var imgLoader:MovieClipLoader = new MovieClipLoader();
mc._width = 25;
mc._height = 17;
var earl = nodes[i].childNodes[1].firstChild;
imgLoader.loadClip(earl, mc.fullThm);
trace(earl)
i++
if (i<allimages){
loadImages(nodes);
};
};
Children Confusion
I'm setting up looping logos that scroll across the screen. I was thinking the best way to do this would be to set up two containers (2 sprites) and duplicate the content inside them. Space them accordingly so they move across a 900w stage as one's x hits negative it's width it would reset behind the other and so on. This works fine and dandy if I use only one sprite, but when I put them both together it's as though the second one loads inside the first. If I set it's x value to 900 it's set to 0 when I trace it, but appears to be 900 on the stage. So I'm really confused now. Is this possible or am I doing this wrong .. still trying to grasp AS3. Thanks.
Attach Code
var logos:Array = ["1","2","3","4","5"/*,"6","7","8","9","10"*/]; // GET THIS FROM PHP FILE
var _containerWidth:Number = logos.length * 150;
var _containerX:Number = 0;
var _containerY:Number = 15;
// LOGO CONTAINERS
var _logo:logo = new logo;
var _logoX:Number = 0;
var _logoY:Number = 0;
// CONTAINER A
var _containerA:Sprite = new Sprite;
addChild(_containerA);
_containerA.y = _containerY;
_containerA.x = _containerX;
function loopA():void {
this._containerA.x = 900;
Tweener.addTween(_containerA, {x:-_containerWidth, time:10, delay:0, transition:"linear", onComplete:loopA});
}
for (var i: Number = 0; i < logos.length; i++) {
_logo = new logo();
_containerA.addChild(_logo);
_logo.x = _logoX;
_logo.y = _logoY;
_logoX += 150;
Tweener.addTween(_containerA, {x:-_containerWidth, time:10, delay:0, transition:"linear", onComplete:loopA});
}
// CONTAINER B
var _containerB:Sprite = new Sprite;
addChild(_containerB);
_containerB.y = _containerY;
_containerB.x = _containerX;
function loopB():void {
this._containerB.x = 900;
Tweener.addTween(_containerB, {x:-_containerWidth, time:10, delay:0, transition:"linear", onComplete:loopB});
}
for (var j: Number = 0; j < logos.length; j++) {
_logo = new logo();
_containerB.addChild(_logo);
_logo.x = _logoX;
_logo.y = _logoY;
_logoX += 150;
Tweener.addTween(_containerB, {x:-_containerWidth, time:10, delay:0, transition:"linear", onComplete:loopB});
_logo.alpha = .4;
}
Removing Children
i have a movie clip container that i am dynamically adding buttons to. i need to know how to remove all of the children from my container movie clip. i need to remove all of them before i re-populate the container with the new buttons.
i need a line of code that will remove all the children from a specific movie clip. (ps- the amount of children varies)
any help would be greatly appreciated.
Swap Children At Once
Hi, Please help me. I have 4 tab movieClips (Suppose 1_mc, 2_mc, 3_mc, 4_mc).
Not 1_mc is on top and covering some part of 2_mc, same as 2_mc is covering some part of 3_mc, and 3_mc is covering some part of 4_mc.
Now whenever i clicked any tab Movieclip. it should come on top of all MovieClips.
in AS2 there was a method swapDepths(This.getNextHighestDepth()) and by that we can swap current movieclip by all other MovieClips.
So is there any code in AS3 also, which can swap child at once with all the Movieclips?
I checked from setChildIndex and swapChildren too but its taking more length of code and complexity too, to understand which movieclips has to be swaped now?
Please help me to find the easy way. Thanks in advance.
Trading Children
When I click the button I can add children on top of one another forever but I need the one that loaded before to go away. I've tried a number of possible solutions to no avail. Thanks for any help you might offer.
Attach Code
import flash.display.*;
import flash.events.*;
var _mc1:MC1 = new MC1;
var _mc2:MC2 = new MC2;
btn_mc.addEventListener(MouseEvent.CLICK, loadMC)
btn2_mc.addEventListener(MouseEvent.CLICK, loadMC2)
function loadMC(e:MouseEvent):void
{
container_mc.addChild(_mc1)
_mc1.alpha = .5;
}
function loadMC2(e:MouseEvent):void
{
container_mc.addChild(_mc2)
_mc2.alpha = .5;
}
I Die: DuplicateMovieClip() W/ Children
Hi,
I have yet another "I die-problem", not so drastic this time, though. I've only tried to solve it for two hours or so, but still..... argh, it's killing me Well, as usual, I end up here, at the Kirupa forums.. and of course, l end up emptying the coffe-machine at work.. *runs for more espresso*
Now;
It's an issue regarding the duplicateMovieClip function. I know how it works, and I know how to duplicate MovieClips using the function, however, I do have an issue figuring this out: Now, explained roughly:
I have a MovieClip which contains yet another MovieClip. I want to duplicate both the MovieClip and it's child, but I want it to stay inside the parent MovieClip, just as the original MovieClip contained the original child.. (but both of these are duplicates, of course..)
myMovieClip -> myMovieClipChild
duplicates to:
myMovieClip0 -> myMovieClipChild0
myMovieClip1 -> myMovieClipChild1
and so on...
In case you don't have it next-door, the code for duplicating a movieclip can be found here.. (kirupa.com)
I just can't figure this out. If anyone can help, in any way, I'd appreciate aLOT (as always )..
Now, how?
Hurry!, before them 's gets me!
Thanks for your help,
Peter
[AS3] Locate MC Children
Okay. I have an MC that has three frames, in which each frame has a different MC on the timeline.
When I am on frame one, I can target the child and modify it. However, when I am on frames two or three, I cannot locate the child MC eventhough it exists (numChildren comes back as 1);
Frame 1:MC.currentFrame = 1
MC.numChildren = 1
MC.getChildAt(0) = [object MoviClip]
Frame 2:MC.currentFrame = 2
MC.numChildren = 1
MC.getChildAt(0) = null //(also getChildAt(1), etc.)
Frame 3:MC.currentFrame = 3
MC.numChildren = 1
MC.getChildAt(0) = null //(also getChildAt(1) & 2, etc.)
How the heck do I target the MC on frames 2 and 3. Note that this occurs if I place them on the same layer or all on seperate frames of the same layer.
Help appreciated! Thanks.
Xml Total Children
i would like to find out how to figure out children a node may have.
for example lets say i have this xml doc
Code:
<xml>
<data>
<thingy>text</thingy>
<thingy>text</thingy>
<thingy>text</thingy>
<thingy>text</thingy>
</data>
</xml>
how would i figure out that the node data has 4 children?
Getting All Children Of XML Node
hey,
I got some old XMLs where the single nodes are not closed with /tag:
<tag attrib="1" />
as oppose to
<tag attrib="2" ></tag>
now i did the little following code
_xmlData = new XML();
_xmlData = <test name="root">
<item name="item1" />
<item name="item2"><sub name="sub1" type="dead"/></item>
<item name="item3" />
<item name="item4"><sub name="sub1"/></item>
</test>;
_xmlCurrentSelection = new XMLList();
_xmlCurrentSelection = _xmlData.descendants("item");
for each( var item:XML in _xmlCurrentSelection)
trace("item: "+item);
where xmlCurrentSelection is XMLList, now the output is :
item:
item: <item name="item2">
<sub name="sub1" type="dead"/>
</item>
item:
item: <item name="item4">
<sub name="sub1"/>
</item>
notice that item1 and item3 are not printed out - i wonder why?
i am used to <tag /> and <tag></tag> being the same (or at least feeling very much the same).
any idea on how to reach those objects?
Children Affecting Each Other
Hey
This is my first post I'm getting into AS3 and i'm having trouble with my children affecting each other. This is the code
Code:
package {
//
//
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.Shape;
//
//
public class Waves extends MovieClip {
//
//
private var main_wave:Wave;
private var temp_wave:Wave;
//
//
public function Waves() {
trace("Waves");
loadMainWave();
}
//
//
private function loadMainWave():void {
trace("loadMainWave");
this.main_wave = new Wave();
this.main_wave.blendMode = "overlay";
this.main_wave.alpha = 1;
this.main_wave.scaleY = 0.7;
this.main_wave.x = 0;
this.addChild(this.main_wave);
this.temp_wave = new Wave();
this.temp_wave.blendMode = "overlay";
this.temp_wave.alpha = 1;
this.temp_wave.scaleY = 1.5;
this.temp_wave.x = 0;
this.addChild(this.temp_wave);
var ref:Shape = new Shape();
ref.graphics.beginFill(0xff0000);
ref.graphics.lineStyle(0, 0x000000);
ref.graphics.drawCircle(2, 2, 2);
ref.graphics.endFill();
ref.x = 0;
this.addChild(ref);
}
}
}
Wave is a animated (tweened) movie clip. Now if i change
Code:
this.temp_wave.x = 0
to another value, say 100, then ref, temp_wave and main_wave, all move across. Temp_wave and main_wave no longer line up though.
Now, i'm pretty sure this shouldn't be happening slash i don't want this to happen. First i thought that i might actually be moving the graphic inside the movie clip (i hope not) but that doesn't explain why ref would move as well.
Can anyone see what i'm doing wrong? I tried searching for answers, but i'm not even sure what i'm really looking for.
Cheers
Lango
****EDIT****
The same thing happens if i change main_wave.x, but NOT if i change ref.x
How Can I Remove All Children Like In AS3?
Hi all,
is there a way to remove all children mcs from a movie clip in a way similar to
if (mc.numChildren) mc.removeChildAt(0);
(which is AS3 by the way) but for AS2?
I need to "empty" a container movie clip from movie clips duplicated in it through attachMovie, so i can load other stuff AFTER its emptied
Any suggestions?
George
DisplayObjects And Their Children
as mentioned in many others threads we have to remove all objects we created manually.
if the DisplayObject has eventlisteners you have to remove them manually, too.
for example:
PHP Code:
var circle:Sprite = new Sprite();circle.addEventListener(Event.ENTER_FRAME, doSomething);circle.addEventListener(Event.REMOVED_FROM_STAGE, doCleanup);addChild(circle);stage.addEventListener(MouseEvent.CLICK, doAction);function doSomething(event:Event):void { trace('enterFrame event running');}function doAction(event:MouseEvent):void { trace('removing DisplayObject'); removeChild(circle); circle = null;}function doCleanup(event:Event):void { trace('removing eventlisteners'); circle.removeEventListener(Event.ENTER_FRAME, doSomething);}
so i am still a bit confused about removing objects from the stage.
what happens to a child object, if its parent has been removed from the stage?
PHP Code:
var circle1:Sprite = new Sprite();var circle2:Sprite = new Sprite();circle1.addEventListener(Event.ENTER_FRAME, doSomething);circle1.addEventListener(Event.REMOVED_FROM_STAGE, doCleanup);circle2.addEventListener(Event.REMOVED_FROM_STAGE, stillOnStage);addChild(circle1);circle1.addChild(circle2);stage.addEventListener(MouseEvent.CLICK, doAction);function doAction(event:MouseEvent):void { trace('removing DisplayObject'); removeChild(circle1); circle1 = null;}function doSomething(event:Event):void { trace('enterFrame event running');}function stillOnStage(event:Event):void { trace('seems i was removed?');}function doCleanup(event:Event):void { trace('removing eventListener'); circle1.removeEventListener(Event.ENTER_FRAME, doSomething);}
so does circle2 still remain on the stage? is it still in the memory? will it get garbage collected? the listener tells me, that it was removed.
regards
michael
Edit:
similar article
Edit:
guess the listeners for the removement should also be removed?
PHP Code:
function doCleanup(event:Event):void { trace('removing eventListener'); circle1.removeEventListener(Event.ENTER_FRAME, doSomething); circle1.removeEventListener(Event.REMOVED_FROM_STAGE, doCleanup); circle2.removeEventListener(Event.REMOVED_FROM_STAGE, doCleanup);}
Remove All Children
Is there a quick way to remove all child instances (movie clips) from the stage without referencing each one of them by name?
RemoveChild And Children
I have an object that has children. When I remove the object it appears that children of that object are not removed. How can I ensure that all children of this object are removed as required?
Thanks.
|