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.
ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 01-15-2009, 07:32 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
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?
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?
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;
}
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;
}
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.
[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!
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;
}
}
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?
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!
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?
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
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......?
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);
}
}
}
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
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.
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
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);
}
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);
}
}
}
}
}
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.
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
}
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
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
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!
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);
}
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;
}
}
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
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?
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???
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.
RemoveChild() From The Child Itself ?
Okay - it's not often I post on forums at all for help - let alone three times recently - but I really appreciate the help here!
As the title says - I've added a child (which is class called "Target" and is an extended Sprite) straight to the main object (entry point). I've also made it somewhat of a Singleton object (the main object, that is) by making a static reference and a GetReference() function to call the main object.
1 - The singleton appears to be working fine - a call to Main.GetInstance().StatusMessage("Test"); works absolutely fine, and outputs to the screen as it should
2 - I've tried, from the child, using this.parent.removeChild(this); - it failed
3 - I've tried:
var d:flash.display.DisplayObject = Main.GetInstance().getChildByName(this.name);
trace(d);
Main.GetInstance().removeChild(d);
d traces as NULL, and of course removeChild fails.
So - how is a child supposed to kill themselves without external involvement? Surely this is something that is required incredible frequently?!
Thanks again!
Mark
RemoveChild If Then Else Problem
Hello,
Below I have a fla file and 4 swfs that are loaded in, so you can understand my problem better.
I am having trouble coding a removeChild within a If Then Else statement.
What I have is three buttons (One, Two, Three). The buttons take the place head to three frame sections (One,Two,Three). Within each frame section it addChilds the corresponding number to the stage.
Lets say I click the One Button, the number 1 pops up onto the stage. I then click the two button, the number 2 pops up onto the stage, but the 1 doesn't go away like I want it to. I want any combination to work.
The code that I have been using in each frame section is:
*Note* Each loader corresponds with a number. loader = 1, loader2 = 2, loader3 = 3
Code:
if (loader.visible = true)
{
removeChild(loader)
}
if (loader2.visible = true)
{
removeChild(loader2)
}
if (loader3.visible = true)
{
removeChild(loader3)
}
The errors I am receiving is:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller
The 1 FLA and 3 Swfs Here:
TestFLA:http://www.filecrunch.com/file/~cmkw3t
OneSwf:http://www.filecrunch.com/file/~nq4nex
TwoSwf:http://www.filecrunch.com/file/~py1eh5
ThreeSwf:http://www.filecrunch.com/file/~jab5ah
I hope someone can show me the way and some insight on this problem. Also if someone could correct the fla I have posted and send it back to me that would be great! - Thanks
Different RemoveChild From MC Problem
similar to a previous post but this doesnt use contains and keywords like that.
the code works perfectly if i dont put the array image inside a movieClip, but get the error that it must be non null:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/removeChild()
at Asktest_fla::MainTimeline/selectPerson()
here is my code:
PHP Code:
var person1:Sprite = new dan();
var person2:Sprite = new dave();
var a:Array = [person1, person2]; // array holding the arrows
var i:Number = 3;
var b:Array = [btn1, btn2]; // array holding the buttons
for each (var element:Button in b)
{
this.addEventListener(MouseEvent.CLICK, selectPerson);
}
// on menu button click
function selectPerson(event:MouseEvent):void
{
// check if the first button has been clicked
if (event.target.name == b[0].name)
{
if (a[i] != null)
{
container.removeChild(getChildByName("mc" + i));
}
i = 0;
}
// if not, then the second button has been clicked
else if (event.target.name == b[1].name)
{
if (a[i] != null)
{
container.removeChild(getChildByName("mc" + i));
}
i = 1;
}
checkChild();
}
function checkChild()
{
if (i == 0 || i == 1)
{
container.addChild(a[i]);
a[i].name = "mc" + i;
}
}
anybody have any idea why it cant be inside a MC?
[CS3] RemoveChild Problems?
Hi everyone, so I've got a problem with addChild and removeChild. I can't quite figure out the problem.. I've only been using flash for a few days. So anyways, I've got this movieclip, mcStarburst. I want to have it play wherever the mouse clicks, play once and then remove itself fromt he stage (or just stop playing, whatever works) So I've got it to add a clip where I click, but it wont stop playing when I release the mouse. This is the code I've got so far:
stage.addEventListener(MouseEvent.MOUSE_DOWN,func) ;
stage.addEventListener(MouseEvent.MOUSE_UP,funcOut );
function func(event:MouseEvent):void
{
var mouseX:Number = event.target.mouseX;
var mouseY:Number = event.target.mouseY;
var starburst:MovieClip = new mcStarburst();
addChild(starburst);
starburst.x = mouseX;
starburst.y = mouseY;
}
function funcOut(event:MouseEvent):void{
var starburst:MovieClip = new mcStarburst();
removeChild(starburst);
}
And I get this error message in the output window: ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at Constellations_fla::MainTimeline/funcOut()
I kind of get the idea of it... But can someone more experienced than I kinda explain whats going on and then how to fix it? Or if there's a different way to do this, it'd be helpful if you could help me out. Thanks
RemoveChild Problem
I've got an instance created from a linked mc in the library and I'm using addChild to add it to the .swf upon mousing over. On mousing out, it should disappear but it isn't as I just get errors. This is the code I'm using:
function chanelOver1 (e:MouseEvent):void
{
var newC:text_mc = new text_mc();
this.addChild(newC);
newC.x = 10;
newC.y = 390;
}
function chanelOut1 (e:MouseEvent):void
{
removeChild(newC);
}
[AS3]removeChild Within Class...
I am looking for a way to remove a child from the display list when the child MC was added in one class but to be removed from another. Any suggestions?
Here is an example to my question:
There are two classes:
class one:
PHP Code:
package {
public class ClassOne {
public var mc:MovieClip;
public function ClassOne() {
mc = new MovieClip();
addChild(mc);
}
}
}
class two:
PHP Code:
package {
public class ClassTwo {
public function ClassTwo() {
this.parent.removeChild(mc);
}
}
}
Thanks for your help!!
RemoveChild Containing .swf Loading An .flv
Yo!
making a flash gallery kind of thing, where i've got a bunch of little thumbnails. When you click on them they load the relative .jpg or .swf file. .swf files are linking to .flv files.
I'm sure there's a more effective way to accomplish this, but i wanted a custum flash player skin, and this was the only way i knew.
The problem arises when i want to load a new movie with a current movie playing. The current movie keeps playing, or at least the sound from it. How do i kill the current movie before loading the new one?
code is as follows:
Code:
var with .swf link
var filmSten:URLRequest = new URLRequest("images/store/uniconfilm_stensand.swf")
loader class loading images/movies
var imageLoader:Loader = new Loader();
event listener on "filmSteensand_mc" movieclip triggering function "filmStenClick"
filmSteensand_mc.addEventListener(MouseEvent.CLICK, filmStenClick);
function creating imageLoader containing .jpg's/.swf's
function filmStenClick(event:MouseEvent):void {
imageLoader.load(filmSten);
addChild(imageLoader);
}
i tried a removeChild(); in the function about the addChild(imageLoader); - that didn't work.
RemoveChild Of Parent Swf
I feel really dumb here. But, lets assume you have two swfs, loader and loadee. Lets also assume that ball_mc has been added to the display list of loader.
Now you've loaded loadee into loader and you want to call removeChild(ball_mc). But, you want to call it from the loadee. How would you do that?
I know this has a really easy answer, but googling "removeChild+parent" or other related queries don't yield helpful answers.
Curiosity About Add/removeChild
Just curious if anyone knows how flash works... if I have a DisplayObject but it is not part of a display list... will flash still take the cpu time to "draw" it... like in memory? or if it is not on a display list is it totally ignored?
What i was thinking of doing is in my game, when a room is loaded for the first time then instead of deleting it totally out of memory... just removing it from and adding it to the display list as needed. but if flash takes extra cpu time to draw it even if it's not displayed then i dont want to do that. I know it would take more memory to keep the graphics in there, but that's ok, it's not that much memory in my case anyway.
thanks!
Kyle
RemoveChild Problem
I'm having trouble with removeChild. I got the movie clip to move out of the frame with these two lines, but I can't figure out how to remove it which is what I really want.
PHP Code:
var fn2:MovieClip = MovieClip(e.currentTarget.parent.parent);
fn2.x = -5000;
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.
RemoveChild() Problem
Hi everyone,
Around the time AS3 came out I stopped making flash sites that were just one single large flash movie and so I had not run into this problem before. But I'm making a full flash page for a friend and it has prompted me to think that maybe I don't quite understand how the new "addChild()" "removeChild()" and traversing Children and Parent objects aspect of AS3 works.
In the following code I basically have an empty flash movie and then I am creating 2 new instances of movies on the stage through actionscript: a page instance and a navigation menu instance. Then I'm adding a MouseClick event listener to one of the nav menu buttons that tells it to look at the main timeline and removeChild the page and addChild a new page.
Code:
// --- IMPORT NEEDED CLASSES
import flash.display.*;
import flash.net.URLRequest;
// --- CREATE ORIGINAL PAGE INSTANCE
var thisPage:page_about = new page_about();
addChild(thisPage);
thisPage.x = 20;
thisPage.y = 110;
// --- CREATE NAVIGATION MENU FROM LIBRARY
var navMain:nav_main = new nav_main();
addChild(navMain);
navMain.x = 23;
navMain.y = -10;
....
// --------- RESUME DROP DOWN --------- //
function btnCLK_resume_education(eventObject:MouseEvent):void
{
parent.removeChild(thisPage);
var thisPage:page_resume_education = new page_resume_education();
parent.addChild(thisPage);
thisPage.x = 20;
thisPage.y = 110;
}
The page runs fun until I click the resume_education button at which point I get the following error:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/removeChild()
at home_fla::MainTimeline/btnCLK_resume_education()
Am I not traversing the movie clip heirarchy correctly? Or can I not access other children objects of the main parent (in this case the stage)?
RemoveChild Question
Hi guys,
I'm new to AS3 and need a little help.
I've got a simple gallery where you can click on a pic and it will be enlarged by placing a movieclip on top using the following function:
function pageZoom(e:MouseEvent):void
{
addChild(zoomAlize);
zoomAlize.gotoAndPlay(1);
}
This all works fine and the MC is placed on top.
What I want is a little x in the top right to then close the box (removechild)
I've tried to do this using the following function:
function zoomClose(e:MouseEvent):void
{
removeChild(zoomAlize);
}
Now I get the most helpful message on runtime:
TypeError: Error #1010: A term is undefined and has no properties.
at KSdigitalmedia_fla::MainTimeline/frame1()
Am I getting this error because im trying to remove the MC that holds the close button?
If so, what's the work around?
Many thanks in adance.
Stu.
RemoveChild Problems
Hi,
I am pretty new to AS3 and am trying to build a game based on Pong. I am having trouble however. When a 'goal' is scored, i am given the following error:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display:isplayObjectContainer/removeChild()
at Pong/ballPosition()
My code is below:
Code:
package {
import flash.display.Sprite;
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class Pong extends MovieClip {
private var paddle:Paddle;
private var paddle2:Paddle;
private var ball:Ball;
private var topLine:Line;
private var bottomLine:Line;
public var upArrow, downArrow:Boolean;
public var upArrow2, downArrow2:Boolean;
public var spacebarDown:Boolean;
public var ballOutOfPlay:Boolean;
public var ballDX:Number;
public var ballDY:Number;
public var playerOneScore:Number;
public function Pong() {
//set speed of ball
ballDX = 10;
ballDY = 5;
//set score
playerOneScore = 0;
//set up stage
showPlayerOneScore.text = ""+playerOneScore;
showPlayerTwoScore.text = "0";
topLine = new Line();
addChild(topLine);
topLine.x = stage.stageWidth/2;
topLine.y = 43;
bottomLine = new Line();
addChild(bottomLine);
bottomLine.x = stage.stageWidth/2;
bottomLine.y = 393;
paddle = new Paddle();
addChild(paddle);
paddle.x = 25;
paddle.y = 80;
paddle2 = new Paddle();
addChild(paddle2);
paddle2.x = 523;
paddle2.y = 80;
paddle2.width = 30;
ball = new Ball();
ball.x = 125;
ball.y = 80;
addChild(ball);
//key presses and stage boundary
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownFunction);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpFunction);
stage.addEventListener(Event.ENTER_FRAME, stageBoundary);
stage.addEventListener(Event.ENTER_FRAME, stageBoundary2);
//animations
paddle.addEventListener(Event.ENTER_FRAME, movePaddle);
paddle2.addEventListener(Event.ENTER_FRAME, movePaddle2);
ball.addEventListener(Event.ENTER_FRAME, moveBall);
//check for paddlecollision
ball.addEventListener(Event.ENTER_FRAME, hitBall);
// check for goal
ball.addEventListener(Event.ENTER_FRAME, ballPosition);
if (ballOutOfPlay) {
removeChild(ball);
}
}
// key pressed
public function keyDownFunction(event:KeyboardEvent):void {
if (event.keyCode == 65) {
upArrow = true;
}
else if (event.keyCode == 90) {
downArrow = true;
}
else if (event.keyCode == 38) {
upArrow2 = true;
}
else if (event.keyCode == 40) {
downArrow2 = true;
}
else if (event.keyCode == 32) {
spacebarDown = true;
}
}
// key released
public function keyUpFunction(event:KeyboardEvent):void {
if (event.keyCode == 65) {
upArrow = false;
}
else if (event.keyCode == 90) {
downArrow = false;
}
else if (event.keyCode == 38) {
upArrow2 = false;
}
else if (event.keyCode == 40) {
downArrow2 = false;
}
}
//move ball
public function moveBall(event:Event):void {
if(spacebarDown) {
ball.x -= ballDX;
ball.y += ballDY;
}
}
// stage boundary
public function stageBoundary(event:Event):void {
if (paddle.y <= 80) {
upArrow = false;
}
else if (paddle.y >= 351) {
downArrow = false;
}
}
public function stageBoundary2(event:Event):void {
if (paddle2.y <= 80) {
upArrow2 = false;
}
else if (paddle2.y >= 351) {
downArrow2 = false;
}
}
//check for goal
public function ballPosition(event:Event) {
if (ball.x < 0) {
ballOutOfPlay = true;
trace("goal");
playerOneScore++;
showPlayerOneScore.text = ""+playerOneScore;
removeChild(ball);
}
}
//move paddles
public function movePaddle(event:Event) {
if(upArrow) {
paddle.y -=10;
}
else if(downArrow) {
paddle.y +=10;
}
}
public function movePaddle2(event:Event) {
if(upArrow2) {
paddle2.y -=10;
}
else if(downArrow2) {
paddle2.y +=10;
}
}
//check for bouncing ball
public function hitBall(event:Event) {
if(ball.hitTestObject(paddle)) {
//trace("hit");
ballDX*=-1;
}
else if(ball.hitTestObject(paddle2)) {
//trace("hit2s");
ballDX*=-1;
}
else if(ball.hitTestObject(topLine)) {
//trace("hitTop");
ballDY*=-1;
}
else if(ball.hitTestObject(bottomLine)) {
//trace("hitBottom");
ballDY*=-1;
}
}
}
}
Any help is greatly appreciated
Thanks
-John
Best Way Around RemoveChild Problem
Scene 1 has my menu buttons that switch pages.
On scene 1 I have symbol12.mc that (in part) dynamically loads .flv onto the stage with addchild.
When I click a menubutton I want to also execute a removeChild(videoHoler)
So I went to Scene1 action frame and I added in
stage.removeChild(videoHolder);
inside each menu button CLICK function.
The error I get is "access of undefined property videoholder" for each of the times that it was added.
How can this best be fixed so that the video dissapears when the viewer navigates to the next webpage
RemoveChild Problems
Hey everyone!
http://www.c1nz.com/files/manual/share/game.swf
http://www.c1nz.com/files/manual/share/source.zip
I am having problems - my vehicle disappears off the stage, but a trace("I exist") proves it is still there.
Test it out above, click on the Garage to spawn a few enemies, and move close to the enemies.
(Error #1009: Cannot access a property or method of a null object reference.)
Thanks in advance!!
RemoveChild Errors
I am trying to create a movie clip by using a button in Flash. The button's instance is cir_btn which creates a circle on the stage
I am using an external .as file to generate the public class Cir which calls upon several mouse actions as well as referrence a movie clip in my library that contains a shape. The movie clip's name is circle and it has a linkage of circle
I am able to repeatedly generate circles inside of the swf, however when I try to use the remove button, this is what I get:
ReferenceError: Error #1065: Variable circ is not defined.
at Cir/::removeCirc()
Here is the code for my .as file:
ActionScript Code:
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Cir extends MovieClip {
var timeline:MovieClip;
public function Cir(tl:MovieClip) {
timeline=tl;
timeline.cir_btn.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
timeline.reset_btn.addEventListener(MouseEvent.MOUSE_DOWN, removeCirc);
}
public function onMouseDown( event:MouseEvent ):void
{
var circ:MovieClip = new circle;
circ.x = 110;
circ.y = 70;
this.addChild(circ);
}
private function clicked(e:MouseEvent):void {
removeEventListener(MouseEvent.CLICK,clicked);
}
private function removeCirc( event:MouseEvent ):void {
parent.removeChild(circ);
}
}
}
Just to see if I was ever meeting the removeCirc function, I did both a trace and I changed the code from parent.removeChild(circ); to parent.removeChild(this); which does remove the circle from the stage, but I can't generate a new circle as long as I have the swf open. I am having a very hard time unlearning AS2 to learn AS3. Can any one help me out?
EXTRA CREDIT: I am also looking for a way to constrain the circle movie clip to a certain portion of the stage only. Some kind of bounds command so that the movie clip will only display in a rectangular area inside of the swf. This is not as important right now as figuring out how to remove the circle, but I will need to get to it eventually.
Thanks in advance.
RemoveChild() Problem
I'm trying to delete this sprite is its y position is greater than a certain number.
this gives an error during run-time when it gets past the number where it should be removed.
BTW, this class is used within ANOTHER class which is where this is added.
in the other class i used it like
var S:Star = new Star();
S.move();
myContainer.addChild(S);
How do I kill it after it's y position is too big?
Code:
package com.game.graphix
{
import flash.display.Sprite;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class Star extends Sprite
{
private var p_timer:Timer;
public function Star()
{
graphics.beginFill(0xFFFFFF);
graphics.drawRect(0,0,2,2);
graphics.endFill();
x = Math.random()*600;
trace("star has been created.");
}
public function move():void
{
p_timer = new Timer(30);
p_timer.addEventListener(TimerEvent.TIMER, p_onTimer);
p_timer.start();
}
private function p_onTimer(event:TimerEvent):void
{
y += 5;
trace("move y["+y+"]");
if (y > 300)
{
trace("kill me");
removeChild(this);
}
}
}
}
RemoveChild Question
I am making a small site that has a basic image gallery in it. The site navigation is real basic with frame labels and gotoAndStop functions. I have a few pages that require image gallerys that I have written a class for. The code I'm using to add the gallery is:
import classes.ImageGallery;
var gallery:ImageGallery = new ImageGallery("images.xml","thumb","source");
addChild(gallery);
I am wondering if anyone could tell me an easy way to remove the image gallery when navigating to other parts of the site. I've tried just putting:
removeChild(gallery);
in the functions to navigate to other labels but it keeps giving me this error:
TypeError: Error #2007: Parameter child must be non-null.
I was thinking of using a conditional statement but I'm not sure how to reference the gallery object correctly.
RemoveChild, Only If It Exists?
When I create an instance from a class, lets say like this:
Code:
circle = new Circle("blue");:
box.addChild(circle);
and later want to replace the blue circle with a green, how can I do?
I mean the application doesnt always know if a circle have been added
or not before.
So if I try this:
Code:
box.removeChild(circle);
circle = new Circle("green");:
box.addChild(circle);
...I get an error if there was no circle-instnce there allready.
So how do I solve this?
Thanks.
|