Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash








AS3: AddChild RemoveChild Newbie Question


Hi all

I'm working with an update to a flash file that has the following structure:

every 10 frames is a keyframe named page1 page2 page3...etc..

in other words, page2 is frames 11-20, and so on.

Frame 1 has the following professionally written code (i.e. I didn't write it) for assigning functionality to the nav buttons that take the user from page1 to page2 and back and so on.


Code:
var pg_curr = 1;
var pg_max = 7;

myNext.addEventListener(MouseEvent.CLICK,navPg);
myPrevious.addEventListener(MouseEvent.CLICK,navPg);
myPrevious.visible = false;

function navPg( e:MouseEvent ) {
if (e.target.name=="myNext") {
if (pg_curr>=pg_max) {
return;
}
pg_curr++;
} else {
if (pg_curr<=1) {
return;
}
pg_curr--;
}
gotoAndStop("page"+pg_curr);
myNext.visible = !(pg_curr>=pg_max);
myPrevious.visible = !(pg_curr<=1);
}
[page1 is actually frames 2-10, and a keyframe in the top layer stretching from frame 2 to the end of the timeline has the stop(); script]

So far so good. Works great. Now, on page3, I have added the following code to call up an external SWF called "familyfeud.swf"


Code:
var FFrequest:URLRequest = new URLRequest("FamilyFeud/FamilyFeud.swf");
var FFloader:Loader = new Loader()
FFloader.load(FFrequest);

FFloader.x = 47;
FFloader.y = 30;
//FFloader.width = 756;
//FFloader.height = 480;

addChild(FFloader);
I have two questions about this:

1) how do I code this so that "removeChild" will remove FFloader when the user EITHER clicks forward to page4 OR clicks back to page2 (i.e. using the myNext or myPrevious nav buttons)?

2) notice that I have commented out the two lines of code that I naively thought would set the dimensions of FamilyFeud.swf within the current flash file. The thing is that the total dimensions of the current flash file AND familyfeud.swf are the same (850x540). I want familyfeud.swf to display in only part of the current flash file, so that the nav buttons at the lower right (for example) are visible and accessible. When I activate those two (height, width) lines of code, the familyfeud.swf file disappears.

3) on page5, I have another displayed swf called "CO2.swf" I plan to repeat the page3 code for page5 so that CO2.swf will behave the same way as FamilyFeud.swf (appear when user enters page5, disappear when user enters page6 or backtracks to page4).


so...if someone please help me with the following, I would be very grateful:

*how to write a generic code to removeChild on navigating forward or back from these externally-loaded SWF pages (i.e. pages 3 & 5).

*how to shrink the size of the externally loaded swf to fit within the current fla framework.


Many thanks for any advice!




ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 07-18-2008, 06:59 PM


View Complete Forum Thread with Replies

Sponsored Links:

AS3: AddChild RemoveChild Newbie Question
Hi all

I'm working with an update to a flash file that has the following structure:

every 10 frames is a keyframe named page1 page2 page3...etc..

in other words, page2 is frames 11-20, and so on.

Frame 1 has the following professionally written code (i.e. I didn't write it) for assigning functionality to the nav buttons that take the user from page1 to page2 and back and so on


Code:
var pg_curr = 1;
var pg_max = 7;

myNext.addEventListener(MouseEvent.CLICK,navPg);
myPrevious.addEventListener(MouseEvent.CLICK,navPg);
myPrevious.visible = false;

function navPg( e:MouseEvent ) {
if (e.target.name=="myNext") {
if (pg_curr>=pg_max) {
return;
}
pg_curr++;
} else {
if (pg_curr<=1) {
return;
}
pg_curr--;
}
gotoAndStop("page"+pg_curr);
myNext.visible = !(pg_curr>=pg_max);
myPrevious.visible = !(pg_curr<=1);
}
[page1 is actually frames 2-10, and has the stop(); script]

So far so good. Works great. Now, on page3, I have added the following code to call up an external SWF called "familyfeud.swf"


Code:
var FFrequest:URLRequest = new URLRequest("FamilyFeud/FamilyFeud.swf");
var FFloader:Loader = new Loader()
FFloader.load(FFrequest);

FFloader.x = 47;
FFloader.y = 30;
//FFloader.width = 756;
//FFloader.height = 480;

addChild(FFloader);
I have two questions about this:

1) how do I code this so that "removeChild" will remove FFloader when the user EITHER clicks forward to page4 OR clicks back to page2 (i.e. using the myNext or myPrevious nav buttons)?

2) notice that I have commented out the two lines of code that I naively thought would set the dimensions of FamilyFeud.swf within the current flash file. The thing is that the total dimensions of the current flash file AND familyfeud.swf are the same (850x540). I want familyfeud.swf to display in only part of the current flash file, so that the nav buttons at the lower right (for example) are visible and accessible. When I activate those two (height, width) lines of code, the familyfeud.swf file disappears.

3) note that on page5 I have another displayed swf called "CO2.swf" I plan to repeat the page3 code for page5 so that CO2.swf will behave the same way (appear when user enters page5, disappears when user enters page6 or backtracks to page4).


so...can someone please let me know
*how to write a generic code to removeChild on navigating forward or back from these externally-loaded SWF pags
*how to shrink the size of the externally loaded swf to fit within the current fla framework?

Many thanks for any advice!

View Replies !    View Related
HELP::: AddChild / RemoveChild
Good day everyone,

I was hoping someone could help me out with my addChild / removeChild code... I am using the following code for addChild but I keep receiving the error below....

my code:

var puzzle1uzzle01 = new puzzle01();
puzzle1.addEventListener(MouseEvent.CLICK, showImage);
function showImage(evt:MouseEvent):void{
puzzle1.x = 200;
puzzle1.y = 400;
stage.addChild(puzzle1);
}

This is the error:

1151: A conflict exists with definition puzzle1 in namespace internal.

View Replies !    View Related
Best Way To AddChild(); RemoveChild();?
I am getting better at AS3 but still have a while to go. I can not figure out the best way to add and remove a child from the stage in my package. Any help would be greatly appreciated.

Thanks in Advanced,
Scott

Here's the code:

package {

//import flash.display.*;
//import flash.utils.getTimer;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.Sprite;
import flash.events.*;
import fl.motion.Animator;

public class Duck5 extends MovieClip {
//var duckHit_animator:removeChild;
public var currentindex:int;
var duckHit_animator:Animator;
public var disposition:String = "good";
//public var duckHit_remove:Sprite;
//public var points:int;


function Duck5():void {
this.disposition = "good";
}


public function swim():void {
var swimTween = new Tween(this, "x",None.easeNone,82.2,82.2, 8, true);

}
public function hit():void {


var duckHit_xml:XML = <Motion duration="12" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="24" x="245.15" y="586.9" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="duckHit">
<dimensions>
<geom:Rectangle left="-85.65" top="-51" width="171.3" height="102"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5046701692936368" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
<filtersropShadowFilter distance="0" angle="45" color="0x000000" alpha="1" blurX="0" blurY="0" strength="0" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>

<Keyframe index="4" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="19" blurY="19" color="0xFF6600" alpha="1" strength="1" quality="1" inner="false" knockout="false"/>
<filtersropShadowFilter distance="-2" angle="233" color="0xFF9900" alpha="1" blurX="0" blurY="0" strength="3.36" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>

<Keyframe index="7" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="19" blurY="19" color="0xFF6600" alpha="1" strength="1" quality="1" inner="false" knockout="false"/>
<filtersropShadowFilter distance="-2" angle="233" color="0xFF9900" alpha="1" blurX="0" blurY="0" strength="3.36" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>

<Keyframe index="11" tweenSnap="true" tweenSync="true">
<color>
<Color alphaMultiplier="0"/>
</color>
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
<filtersropShadowFilter distance="0" angle="45" color="0x000000" alpha="1" blurX="0" blurY="0" strength="0" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>
</Motion>;

duckHit_animator = new Animator(duckHit_xml, this);
duckHit_animator.play();



}

View Replies !    View Related
Addchild / Removechild: How To?
Hi everyone,

this is my second thread on actionscript.org about the addchild/remove child methods. I've have encounterd several problems in try do to some simple (for many guru here) task.

I want to realize an easy function to add/remove child in an object. Assuming that i have something like a treeview:

main_MC (parent)+
|___child1
|___child2+
|_______|___ child1
|___child3+
|_______|___child1
|_______|___child2
|_______|___child1

I just want that if i click on the parent, all the child should be added/removed. The same for the other child: if i click on main_MC > child2, the child under this should added or removed. Moreover, i noticed that every child inherit the proprierties of the previuos one. Could this be avoided?
I hope i've been clear enough.

Thank you all for the precious help.

View Replies !    View Related
AddChild(...) / RemoveChild(...)
If I have

h1.addChild(abc);

and then later

h2.addChild(abc);

Is this the same as using

h1.removeChild(abc);
h2.addChild(abc);

Just wondering cause I dont want lots of references to content ive loaded thats all, anybody know..

View Replies !    View Related
Best Way To AddChild(); RemoveChild();?
First, I would like to thank, ptfury, magcius, dzhedzho, wvxvw, amarghosh, jwopitzand Rada for all of their help. I could not have gotten this far without their guidance .

I am getting better at AS3 but still have a while to go. I can not figure out the best way to add and remove a child from the stage in my package. Any help would be greatly appreciated.

Thanks in Advanced,
Scott

Here's the code:

Code:
package {

//import flash.display.*;
//import flash.utils.getTimer;
import flash.display.DisplayObject;
import flash.display.MovieClip;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.Sprite;
import flash.events.*;
import fl.motion.Animator;

public class Duck5 extends MovieClip {
//var duckHit_animator:removeChild;
public var currentindex:int;
var duckHit_animator:Animator;
public var disposition:String = "good";
//public var duckHit_remove:Sprite;
//public var points:int;


function Duck5():void {
this.disposition = "good";
}


public function swim():void {
var swimTween = new Tween(this, "x",None.easeNone,82.2,82.2, 8, true);

}
public function hit():void {


var duckHit_xml:XML = <Motion duration="12" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">
<source>
<Source frameRate="24" x="245.15" y="586.9" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" symbolName="duckHit">
<dimensions>
<geom:Rectangle left="-85.65" top="-51" width="171.3" height="102"/>
</dimensions>
<transformationPoint>
<geom:Point x="0.5046701692936368" y="0.5"/>
</transformationPoint>
</Source>
</source>

<Keyframe index="0" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
<filters:DropShadowFilter distance="0" angle="45" color="0x000000" alpha="1" blurX="0" blurY="0" strength="0" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>

<Keyframe index="4" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="19" blurY="19" color="0xFF6600" alpha="1" strength="1" quality="1" inner="false" knockout="false"/>
<filters:DropShadowFilter distance="-2" angle="233" color="0xFF9900" alpha="1" blurX="0" blurY="0" strength="3.36" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>

<Keyframe index="7" tweenSnap="true" tweenSync="true">
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="19" blurY="19" color="0xFF6600" alpha="1" strength="1" quality="1" inner="false" knockout="false"/>
<filters:DropShadowFilter distance="-2" angle="233" color="0xFF9900" alpha="1" blurX="0" blurY="0" strength="3.36" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>

<Keyframe index="11" tweenSnap="true" tweenSync="true">
<color>
<Color alphaMultiplier="0"/>
</color>
<tweens>
<SimpleEase ease="0"/>
</tweens>
<filters>
<filters:GlowFilter blurX="0" blurY="0" color="0xFF0000" alpha="1" strength="0" quality="1" inner="false" knockout="false"/>
<filters:DropShadowFilter distance="0" angle="45" color="0x000000" alpha="1" blurX="0" blurY="0" strength="0" quality="1" inner="false" knockout="false" hideObject="false"/>
</filters>
</Keyframe>
</Motion>;

duckHit_animator = new Animator(duckHit_xml, this);
duckHit_animator.play();



}

View Replies !    View Related
If Statement Help - AddChild And RemoveChild
Hi. I'm creating an application in an actionscript file, so instead of working with frames, i'm trying to code - if a user clicks on a link, particular objects are displayed or removed.

So how do you code:

ActionScript Code:
if (MovieClip is on stage){
       remove MovieClip;
}

Thanks for the help.

EDIT
please put code in
[ as ] [ /as ] tags (without spaces)

View Replies !    View Related
AddChild And RemoveChild Between Functions
Hi,

I have a file where I call functions that load text from xml files and add them to the stage with addChild().

How would I remove these children when I'm moving from one function to the other?

e.g.

I have a function called: loadNav() which creates a menu from xml.

When I press button Work Examples on my menu:

It calls a function readWork that loads an xml called: work.xml adds a pageWrap Sprite (which is declared in an as file that is included in my fla file) with addChild(pageWrap); and then it adds text fields: pageWrap.addChild('bla')

Then, when I press button Education on my menu:
It calls function readEducation that loads an xml called: education.xml adds a pageWrap Sprite addChild(pageWrap) and text fields pageWrap.addChild('bla')

but the text fields from the previous function are still on the stage and I want to remove them.

Tried lots of ways to use the removeChild but I keep getting the error:

The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at MethodInfo-412()

I'm attaching my functions files. I can't attach the fla file since it's too big to post here.

Can someone help please?

Thanks,

Cgull

View Replies !    View Related
How To Reinitialize A Mc - RemoveChild Then AddChild Again?
This simple little task is super frustrating so hopefully someone can help.

All I want to reinitialize the 3 nodes (curr, new, & ghost) each time the initRelationship is called?

Problem is I don't understand how removeChild works.

Thanks!

the class:

ActionScript Code:
package TreeManager
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.text.TextField;
    import fl.controls.ComboBox;
   
    public class CreateRelationship extends MovieClip
    {
        public var node_curr:Node_create;
        public var node_new:Node_create;
        public var node_ghost:Node_create;
       
        public function CreateRelationship()
        {
            //just a constructor
            addEventListener(Event.ADDED_TO_STAGE, onAdded, false, 0, true);
        };
       
        /* ########## event handlers ########## */
        public function onAdded( event:Event ):void
        {
            // remove the listener( for first-run init only, otherwise you can leave this here
            // for each time the object is added to the display-list ).
            removeEventListener(Event.ADDED_TO_STAGE, onAdded, false );
           
            var cb:ComboBox = new ComboBox(); // create select relationship combobox
           
            cb.addItem( { label: "Relationship" } ); // add relationships
            cb.addItem( { label: "Mother" } );
            cb.addItem( { label: "Father" } );
            cb.addItem( { label: "Sister" } );
            cb.addItem( { label: "Brother" } );
            cb.addItem( { label: "Daughter" } );
            cb.addItem( { label: "Son" } );
            cb.addItem( { label: "Wife" } );
            cb.addItem( { label: "Husband" } );
            cb.addItem( { label: "Partner" } );
            cb.addItem( { label: "Friend" } );
           
            addChild(cb); // add cb to stage
           
            cb.x = 20; // position cb
            cb.y = 70;
            cb.width = 120;
           
            cb.addEventListener(Event.CHANGE,initRelationship); // add relationship type change event
           
            addNodes(); // add nodes
        };
       
       
        /* ########## add modify relationships ########## */
        public function initRelationship(e:Event):void
        {
            if(node_curr == null) { removeChild(node_curr); trace("does this ever run?") };
            if(node_new == null) removeChild(node_new);
            if(node_ghost == null) removeChild(node_ghost);
           
            addNodes();
           
            var r_type:String = e.target.selectedLabel; // get the selected label
            var gender:String = defineGender(r_type.toLowerCase()); // define the gender
            var r_base:String = defineBase(r_type.toLowerCase()); // define the base relationship
           
            node_new.assignGender(gender);
            node_new.assignType("new");
           
            if(r_base == "parent")
            {
                //do stuff
                node_curr.y = 150; // set y position for nodes
                node_new.y = 70;
               
                node_curr.x = 195; // set x position for nodes
                node_new.x = 195;
            }
            else if(r_base == "child")
            {
                //do stuff
                node_curr.y = 70; // set y position for nodes
                node_new.y = 150;
               
                node_curr.x = 195; // set x position for nodes
                node_new.x = 195;
            }
            else if(r_base == "sibling" || r_base == "spouse" || r_base == "other")
            {
                //do stuff
                node_curr.y = 125; // set y position for nodes
                node_new.y = 125;
               
                if(gender == "female")
                {
                    node_curr.x = 195; // set x position for nodes
                    node_new.x = 20;
                }
                else
                {
                    node_curr.x = 20; // set x position for nodes
                    node_new.x = 195;
                }
            }
           
            //node_new.icon.gotoAndStop(gender);
            node_new.username.text = r_type;
           
            var vis:Boolean = (r_type == "Relationship") ? false : true;
           
            node_curr.visible = vis;
            node_new.visible = vis;
           
            //connector.visible = true;
           
            //back.height = 400;
        };
       
       
        public function addNodes():void
        {
            node_curr = new Node_create();
            node_new = new Node_create();
            node_ghost = new Node_create();
           
            addChild(node_curr);
            addChild(node_new);
            addChild(node_ghost);
           
            node_curr.visible = false;
            node_new.visible = false;
            node_ghost.visible = false;
        };
       
        public function defineGender(r_type:String):String
        {
            if(r_type == "mother" || r_type == "sister" || r_type == "daughter" || r_type == "wife") return "female";
            if(r_type == "father" || r_type == "brother" || r_type == "son" || r_type == "husband") return "male";
           
            return "unknown";
        };
       
        public function defineBase(r_type:String):String
        {
            if(r_type == "mother" || r_type == "father") return "parent";
            if(r_type == "daughter" || r_type == "son") return "child";
            if(r_type == "sister" || r_type == "brother") return "sibling";
            if(r_type == "wife" || r_type == "husband") return "spouse";
           
            return "other";
        };
    }
}

View Replies !    View Related
AddChild And RemoveChild With MouseEvent
Hello,
I am encountering a problem with addChild and removeChild.

I would like to add a child when one button is pushed and remove the same child when another button is pushed.

The code I am working with doesn't work. (see attached code)
and this is the error message I get back.
1120: Access of undefined property gallery.







Attach Code

recycled_btn.addEventListener(MouseEvent.MOUSE_UP , btn_Release );
function btn_Release(event:MouseEvent):void
{
var gallery:MovieClip = new photo_gallery();
objects.addChild(gallery);
gallery.x = 45;
gallery.y = 0;
)

sw_btn.addEventListener(MouseEvent.MOUSE_DOWN , btn_Press );
function btn_Press(event:MouseEvent):void
{
objects.removeChild(gallery);

}

View Replies !    View Related
Question About AddChild() And RemoveChild() AS3
Hello

I am trying to add a movieclip from the library via AS. And then delete it
I make a new MC in the library port with a reqtangle from 50px at 50px.
Then i set the properies export for AS
Class: port_mc
Base class:flash.display.MovieClip

this is the script i use:

var port:port_mc;

for (var i:int = 0; i<5; i++)
{
port = new port_mc();
port.x = i * 80;
addChild (port);
}

removeChild(port)

the script places 5 instances of port on the stage. But only remove one off teh stage.
How do i remove all five of them.
Thx.

ps: sorry for bad english...

View Replies !    View Related
Can't Perform AddChild After RemoveChild
I have images that load on the timeline using addChild. When you go from one frame to the next, it basically removes the child and then adds the new one. My problem involves a button which JUST removes the child and does nothing else. Then when I try to go to another frame to load a picture I get the following error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/loadPicture()
at Untitled_fla::MainTimeline/frame3()


This is my code for loading the images:
Code:

function loadPicture(fileName):void
{

      if (theLoad != null )
{
      theLoad.parent.removeChild(theLoad);
}

   
   
theLoad = new Loader();
theLoad.load(new URLRequest(fileName));
theLoad.x = 25;
theLoad.y = 25;
theLoad.contentLoaderInfo.addEventListener(Event.COMPLETE, mainLoaded);
}

      function mainLoaded(event:Event):void
      {
         theLoad.x = 25;
         theLoad.y = 25;
         mainPicArea.addChild(theLoad);
         fadeIn = new Tween(theLoad, "alpha", Regular.easeOut, 0,1,.5, true);
         
      }

This seems to be the problem code from the above:

Code:

      if (theLoad != null )
{
      theLoad.parent.removeChild(theLoad);
}


This is the code for the remove button:
Code:

theLoad.parent.removeChild(theLoad);

The problem is, if I remove the problem code, then the images just pile on top of each other and don't clear out. If the code is in, then the clear button permanently stops any images from loading. Any ideas whats wrong?

View Replies !    View Related
AddChild, GetChildByName, RemoveChild
This script should load an Image put it in "phClip" movieclip and remove it ... what's wrong?

Code:

   var imageLoader:Loader = new Loader();
   var pic:URLRequest = new URLRequest(url);
   imageLoader.load(pic);
   imageLoader.name = "selected_pic";
   MovieClip(phClip).addChild(imageLoader);
   var target:DisplayObject =  MovieClip(phClip).getChildByName("selected_pic");
   removeChild(DisplayObject(target));

View Replies !    View Related
AddChild And RemoveChild Problem
Is there a way of saying: if this event is triggered, find out if a certain child has been added and then remove it, for example.
Thanks
dai

View Replies !    View Related
AddChild RemoveChild From Main Movie
I have 5 buttons that load external .swf files to the main stage into a
holder_mc. Each button has code like this.

Code:

import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.*;
import flash.net.URLRequest;


var imageLoader:Loader = new Loader();
var theURL:String = "New4thfloorStar.swf";
var imageRequest = new URLRequest(theURL);


imageLoader.load(imageRequest);
//var holder_mc = new MovieClip();

FourthFloor_btn.addEventListener(MouseEvent.CLICK, FourthFloor_btn_Click);
function FourthFloor_btn_Click(event:MouseEvent):void
{
holder_mc.x = 0;
holder_mc.y = 120;
holder_mc.addChild(imageLoader.content);
}


When I click on a button, if there is already an external .swf loaded in the holder_mc, I want to
replace it wth the .swf that corresponds with new button clicked.

I think it should be an "if" statement that checks to see if there is a .swf loaded into the holder_mc and if there is, removes it.

If holder_mc.addchild(imageLoader.content) = true then
holder_mc.removechild(imageLoader.content)

As you can see, I'm very new at this and don't have a clue if I'm doing this correctly. Any help greatly appreciated

View Replies !    View Related
Performance Impact: AddChild/removeChild Vs Visible
I have made a flash as3 application with several different Sprite objects containing all sorts of visual content. The display of these objects is controlled through user clicks on a navigation menu.

I was wondering which of the following strategies to use:

1. add all objects to the stage and set their visible property to false or true according to the user input.

2. add those objects which have to be visible using addChild() and removing the 'invisible' objects using removeChild().

My main concern is which of these strategies has the lowest impact on flash player performance.

View Replies !    View Related
About Cache And LoadMovie/removeChild/addChild/Loader.load/sharedLibrary
I am curious about the cache theory

if there's a way to manually delete the cache?

I know there's a "unloadMovie" seems to work like that

did that function still working ?

and I know to add random number after the URL to load new

movie/url every time.

View Replies !    View Related
AddChild Help (newbie To AS3)
I am experienced with AS2, but am very new to AS3. My question should be very easy to understand, but I have no idea on how to get it to work. I am trying to add a MC within a MC... so how do I do this?

This is what I have:


ActionScript Code:
i_parent.clip = new MovieClip();i_parent.clip.addChild( /* the MC I want to attach */);


but this isn't working as expected, I just errors and complaints

Any help would great, thanks

View Replies !    View Related
Error 1061: Undefined Method AddChild... AddChild Problem
1061: Call to a possibly undefined method addChild through a reference with static type flash.displayisplayObject.

Hi, i have searched the forum recently but even i've found some similar problems i could not find any answer that meet my problem.

Well i had a gallery MovieClip and a sprite called photoContainer which i add some thumbs (my thumb class). Everything was perfectly working until i delete my gallery movieClip on the stage and make it a class from the library (class name : Gallery) I wanted to add photoContainer sprite into my gallery using gallery.addChild(photoContainer) so that way i thought when i say removeChild(gallery) both gallery and everything inside it including photoContainer will be removed. But now i can't add anything to my photoContainer sprite which is inside of gallery.

//my working code before i deleted gallery movieclip on stage

ActionScript Code:
var photoContainer:Sprite =  new Sprite();
photoContainer.name="photoContainer";
addChild(photoContainer);
photoContainer.addChild(thumb); //perfectly works
photoContainer.mask=gallery.thumb_holder;

//the code i used after i had deleted gallery movieClip

ActionScript Code:
var gallery:Gallery = new Gallery();
addChild(gallery as MovieClip);

var photoContainer:Sprite =  new Sprite();
photoContainer.name="photoContainer";
gallery.addChild(photoContainer);
photoContainer.mask=gallery.thumb_holder;
/*
gallery.getChildByName("photoContainer").addChild(thumb); //gives "1061: Call to a possibly undefined method
addChild through a reference with static
type flash.display:DisplayObject."

gallery.photoContainer.addChild(thumb); //gives TypeError: Error #1010: A term is undefined and has no properties.
*/


by the way:

ActionScript Code:
trace("gallery Type : " +gallery); //gallery type : [object Gallery]
trace("photo container type  : " +gallery.photoContainer); //photo container type  : undefined

trace("photo container type  : " +gallery.getChildByName("photoContainer"))

//photo container type  : [object Sprite]

it perfectly adds photoContainer to gallery but gallery.photoContainer returns undifined?? or when i use "gallery.getChildByName("photoContainer").addChild (thumb);" it gives error 1061 Can anybody help me?

thanks you very much...

View Replies !    View Related
Is There A Way To Add Variable Arguments To AddChild.. Like AddChild(blah, {x:30})?
in AS2 you could so something like:

blah = attachMovieClip("something", "whatever", {_x:30, _y:25, blahVar:90});

and it would immediately position the blah movieclip, and add a variable called blahVar set to 90 within it, which could be accessed like:

trace(blah.blahVar);

is there any way of doing this in AS3? addChild only takes one argument it seems, so i find myself being forced to do crap like this:

addChild(someMovie);
someMovie.x = 20;

and i have absolutely no idea how to add variables to a movieclip either.. does anyone have any idea?

View Replies !    View Related
OOP Addchild Problem "undefined Method Addchild"?
Trying to do more OOP...

This is within a Movieclip class in a .as file:




public static function iconLoad(section:String){
var iconLoader:Loader;
iconLoader = new Loader();

var myDispatcher:IEventDispatcher = iconLoader.contentLoaderInfo;
myDispatcher.addEventListener(Event.COMPLETE, completeIconListener);
myDispatcher.addEventListener(ProgressEvent.PROGRE SS, progressIconListener);
iconLoader.load(new URLRequest("photos/"+section+"/icon.jpg"));
trace("photos/"+section+"/icon.jpg");
var image:Bitmap;
function completeIconListener(event:ProgressEvent):void{
image = Bitmap(event.target.loader);
image.smoothing = true;
addChild(image);
image.x = 0;
image.y = 0;
engage();
}

function progressIconListener(event:ProgressEvent){
iconBytesLoaded = event.bytesLoaded;
iconBytesTotal = event.bytesTotal;
}
}


Why do I get this error for addchild()?
1180: Call to a possibly undefined method addChild.

View Replies !    View Related
RemoveChild(this)
in a mouse event I am trying to get rid of an instance of a property. I would have thought that this.parent.removeChild(this) would work, but it does not. In fact this traces as an [object global]. I don't know what that is. Any help?

View Replies !    View Related
RemoveChild
I am loading an external swf and I am loading it on a certain frame in my time line and I need to know how to remove the swf when I go to another from.From what I have read I need to use removeChild but I don't know how to implement it into my code:

Code:
var myLoader:Loader = new Loader();
addChild(myLoader);
var url:URLRequest = new URLRequest("photo.swf");
myLoader.load(url);

Maybe an if else statement of some kind.I don't know.Can someone please show me how to do this?

View Replies !    View Related
RemoveChild?
Hi, I've scoured the forums seacrhing for an answer to this but to no avail! Can anyone help?

I have a series of sliding elements which, when button is clicked, slide into place to form each page of my site. I've done this using the Tween Class.
On to these pages I have text which appear on the page via a loader using addChild.

All of this works perfectly well, except that when I change pages and the page drops (making way for another to slide up), I need to remove the text on the page.

I've tried using a simple stage.removeChild(myloader); within the function which drops the pages down but it gives me an error (access of undefined property.myloader)?!

I've tried putting the removeChild into various parts of the code but none work and most give me the same or similar errors.

What am I doing wrong??


Please help! Here's the code.....there's a lot of it:

import fl.transitions.*;
import fl.transitions.easing.*;

//Make 'home' always open when first page loads
var home_up:Object = new Tween(homelp_mc, "y", Strong.easeOut, 310, 15, 1.5, true);
this.homelp_mc.gotoAndPlay("go");
this.home_btn.mouseEnabled = false;
home_up.addEventListener(TweenEvent.MOTION_FINISH, homeDone);

//Make 'home' always open when first page loads
var hOpen:Boolean = true;
var aOpen:Boolean = false;
var sOpen:Boolean = false;
var cOpen:Boolean = false;


//Start home
function homeClick(myevent:MouseEvent):void{
this.home_btn.mouseEnabled = false;
var home_up:Object = new Tween(homelp_mc, "y", Strong.easeOut, 310, 15, 1.5, true);
this.homelp_mc.play();
hOpen = true;
//Listener for motion finished
home_up.addEventListener(TweenEvent.MOTION_FINISH, homeDone);
}

//Call loader function when anim finished
function homeDone(e:TweenEvent):void
{
loadHomeText();
}

//Loader for text
function loadHomeText():void{
var homeRequest:URLRequest=new URLRequest("home.swf");
var myloader:Loader=new Loader();
myloader.load(homeRequest);
stage.addChild(myloader);

//Add text 'slider' to stage
function homeLoaded(myevent:Event):void {
var homeSlider:MovieClip=myevent.target.content;
homeSlider.x=175;
homeSlider.y=15;
}
//Listener to trigger text 'slider' after swf loads
myloader.contentLoaderInfo.addEventListener(Event. COMPLETE, homeLoaded);

}

//Listeners to trigger pull-up of homepage and drop-down of any open page
this.home_btn.addEventListener(MouseEvent.MOUSE_DO WN, dropAll);
this.home_btn.addEventListener(MouseEvent.MOUSE_UP , homeClick);
//End Home



//Start About
function aboutClick(myevent:MouseEvent):void{
this.about_btn.mouseEnabled = false;
var about_up:Object = new Tween(aboutlp_mc, "y", Strong.easeOut,300, 15, 1.5, true);
this.aboutlp_mc.play();
aOpen = true;
about_up.addEventListener(TweenEvent.MOTION_FINISH , aboutDone);
}

function aboutDone(e:TweenEvent):void
{
loadAboutText();
}

function loadAboutText():void{
var aboutRequest:URLRequest=new URLRequest("about.swf");
var myloader:Loader=new Loader();
myloader.load(aboutRequest);
stage.addChild(myloader);

function aboutLoaded(myevent:Event):void {
var aboutSlider:MovieClip=myevent.target.content;
aboutSlider.x=180;
aboutSlider.y=15;
}

myloader.contentLoaderInfo.addEventListener(Event. COMPLETE, aboutLoaded);
}

this.about_btn.addEventListener(MouseEvent.MOUSE_D OWN, dropAll);
this.about_btn.addEventListener(MouseEvent.MOUSE_U P, aboutClick);
//End About



//Start store
function storeClick(myevent:MouseEvent):void{
this.store_btn.mouseEnabled = false;
var store_up:Object = new Tween(storelp_mc, "y", Strong.easeOut, 290, 15, 1.5, true);
this.storelp_mc.play();
sOpen = true;
}
this.store_btn.addEventListener(MouseEvent.MOUSE_D OWN, dropAll);
this.store_btn.addEventListener(MouseEvent.MOUSE_U P, storeClick);
//End Store



//Start Contact
function contactClick(myevent:MouseEvent):void{
this.contact_btn.mouseEnabled = false;
var contact_up:Object = new Tween(contactlp_mc, "y", Strong.easeOut, 280, 15, 1.5, true);
this.contactlp_mc.play();
cOpen = true;
contact_up.addEventListener(TweenEvent.MOTION_FINI SH, contactDone);
}

function contactDone(e:TweenEvent):void
{
loadContactText();
}

function loadContactText():void{
var contactRequest:URLRequest=new URLRequest("contact.swf");
var myloader:Loader=new Loader();
myloader.load(contactRequest);
stage.addChild(myloader);

function contactLoaded(myevent:Event):void {
var contactSlider:MovieClip=myevent.target.content;
contactSlider.x=182;
contactSlider.y=15;
}

myloader.contentLoaderInfo.addEventListener(Event. COMPLETE, contactLoaded);
}

this.contact_btn.addEventListener(MouseEvent.MOUSE _DOWN, dropAll);
this.contact_btn.addEventListener(MouseEvent.MOUSE _UP, contactClick);

//End Contact




//Function to drop any open page if another is opened
function dropAll(myevent:MouseEvent):void{
stage.removeChild(myloader);

if(hOpen){
hOpen = false;
this.homelp_mc.gotoAndPlay("rewind");
}else if (aOpen){
aOpen = false;
this.aboutlp_mc.gotoAndPlay("rewind");
}else if (cOpen){
cOpen = false;
this.contactlp_mc.gotoAndPlay("rewind");
}else if (sOpen){
sOpen = false;
this.storelp_mc.gotoAndPlay("rewind");
}

var home_down:Object = new Tween(homelp_mc, "y", Bounce.easeOut, homelp_mc.y, 310, 1.5, true);
this.home_btn.mouseEnabled = true;

var about_down:Object = new Tween(aboutlp_mc, "y", Bounce.easeOut, aboutlp_mc.y, 300, 1.5, true);
this.about_btn.mouseEnabled = true;


var store_down:Object = new Tween(storelp_mc, "y",Bounce.easeOut, storelp_mc.y, 290, 1.5, true);
this.store_btn.mouseEnabled = true;


var contact_down:Object = new Tween(contactlp_mc, "y", Bounce.easeOut, contactlp_mc.y, 280, 1.5, true);
this.contact_btn.mouseEnabled = true;

}

View Replies !    View Related
RemoveChild?
Hi, I've scoured the forums seacrhing for an answer to this but to no avail! Can anyone help?

I have a series of sliding elements which, when button is clicked, slide into place to form each page of my site. I've done this using the Tween Class.
On to these pages I have text which appear on the page via a loader using addChild.

All of this works perfectly well, except that when I change pages and the page drops (making way for another to slide up), I need to remove the text on the page.

I've tried using a simple stage.removeChild(myloader); within the function which drops the pages down but it gives me an error (access of undefined property.myloader)?!

I've tried putting the removeChild into various parts of the code but none work and most give me the same or similar errors.

What am I doing wrong??


Please help! Here's the code.....there's a lot of it:

import fl.transitions.*;
import fl.transitions.easing.*;

//Make 'home' always open when first page loads
var home_up:Object = new Tween(homelp_mc, "y", Strong.easeOut, 310, 15, 1.5, true);
this.homelp_mc.gotoAndPlay("go");
this.home_btn.mouseEnabled = false;
home_up.addEventListener(TweenEvent.MOTION_FINISH, homeDone);

//Make 'home' always open when first page loads
var hOpen:Boolean = true;
var aOpen:Boolean = false;
var sOpen:Boolean = false;
var cOpen:Boolean = false;


//Start home
function homeClick(myevent:MouseEvent):void{
this.home_btn.mouseEnabled = false;
var home_up:Object = new Tween(homelp_mc, "y", Strong.easeOut, 310, 15, 1.5, true);
this.homelp_mc.play();
hOpen = true;
//Listener for motion finished
home_up.addEventListener(TweenEvent.MOTION_FINISH, homeDone);
}

//Call loader function when anim finished
function homeDone(e:TweenEvent):void
{
loadHomeText();
}

//Loader for text
function loadHomeText():void{
var homeRequest:URLRequest=new URLRequest("home.swf");
var myloader:Loader=new Loader();
myloader.load(homeRequest);
stage.addChild(myloader);

//Add text 'slider' to stage
function homeLoaded(myevent:Event):void {
var homeSlider:MovieClip=myevent.target.content;
homeSlider.x=175;
homeSlider.y=15;
}
//Listener to trigger text 'slider' after swf loads
myloader.contentLoaderInfo.addEventListener(Event. COMPLETE, homeLoaded);

}

//Listeners to trigger pull-up of homepage and drop-down of any open page
this.home_btn.addEventListener(MouseEvent.MOUSE_DO WN, dropAll);
this.home_btn.addEventListener(MouseEvent.MOUSE_UP , homeClick);
//End Home



//Start About
function aboutClick(myevent:MouseEvent):void{
this.about_btn.mouseEnabled = false;
var about_up:Object = new Tween(aboutlp_mc, "y", Strong.easeOut,300, 15, 1.5, true);
this.aboutlp_mc.play();
aOpen = true;
about_up.addEventListener(TweenEvent.MOTION_FINISH , aboutDone);
}

function aboutDone(e:TweenEvent):void
{
loadAboutText();
}

function loadAboutText():void{
var aboutRequest:URLRequest=new URLRequest("about.swf");
var myloader:Loader=new Loader();
myloader.load(aboutRequest);
stage.addChild(myloader);

function aboutLoaded(myevent:Event):void {
var aboutSlider:MovieClip=myevent.target.content;
aboutSlider.x=180;
aboutSlider.y=15;
}

myloader.contentLoaderInfo.addEventListener(Event. COMPLETE, aboutLoaded);
}

this.about_btn.addEventListener(MouseEvent.MOUSE_D OWN, dropAll);
this.about_btn.addEventListener(MouseEvent.MOUSE_U P, aboutClick);
//End About



//Start store
function storeClick(myevent:MouseEvent):void{
this.store_btn.mouseEnabled = false;
var store_up:Object = new Tween(storelp_mc, "y", Strong.easeOut, 290, 15, 1.5, true);
this.storelp_mc.play();
sOpen = true;
}
this.store_btn.addEventListener(MouseEvent.MOUSE_D OWN, dropAll);
this.store_btn.addEventListener(MouseEvent.MOUSE_U P, storeClick);
//End Store



//Start Contact
function contactClick(myevent:MouseEvent):void{
this.contact_btn.mouseEnabled = false;
var contact_up:Object = new Tween(contactlp_mc, "y", Strong.easeOut, 280, 15, 1.5, true);
this.contactlp_mc.play();
cOpen = true;
contact_up.addEventListener(TweenEvent.MOTION_FINI SH, contactDone);
}

function contactDone(e:TweenEvent):void
{
loadContactText();
}

function loadContactText():void{
var contactRequest:URLRequest=new URLRequest("contact.swf");
var myloader:Loader=new Loader();
myloader.load(contactRequest);
stage.addChild(myloader);

function contactLoaded(myevent:Event):void {
var contactSlider:MovieClip=myevent.target.content;
contactSlider.x=182;
contactSlider.y=15;
}

myloader.contentLoaderInfo.addEventListener(Event. COMPLETE, contactLoaded);
}

this.contact_btn.addEventListener(MouseEvent.MOUSE _DOWN, dropAll);
this.contact_btn.addEventListener(MouseEvent.MOUSE _UP, contactClick);

//End Contact




//Function to drop any open page if another is opened
function dropAll(myevent:MouseEvent):void{
stage.removeChild(myloader);

if(hOpen){
hOpen = false;
this.homelp_mc.gotoAndPlay("rewind");
}else if (aOpen){
aOpen = false;
this.aboutlp_mc.gotoAndPlay("rewind");
}else if (cOpen){
cOpen = false;
this.contactlp_mc.gotoAndPlay("rewind");
}else if (sOpen){
sOpen = false;
this.storelp_mc.gotoAndPlay("rewind");
}

var home_down:Object = new Tween(homelp_mc, "y", Bounce.easeOut, homelp_mc.y, 310, 1.5, true);
this.home_btn.mouseEnabled = true;

var about_down:Object = new Tween(aboutlp_mc, "y", Bounce.easeOut, aboutlp_mc.y, 300, 1.5, true);
this.about_btn.mouseEnabled = true;


var store_down:Object = new Tween(storelp_mc, "y",Bounce.easeOut, storelp_mc.y, 290, 1.5, true);
this.store_btn.mouseEnabled = true;


var contact_down:Object = new Tween(contactlp_mc, "y", Bounce.easeOut, contactlp_mc.y, 280, 1.5, true);
this.contact_btn.mouseEnabled = true;

}

View Replies !    View Related
Help With RemoveChild?
I add alot of childs called "thisMC" using my "init" function called displayGallery which uses an array to load image thumbnails and place them on stage.

Now I want it so when a button is clicked all the childs called "thisMC" that the loop below added are removed...

I've tried nearly everything I can think of and it all results in an error about "null" values



PHP Code:




function displayGallery(gallery_array:Array):void {
    var i:int;
    var galleryLength:Number = gallery_array.length;
    for (i = 0; i<galleryLength; i++) {
        var thisLdr:Loader = new Loader();
        thisLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderCompleteHandler);
        thisLdr.load(new URLRequest(gallery_array[i].src));

        var thisMC:MovieClip = new MovieClip();
        thisMC.x = thisX;
        thisMC.y = thisY;
        thisMC.addChild(thisLdr);
        addChild(thisMC);
}
}








any help with this would be great I've been trying for ages and its now annoying me.

Thanks,
Kriogenic.

View Replies !    View Related
[CS3] How To Use RemoveChild()
I am building a virtual tour page for a client using GardenGnomes. They use pano2vr for their flash virtual tours. I am have successfuly used the loader to load the projects, but if I want to delete them from the stage I can't.

I have set up a testing server at testing.vannblack.com/vrtour/tourtest.html if you would like to see the page

Hear is the code to load the tour that I run one the first frame of the timeline.

//Load Virtual Tour

import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
var loader:Loader;
loader = new Loader();
var url:String = "tour0.swf";
var urlReq:URLRequest = new URLRequest(url);
var vr:MovieClip;
// This is done after the swf is loaded.
function finished_loading (e:Event) {
}
function initHandler(event:Event):void {
trace("initHandler: " + event);
vr = MovieClip(loader.content); // cast 'DisplayObject' to 'MovieClip'
vr.pano.setWindowSize(640,480);
vr.pano.setWindowPos(25,25);
}
// Tell the loader to call 'finished_loading' after the swf is loaded.
loader.contentLoaderInfo.addEventListener(flash.ev ents.Event.COMPLETE, finished_loading);
loader.contentLoaderInfo.addEventListener(Event.IN IT, initHandler);
loader.load(urlReq);
addChild(loader); // add your swf directly to the stage


///

After it is loaded I wanted to test unloading the tour from the page. So I set up the following to happen when someone click on the map button and it takes them to frame 20 on the main timeline. It then runs this code.

vr.pano.cleanup();
removeChild(vr);

When that happens I get this error.

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at tourtest_fla::MainTimeline/frame20()

What do I need to do to make this test of the cleanup() function work better. (The error is from the removeChild(vr) function however. What do I need to use instead.

Here is a link to GardenGnomes FLASH API page for reference if you need it.

http://www.gardengnomesoftware.com/w...VR_-_Flash_API

Any help would be great, thanks!

View Replies !    View Related
RemoveChild
Is there anyway for an object to call removeChild on itself without throwing an error... Right now all my children are added by my document class, and I want my Bullets to be removed whenever they hit a zombie... so I call something like
getWorld().removeChild(this); Where getWorld() returns the root/document class.... but whenever I do this, I get a call to a null reference error... I can remove a zombie from the bullet class, so I know my getWorld() is working correctly, I just can't remove the bullet itself... to help my bullet code is located below.


PHP Code:



package
{
    import flash.events.Event;
    
    public class Bullet2 extends MovingObject
    {
        public function Bullet2(setX:int, setY:int, setRotation:int)
        {
            addEventListener(Event.ENTER_FRAME, act);
            this.x = setX;
            this.y = setY;
            this.rotation = setRotation;
            speed = 30;
            dead = 0;
        }
        
        function act(event:Event):void // Act method called every ENTER_FRAME.
        {
            moveForward(speed);
            checkCollision();
        }
        
        public function checkCollision():void
        {
            zombieArray = getWorld().getZombieArray();
            
            for(var i:int = 0; i < zombieArray.length; i++)
            {
                z = zombieArray[i];
                if(z != null)
                {
                    if(hitTestObject(z))
                    {
                        z.die();
                        getWorld().removeChild(this);
                    }
                }
            }
        }
        
        private var speed:int; // How fast it moves.
        private var angle:Number; //direction
        private var isPaused:int;
        private var zombieArray:Array;
        private var z:Zombies;
    }
}

View Replies !    View Related
RemoveChild
Im having some trouble removing an object from the stage...
Its saying that it cant remove an Object from the display list.....as it is not a Sprite. It adds the object to the display list, like so :

ActionScript Code:
var placeItem:PlaceItem = new PlaceItem();
placeItem.setBounds(0, 0, 180, 500);
placeItem.x = 400;
placeItem.y = 200;
addChild(placeItem);

The PlaceItem object extends a PickupItem that extends a Sprite.
When the item is put down, i have a listener that fires and needs to remove the item that was put down, like so :


ActionScript Code:
private function placeItem(e:MouseEvent):void {
removeChild(e.target);
}

It is definitely the PlaceItem that is being used as the target, but for some reason it cannot remove it.

Can anyone help?

View Replies !    View Related
RemoveChild() Help
Today is the first day I try to use as3 ...
Very difficult ;(

Please help.. I just want to do some simple attachMovie and removeMovieClip (from as2)..

So here is the code I have for as3:


Code:
b108.addEventListener(MouseEvent.MOUSE_OVER, clickHandler);
b108.addEventListener(MouseEvent.MOUSE_OUT, outHandler);

function clickHandler(event:MouseEvent):void {
var myinfobox:MovieClip = new infobox();
this.addChild(myinfobox);
}

function outHandler(event:MouseEvent):void {
trace("Out");
this.removeChild(myinfobox);
}
THe error I receive when MOUSE_OUT is

Code:
ReferenceError: Error #1065: Variable myinfobox is not defined.
at test_fla::MainTimeline/outHandler()
I am confused? I thought I had myinfobox defined earlier in clickHandler function?

Please help ;( any help is greatly appreciated!

View Replies !    View Related
RemoveChild If It's There?
Hi,

I have a few buttons set up that load in some text, but they need to remove the video which is in the same place before they appear, so I have added a removechild(video); which works fine the first time, but if I want to load some more text off another button before I load another video I get an error, because the video has already been removed.

Is there anyway to check that the video is there and if it is remove child?

View Replies !    View Related
Add & RemoveChild(...)
I have a slight problem with removing a child (off the non-human type )

The child is being added within an MC, within a scrollPane...


ActionScript Code:
var mc_plot:Sprite = new CirclePlot();
   
    mc_scroll.source.mc_chart.addChild(mc_plot);

to remove it I have the following function...


ActionScript Code:
function deletePlot()
{
    trace("deleting")
    if(!noPlots)
    {
        removeChild(mc_scroll.source.mc_chart.mc_plot);
        noPlots = true;
    }
    else
    {
        trace("no plots to delete");
    }
}

I get the run time error:

Quote:




TypeError: Error #2007: Parameter child must be non-null.
at flash.display::-DisplayObjectContainer/removeChild()
at AS3_fla::MainTimeline/resetChart()




which I guess means its not there...

If I use:


ActionScript Code:
mc_scroll.source.mc_chart.removeChild(mc_plot);
//OR
removeChild(mc_plot)

I get a compiler error


Quote:




1120: Access of undefined property mc_plot.




Any help would be greatly appreciated

View Replies !    View Related
AS3 RemoveChild By Name?
hello, very simple question I imagine, is there a way to reference an object in AS3 other than by assigning Sprites/MC's to an array?

I am encountering situations where I have made a new Sprite, used addChild to attach it to the parent MC but then later I want to reference it [to remove it or access a function].

If I use spriteName.name = "something"

I can't seem to use the 'name' property to call the MC, even though at run-time it correctly assumes the name when I do 'show variables'

here is an example of the kind of code I am writing [which does not work]:


Code:
var mtey = new Sprite;
mtey.name = "holder";
addChild (mtey);
then later in the application I want to reference it:


Code:
removeChild ("holder");//this gives an error since this is a string
removeChild (holder);//this also gives an error since this is not a variable
removeChild (["holder"]);//this makes the compiler go error crazy
removeChild (mtey);//this also doesn't work because mtey was a var which was temporary and thus no longer exists outside of the other function
While I am sure I could define mtey as a property and make it global to all functions w/i the class; I'm working with loops and mtey is a temporary var name which is reused.

My question is, do I have to assign mtey to an array? Or can I access the Sprite in another way?

Since I know it works when I do this:


Code:
private var mteyArray: Array = [];

Code:
mteyArray.push (mtey);

Code:
removeChild (mteyArray[0]);
but this just seems excessive to me......?

View Replies !    View Related
Help With RemoveChild();
Hi I'm creating a simple photo gallery. And each time you click on thumbnail it displays enlarge version of the image and title for that image. I'm having problems with removeChild(), I get an error trying to remove the instance of the title. The error I get is TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/removeChild()
at PhotoGallery/createTitleField()
at PhotoGallery/onMouseOver()


Here's the code and the removeChild is at createTitleField();


ActionScript Code:
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.display.Loader;
    import flash.events.ProgressEvent;
    import flash.display.LoaderInfo;
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.display.BitmapData;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.utils.*;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.MovieClip;
   
    import flash.events.MouseEvent;
   
    public class PhotoGallery extends Sprite
    {
       
        private var xmlLoader:URLLoader;
        private var xml:XML;
        private var xmlList:XMLList;
        private var capturePath:Array;
        private var captureTitle:Array;
        private var menuHolder:Sprite;
        private var loader:Loader;
        private var urlRequest:URLRequest;
        private var imageHolder:MovieClip;
        private var imageTotal:Number = 0;
        private var imageContainer:MovieClip;
        private var titleText:TextField;
        private var titleTxt:String = "";
        private var percent:TextField;
        private var perc:Number;
        private var iCount:Number = 0;
        private var txtFlag:Boolean = false;

        public function PhotoGallery ()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            init();
           
        }
       
        private function init():void
        {
            xmlLoader = new URLLoader();
            xmlLoader.addEventListener(Event.COMPLETE, onLoaded);
            xmlLoader.load(new URLRequest("myXML.xml"));
           
           
        }
       
        private function onLoaded (event:Event):void
        {
            captureTitle = new Array();
            capturePath = new Array();
            xml = new XML(event.target.data);
            xmlList = xml.image;
            //trace(xmlList[0].path);
            for(var i:int = 0; i < xmlList.length() ; i++)
            {
                capturePath.push(xmlList[i].path);
                captureTitle.push(xmlList[i].title);
                imageTotal = i ;
            }
           
            loadImage();
        }
       
        private function loadImage ()
        {
           
            for (var i:int = 0; i < imageTotal; i++)
            {
                var url:String = capturePath[i];
                urlRequest = new URLRequest(url);
                loader = new Loader();
                //loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
                //loader.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
                loader.load(urlRequest);
               
               
               
                imageHolder = new MovieClip ();
                addChild(imageHolder);
                imageHolder.x = stage.stageWidth/2 + 190;
               
                imageHolder.scaleY = .10;
                imageHolder.scaleX = .10;
               
                imageHolder.addChild(loader);
                imageHolder.y = i * 75;
               
                imageHolder.Path = capturePath[i];
                imageHolder.Title = captureTitle[i];
               
                imageHolder.buttonMode = true;
                imageHolder.mouseChildren = false;
                addEventListener(MouseEvent.MOUSE_DOWN, onMouseOver);
            }
           
        }
       
        private function onMouseOver(event:MouseEvent)
        {
            createTitleField(event.target.Title);

        }
       
         private function createTitleField(myTxt):void
        {
            if (txtFlag == false)
            {
            var titleText:TextField = new TextField();
            var format:TextFormat = new TextFormat();
            format.font = "_sans";
            format.color = 0x000000;
            format.align='left';
            format.size = 10;
            titleText.width = 215;
            titleText.height = 15;
            titleText.defaultTextFormat = format;
            titleText.selectable = true
            titleText.border = true;
            titleText.borderColor=0xFFFFFF;
            //titleText.text = myTxt;   
            titleText.y = 330;
           
           
                titleText.text = myTxt; 
                addChild(titleText);
               
                txtFlag = true;
            }else{
               
                removeChild(titleText);
                titleText = null;
                txtFlag = false;
                createTitleField(myTxt);
            }
           
           
           
           
            //removeChild(titleText);
        }
       
        private function loop (event:ProgressEvent):void
        {

            percent = new TextField();
            var format:TextFormat = new TextFormat();
            format.font = "_sans";
            format.color = 0x000000;
            format.align='left';
            format.size = 10;
            percent.width=215;
            percent.height=15;
            percent.defaultTextFormat = format;
            percent.selectable = false;

            percent.x = stage.stageWidth /2 - 260;
            percent.y =  stage.stageHeight /2 +90;
           
            //percent.text = "lkfjdaslkfjasd";
           
            perc = event.bytesTotal / event.bytesTotal;
            percent.text = Math.ceil(perc*100).toString() + "%";
           
           
            addChild(percent);
            trace("fls");
        }
       
        private function done(event:Event):void
        {
           
            iCount++;
            //removeChild(percent);
            if(iCount == 5){
                percent.visible = false;
                ;
            }
            //percent = null;
            trace(iCount);
        }
       
       
    }
}

View Replies !    View Related
RemoveChild How To
hello i have simple code addChild textField move allows mouseX and mouseY
function that loop with setinterval.
my code

PHP Code:



function t(e:String){
var test:TextField=new TextField();
test.x=mouseX;
test.y=mouseY;
test.text="hello";
addChild(test);

}
var ok1=0;
setInterval(t,500,ok1) 




when Ctrl+Enter it have very old textField. i want removeChild it, want 1 textField only and it is new
please help me . thanks.
sorry my bad E

View Replies !    View Related
Using IF To RemoveChild?
Greetings

Surpisingly enough, I haven't used many "if" statements yet. I'm trying to remove a MovieClip when it reaches a certain point in the timeline after it has "faded out". But I'm not sure how to use "currentFrame" to tell it when.


ActionScript Code:
function closePhoto(e:MouseEvent):void
{
    photoGallery.gotoAndPlay("close");
    if (photoGallery.currentFrame == 46)
    {
        removeChild(photoGallery);
    }
}

This is not working, but it's not giing an error either, just loops the MovieClip.
Perhaps there is even a better way to do this, but this was all I could think of. Thanks in advance.

View Replies !    View Related
RemoveChild
I have added a number of the same movie clips to the stage and I would like to be able to remove them all with the click of a button.

This only removes the last movie clip added:
removeChild(dir_num);

Is there any way of removing the all? In AS2 you could assign each of them a name value and you were then able to manipulate the clip using that instance name. Doesn't exactly work like that any more so some help would be greatly appreciated. Thanks.

View Replies !    View Related
RemoveChild
Hi

I am trying to remove an swf called 'menu.swf' using this statement;

removeChild(MovieClip(root).myLoader1);


The swf I want to remove has been loaded from a preloader (on the maintimeline ) so I am referencing the MovieClip(root)

I am instating the command ''removeChild(MovieClip(root).myLoader1);''
inside my 'menu.swf' which is inside a click function that will load a third
swf. ( on the load of the third swf I want to remove the menu.swf)

hope it is clear
if you can see anything here or suggest a better way
that would be great help!
matt

View Replies !    View Related
RemoveChild Help
I am trying to animate a bitmap with an ActionScript 3 example from Flash
help that I slightly modified. The code uses an ENTER_FRAME event to draw a
new portion of the bitmap and add it to the stage using addChild(). I am
not a very skilled programmer but I know I need some way to remove the
unused or hidden instances to increase processor efficiency. How do I use
removeChild() in my code to remove all instances but the most current image?

Here is my code:

import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.IOErrorEvent;


var url:String = "BMPF002.png";
var loader:Loader = new Loader();

var request:URLRequest = new URLRequest(url);

loader.load(request);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
drawImage);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,
ioErrorHandler);

function drawImage(event:Event):void
{

stage.addEventListener(Event.ENTER_FRAME,animateBitmap);

var xSpeed:Number = 0;
var ySpeed:Number = 0;

function animateBitmap(event:Event):void
{
xSpeed += 9;
ySpeed += 6;



var mySprite:Sprite = new Sprite();
var myBitmap:BitmapData = new BitmapData(loader.width,
loader.height, false);

myBitmap.draw(loader);
mySprite.graphics.beginBitmapFill(myBitmap);
mySprite.graphics.drawRect(0, 0, xSpeed,ySpeed);
mySprite.graphics.endFill();
addChild(mySprite);

}


}

function ioErrorHandler(event:IOErrorEvent):void
{
trace("Unable to load image: " + url);
}

View Replies !    View Related
RemoveChild
I created an object on my stage that moves up in the air and spins around and then falls down to the bottom. After the animation, the object just sits there and takes up space. I know I need to use the removeChild method but I'm not sure where it would go in my code. The very last function was my guess but I get this error: "Access of undefined property newToast"










Attach Code

package {
import flash.display.MovieClip;
import flash.events.*;
import flash.utils.*;

public class Toaster extends MovieClip {
public function Toaster() {
var toastLauncher:Timer = new Timer(500, 0);
toastLauncher.addEventListener(TimerEvent.TIMER, setupToast);
toastLauncher.start();
}
function setupToast(event:TimerEvent):void {
var newToast:Toast = new Toast;
newToast.x = (Math.random()* (stage.stageWidth - 70)) + 30;
newToast.y = stage.stageHeight;

var randomScale = Math.random()*1 + .3;
newToast.scaleX = randomScale;
newToast.scaleY = randomScale;
addChild(newToast);
launchToast(newToast);

newToast.play();
}

function launchToast(toastObject):void {
var yVel:Number = -35;
var yAcc:Number = 1.5;
var spinControl:uint = 15
var spinRight:Number = Math.random()*spinControl;
var spinLeft:Number = Math.random()*-spinControl;
var randomSpin:Number = Math.floor(Math.random()*2);

stage.addEventListener(Event.ENTER_FRAME, checkPosition);
stage.addEventListener(Event.ENTER_FRAME, accelleration);

function accelleration(event:Event):void {
toastObject.y += yVel;
yVel += yAcc;
if (randomSpin) {
toastObject.rotation += spinLeft;
} else {
toastObject.rotation += spinRight;
}
}

function checkPosition(event:Event):void {
if (newToast.y > stage.stageHeight + 1) {
removeChild(newToast);
}
}
}
}
}

View Replies !    View Related
Help With RemoveChild
I have a flash movie in which I've created something that functions similarly to a calculator. When the user clicks a button, depending which button was pressed and in which order, a series of movie clips is displayed from left to right in specific positions, using addChild. I have a button on the calculator which I would like to have function similarly to a 'clear' button on a real calculator. When clicked, it would remove only the movie clips that were displayed by clicking the calculator buttons. Can anyone point me in the right direction as to how I can remove only the movieclips that are part of the calculator display? Here are some code samples.

var mcSelection:MovieClip = new MovieClip();

//check to see how many times a calculator button was clicked
function checkTime()
{
if (Counter == 1)
{
mcSelection.x = 94.4;
mcSelection.y = 264;
}

else if (Counter == 2)
{
mcSelection.x = 121.9;
mcSelection.y = 264;
}
etc, etc....

//for calculator buttons
function onClick_4(evt:MouseEvent):void {
Counter = Counter + 1;
checkTime();
var mcNum4_1:MovieClip = new mcNum4;
addChild(mcNum4_1);
mcNum4_1.x = mcSelection.x;
mcNum4_1.y = mcSelection.y;
}

I've tried different variations of removeChild and removeChildAt, but either parts of the calculator are getting removed, or I remove the parts of the display one clip at a time instead of all together, or I get out of range errors. How do I target a certain range of movieclips to remove? Do I need to assign a specific range of levels when the new movieclips are added and then remove that range? It will be different number of clips and combination of clips every time.

Thanks for any ideas.

View Replies !    View Related
RemoveChild
Hi
I am trying to remove an swf once I have loaded a new one ontop of it. I have tried removeChild();
but this does not work. Is this because I am loading the second swf in to the first one?
Any help will be great
thanks!
mt


var swfRequest : URLRequest = new URLRequest( 'fractureEnginePage.swf' );
var imageLoader : Loader = new Loader();

function Click3 ( e : MouseEvent ) {
imageLoader.load( swfRequest );
addChild( imageLoader );
removeChild( 'fractureMenu.swf' ); // this the fist swf ( the main menu ) i want to remove

}

View Replies !    View Related
AS3.0>>> RemoveChild
I'm assuming some of you's must be doin some AS3.0 so i'll post it here to see if anyone knows the answer.

i have an array of MovieClips that i'm checking in an enterFrame event to see if the scaleX has hit one... if it has remove the child from the display list. I keep getting an

ArgumentError: Error #2025: The DisplayObject supplied must be a child of the caller.

now... what i'm doing is adding a child on every frame (a mc)... pushing it into an array and then checking the whole array to see if nay have hit their target scaleX's as below


ActionScript Code:
for (var i:int = this.ball_array.length - 1; i >= 0; i--){    if (this.ball_array[i].scaleX >= 1)    {        this.removeChild(this.ball_array[i]);       }}


there's obviously somit worng with the way i'm doing this. Does anyone have any ideas?

Cheers

Jimmy

View Replies !    View Related
RemoveChild Only If Something Is There Already
I have some buttons that are loading external SWF files into a movie clip called holder. Each button loads SWFs into that clip, but the addChild method puts one on top of the other in sequence. How can I use removeChild to remove specifically, the content of the holder clip?

I have seen this: if (this.contains(ball)) this.removeChild(ball); But it doesn't serve my purposes because the movie clip is a placeholder. Here's my code:


Code:
b1.addEventListener(MouseEvent.CLICK, swf1);
function swf1(event:MouseEvent):void {
var swf1Ldr:Loader = new Loader();
var swf1URL:String = "dieHard.swf";
var swf1URLReq:URLRequest = new URLRequest(swf1URL);
swf1Ldr.load(swf1URLReq);
swf1Ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, swf1Loaded);
function swf1Loaded(event:Event):void {
holder.addChild(swf1Ldr.content);
}
// Make the progress clip visible and show the progress loaded
swf1Ldr.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showProgress);

}
Any ideas

View Replies !    View Related
RemoveChild?
So here is what I am doing.

You click a navigation button on the screen
(artclassNav, eventsNav, exhibitionNav, museumNav)

A box slides onto the screen (infoBox) and the appropriate text fades in
(artclassTxt, eventsTxt, exhibitionTxt, museumTxt)

On the infoBox is a close button (closeNav) which when clicked makes the text and the infoBox go bye bye.

My problem:

closeNav works correctly the first time and maybe the third, but eventually it becomes seemingly random if the text will pop up... infoBox slides in, but text may or may not appear.

Here is my code for the closeNav as of now


Code:
infoBox.closeBox.addEventListener(MouseEvent.CLICK, close_CLICK);
function close_CLICK(e:MouseEvent):void
{
Tweener.addTween(infoBox, {x: infoBox.x - 1000, time:1, transition:"easOutBack"});
Tweener.addTween(artclassTxt, {_autoAlpha:0, time:1, transition:"easeOut"});
Tweener.addTween(eventTxt, {_autoAlpha:0, time:1, transition:"easeOut"});
Tweener.addTween(exhibitionTxt, {_autoAlpha:0, time:1, transition:"easeOut"});
Tweener.addTween(museumTxt, {_autoAlpha:0, time:1, transition:"easeOut"});
}
I have tried a few different ways of using removeChild and using if statements... but I'm new to coding, lowly print designer I am. But I'm trying... Please help!

View Replies !    View Related
How To Use RemoveChild
I'm loading in pictures in my timeline (1 picture per frame). I want to put in the removeChild command in the function, but the problem is, it creates an error on the first frame because there is no child to remove, what kind of condition would be best to handle this?

Also, when I click on the link twice for the same picture, it disappears, any reason for this?

Here is the code I'm using to load the picture:


Code:
function loadPic(fileName):void
{
var mainRequest:URLRequest = new URLRequest (fileName);

mainLoader.load(mainRequest);
mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, mainLoaded);
}

function mainLoaded(event:Event):void
{
mainPicArea.x = mainPicPlacementX;
mainPicArea.y = mainPicPlacementY;
mainPicArea.addChild(mainLoader);
fadeIn = new Tween(mainPicArea, "alpha", Strong.easeOut, 0,1,.5, true);

}

View Replies !    View Related
RemoveChild
Wow, this question is so basic, I almost don't want to ask it. I have an object I place in a container, when the container hits my ship, I want to remove the object, however I get the message
display object must be the child of the caller, please see code:




//DISPLAY BLACK HOLE ICON
ActionScript Code:
public function displayBlackHoleIcon(evt:TimerEvent){
myBlackHoleIconContainer = new Sprite()
myBlackHoleIconContainer.x = randomX();

for(var i:int = 0; i < 200; i++){
myBlackHoleIcon = new BlackHoleIcon();
myBlackHoleIcon.x = Math.random()* 30 + 20;
myBlackHoleIcon.y = Math.random()* 30 + 20;

myBlackHoleIconContainer.addChild(myBlackHoleIcon);
}

blackHoleIconArray.push(myBlackHoleIconContainer);
addChild(myBlackHoleIconContainer);


}


//BLACK HOLE ICON VS FALCON
for (var blackHoleNum:int=blackHoleIconArray.length - 1; blackHoleNum >= 0; blackHoleNum--) {
if (blackHoleIconArray[blackHoleNum].hitTestObject(theFalcon)) {

/*playSound(shipHit);*/
removeChild(myBlackHoleIconContainer);
addDisplayBlackHoleIcon(displayBlackHoleIconCount,1);
isBlackHolePowerActive = true;



}
}

View Replies !    View Related
RemoveChild
Hi,

Im building a Video ondemand site, im using a movieclip "thisMC" to load flv videos and when a button in the main timeline is pressed it should unload and clear the screen.

it works fine with the objects on the timeline, but i want to remove a child which is called by a another Object (a Movieclip).

The Child is called by "mc_loading" Movie Clip but then i try to remove the child using a script in the main timeline it doesnt work.

i've used MovieClip(root).removeChild(thisMC) and stage.removeChild(thisMC);

Any help is appriciated im still new to AS3


Thanks

View Replies !    View Related
RemoveChild
hello, I'm trying to do a simple test with the addChild/removeChild function and I can't get the removeChild funtion to work. I attached the fla file. It's a very simple test, I have a button (open) on the stage, an eventListener attached with it that will call a movie clip on click. I used the addChild function to make it appears, and it works well, here's the code:

Code:

var map:Map = new Map();

btnOpen.addEventListener(MouseEvent.CLICK, mapOpen);

function mapOpen(event:MouseEvent):void
{
   addChild(map);
   map.x = 270;
   map.y = 180;
}


the the movieclip appears on the stage. In the movieclip, there's a X as a close button. I again used an eventListener to remove it on click, but the hole stage disapears (the button "open" too). Here's the code for the X button in the map movieclip:

Code:

btnClose.addEventListener(MouseEvent.CLICK, closeWindow);

function closeWindow(event:MouseEvent):void

{
   this.parent.parent.removeChild(this.parent);
}


I would like the map to close and the button "open" to stay there! Someone can help?

View Replies !    View Related
Can't Seem To RemoveChild()
O.k. I think my problem is pretty simple to solve but for some reason I can't seem to get my code to work. I have 6 btns on the main timeline. Each btn places a seperate mc on the stage. 1 of the mc's placed onto the stage contains another menu with btn's there that place a differnt mc that contains info. The info mc is placed within the mc on the stage (mc within an mc). Now the problem is i can't seem to get the removeChild() to work so that the info pages transition on an off. I looked thru this forumn and it said i should use this.parent.parent.removeChild(this.parent) but this doesn't seem to work i keep getting an error. So can someone PLEASE let me know what method I'm supposed to be using. The code on the mainTimeline works perfectly you click on the button it add's and remove's the mc's corrently. Now inside the Info mc where the 2nd menu is located i have this code placed inside the actions layer in that mc. it's supposed to transition a 3RD mc inside the 2ND mc when you click on the menu btn. adding it inside the 2nd mc works just fine it's removing it that isn't working. I traced out the addChild() method on the mainTimeline to see where the mc is being placed and it's being placed inside the 2nd mc exactly like i want it to but i don't know what method to use to remove it. I've tried tracing out the instance name so I can use removeChildByName() but that also doesn't work. I'm not sure what i'm doing wrong here.

Code:


var currentPage = MovieClip;

var infoPage:pageInfo = new pageInfo();

info_btn.targetMC = infoPage;

info_btn.addEventListener(e:MouseEvent.CLICK, nextPage);

function nextPage(e:MouseEvent):void
{
   if(currentPage == null);
   {
      currentPage = MovieClip(e.currentTarget);
      currentPage.targetMC.x = -120;
      currentPage.targetMC.y = 340;   
      addChild(currentPage.targetMC);
   }

   this.parent.parent.removeChild(this.currentPage.targetMC);
   currentPage.targetMC.x = -120;
   currentPage.targetMC.y = 340;   
   currentPage = MovieClip(e.currentTarget);
   addChild(currentPage.targetMC);
}



I know the problem is in the removeChild() method i just don't know what it is or how i'm using it wrong. How do you reference an mc inside of an mc???

View Replies !    View Related
How NOT To Use RemoveChild
Greetings

the set-up
I've created a MovieClip that opens other MovieClips. These MovieClips are galleries with example of my art and such. Within these gallery MovieClips there is a "close" button, which is actually another MovieClip.

the problem
Everything works except that when I open one gallery, then close it, then open it a second time, the "close" button refuses to work.
I thought this was do to my incorrect use of removeChild, but now I don't know.
This is made slightly tougher by the fact that closing the gallery involves playing a closing animation, so first I put the removeChild on the last frame of the gallery MovieClip. That had the same result so then I tried it this way...
but still the same problem.

the code
Opening it with a MovieClip


Code:


var vectorGallery:galleryVector = new galleryVector();

ex_mc.addEventListener(MouseEvent.CLICK, openVector);

function openVector(e:MouseEvent):void
{
addChild(vectorGallery);
vectorGallery.x = -390;
vectorGallery.y = -240;
vectorGallery.gotoAndPlay(1);
}

vectorGallery.close_mc.addEventListener(MouseEvent.CLICK, closeVector);
vectorGallery.addEventListener("done", doneHandler);

function closeVector(e:MouseEvent):void
{
vectorGallery.gotoAndPlay("close");
}

function doneHandler(e:Event):void
{
removeChild(vectorGallery);
}


Closing it with the "close" button within the gallery MovieClip last frame


Code:


dispatchEvent(new Event("done"));


Anyone have a suggestion as to why I'm having this problem? Thanks.

View Replies !    View Related
Copyright © 2005-08 www.BigResource.com, All rights reserved