Flash :: Destroying Objects (and Their Children) Removed From Stage
Jan 25, 2012
I am working in on a Flex / Air application (using PureMVC) written virtually entirely in ActionScript 3 (i.e. we use very little of Flex). View components are added to a Canvas object in the main application window and these Views then load other movie clips, images files, etc.When I remove a View from the stage, I do so using application.canvas.removeChild(). This fires an event in my PureMVC mediator for that View, which removes any event listeners that were set up and everything appears to be dandy.However, the movie clips are still playing in the background. They are not causing any trouble on screen but they are simply there, playing somewhere in memory (e.g. I can see trace statements from them) and I want them gone. I suspect the View that was removed from the Canvas is still there too, but I can't prove it.
Setting the View to null doesn't do anything. I'm surprised that AS3 doesn't include any method to simply and effectively destroy a Display Object and all of its children.Is the only way to do this to tediously unload all of the movie clips, etc. and then hope that Flash will clean them up?
View 2 Replies
Similar Posts:
Apr 7, 2011
I want to remove all children of the name (mc1) but be able to add new one when I call the add function again Heres what I have
// Draws the squares
Code:
function drawIt(e:Event=null):void{
mc1.graphics.lineStyle(1);
mc1.graphics.beginFill(ITsColor);
[code]....
Removing all the (mc1) movieclips works fine, but when i click on the butotn to call drawIt again, all previous mc1's are displayed again with the new ones
View 2 Replies
Aug 8, 2010
I've noticed that using stage.addChild(obj)(i.e. creating objects on the fly) can slow down frame rates.I was told by several sources that one way to speed up a flash game engine (or any animation where instances are generated as you progress), is to reuse objects in what is known as object pooling.
First of all a bit of background:The game engine I'm working on can be found at: http:[url]....Most objects (i.e. bullets, particles, enemies...) are exported for actionscript, each with a set of actions that are performed each frame, and another set of actions upon being created.Each class has an array called instanceList, which keeps track of all objects currently within play.The main timeline contains an event.ENTER_FRAME function mainActions(event:Event):void, that loops through each of the instances and performs the actions associated wit11h each.It goes through each instance of each class by going through the static array instanceList().
Now what I plan to do is:Have a seperate static array for each class, called inactiveInstances,which keeps track of deleted objects.Introduce a function for adding the objects back to the stage (with the nesscessary variables reset), to give the impression of a new object being created.When objects are destroyed:Should they be removed from the stage and readded latter e.g. removeChild(obj2)/addChild(obj1)? e.g.
Code:
public function instance_destroy()
{
parent.removeChild(this)
//Remove all refferences and listeners[code].....
View 5 Replies
Aug 17, 2009
if i have a movie clip with an even listener attached to it, is the event listener being removed automatically when the movie clip is removed from the stage or should i always remove the event listeners manually?
View 4 Replies
Jan 23, 2012
After having some trouble with object deletion, I ran a simple test:Created a simple class with a weak reference listener for Event.ENTER_FRAME.Added a trace("I Exist!") call to the listened function.Instantiated a single instance with one reference in the Document Class.his worked as expected - the SWF file did nothing but print "I Exist!" every frame to the console. (In debug mode, of course.)What I did next did not work as I expected:I set the only reference of the object to be set to null on a mouse event, but the messages from the event listener of of said object still appeared in the console after the mouse event was fired and the reference set to null - meaning the object still existed!Calling System.gc() in the document class IMMEDIATELY stopped the event listener from printing further messages and seemingly deleted the item.
From what I understand, calling System.gc() is discouraged, but as it seems from this simple test the garbage collector is a big FAIL.Am I doing something wrong here in trying to dispose of the object, or should I simply call System.gc() every time I want to get rid of an object..?
View 4 Replies
May 11, 2011
I'm adding a series of objects dynamically to my flash movie from xml but they won't appear when I run the movie. I have nearly identical code adding objects in a different swf that works just fine. I have tested this 8 ways from Sunday including ensuring that they were added to the container which is a child of the main MovieClip (tested the display list), that they were added to stage (had a listener for ADDED_TO_STAGE) and that their position was correct (displayed x,y values and compared them to mouseX & mouseY values). They are in the correct place in the display list. Still there are no objects. The class is linked correctly, I have movie clips in the library.[code]
View 3 Replies
Jan 14, 2009
i have many squares inside a movieclip, and i remove random some of this squares, what i need id: get the real with and heigth of my movieclip, after the squares are removed, i do a little exemplo, and anexed here,
[Code]....
View 1 Replies
Nov 21, 2010
Anyone know if there's a way to check for objects in memory that have been removed from a display object but not set to null?
View 1 Replies
Feb 15, 2010
I am sorry if this is a truly basic question, but how would I code as3 to remove an event listener when the current frame (in my case, section of my site) is no longer on the stage?ke the following code as an example:
function onClick(event:MouseEvent):void
{
doSomething();
[code].....
View 3 Replies
Jan 26, 2012
When bullets hit the wall of multi-colored blocks, when shot one by one, they disappear like they should. But if you hold down the Left Mouse Button, you will see that bullets stop in mid-travel and I can't figure out how to fix that.
See this occur in this SWF. Note:(Use A & D to move left to right, Z to add a new row, and Left Click to shoot)
Here's the important function in the Bullet class.
Code:
public function update():void {
if(global == null){
trace("Global es null.");
[Code]....
View 2 Replies
Jan 12, 2011
sometimes when I import pngs from a Photoshop document and try to make a movieclip with them (F8 ...) Flash is just crashing.
And sometimes it gives me an error message that there is not enough memory.I think this happens when trying to put a png from a Photoshop import and a text or vector object from different layers into a MovieClip.
Today I had the memory error. And after that, flash is creating a mess in my movie. It is just duplicating alles layers in a Clip and also duplicating all labels along my timeline, when I try to work on it. I tried restart but this bug apears again.Is there a way to heal my fla so I can deliver my project soon?
View 13 Replies
Mar 3, 2012
The REMOVED_FROM_STAGE event is fired before the object is actually removed from the stage. I'm looking for a performant way to know when the object is finally removed.
View 3 Replies
May 17, 2010
In AS2, to check if the mc is removed frm stage, i wuld simply just need to do this:
Code:
removeMovieClip(mc);
trace(mc);
[code]......
View 4 Replies
Jan 29, 2011
I am trying to make it so when you click anwhere on the stage the movieclip cursor is removed.
Code:
stage.addEventListener(MouseEvent.CLICK,ketchremove);
function ketchremove (evt:MouseEvent):void
{
trace("I am removed");
[Code]...
View 7 Replies
May 1, 2011
In the past, using Flash CS3 when I needed to remove timers or event listeners from a swf that had been loaded into a parent swf I'd use this inside the loaded swf:
Code:
this.addEventListener(Event.REMOVED_FROM_STAGE, deactivate, false, 0, true);
function deactivate(e:Event):void
{
[code]....
Now that I've upgraded to CS5 and am outputting to Flash Player 10 this no longer seems to work. The event fires right away. Does anyone know why this might be and if there's an alternative that I can use?I tried the unloadAndStop() method in the parent swf but I'm trying to remove some TweenMax delay timers and it doesn't seem to be working.
View 4 Replies
Feb 7, 2012
In the past, using Flash CS3 when I needed to remove timers or event listeners from a swf that had been loaded into a parent swf I'd use this inside the loaded swf:
Code:
this.addEventListener(Event.REMOVED_FROM_STAGE, deactivate, false, 0, true);
function deactivate(e:Event):void
[code].....
View 1 Replies
Nov 15, 2009
I have a main swf that I load external swfs onto the stage. I am trying to fix the loading order. Currently when a button is pressed, the swf is preloaded, the current swf is on the stage with the preloader showing, then the preloader disappears and the swf plays the outro transition.
how to change the order so that currently loaded swf is removed from the stage, show the preloader and then show the new swf.
Code:
package
{
import flash.display.MovieClip;
import flash.display.SimpleButton;
[Code].....
View 7 Replies
Aug 12, 2010
I have two FLV files playing on the stage. The main FLV is instance is: MyVideothe 2nd is MyVideo2I have imported the videos using the wizard. The 2nd video is just a movie I created in Affter Effects that says...loading please wait....this is a really nice video and I don't want it to just use a standard preloader. Anyway, the goal is when the playback for "MyVideo" begins I would like "Myvideo2" to = visible = false;I have tried this many different ways and have been unsuccessful. I am obviously a newb at this. Also, does anyone know where I can get a list of all available eventListener actions...etc?
//var nc:NetConnection = new NetConnection();
//connection_nc.connect();
//var stream_ns:NetStream = new NetStream(connection_nc);
[code].....
View 1 Replies
May 17, 2011
I have ran into another problem, I have written the code for when I click on an enemy, it doesnt add a point to the score and it doesn't remove the enemy, I have a textfield which is called messageDisplay which is linked to the clickEnemy function.Here is the piece of code.
stage.addEventListener(MouseEvent.CLICK, clickEnemy); function clickEnemy(event:MouseEvent):void { if(cursor.hitTestObject(enemyAppear)) { score++ messageDisplay.text = String(score); enemyAppear.parent.removeChild(enemyAppear); } } stage.removeEventListener(MouseEvent.CLICK, clickEnemy);
View 2 Replies
Jan 4, 2009
I was told that if you load a new SWF into a loader that has an existing SWF that the second SWF will replace the object(the first SWF) in the loader and in the display list.Does this mean that the first SWF is removed from the stage once the second SWF is loaded? I am asking because I would like to know if my this.addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler1); in the first SWF will fire once the second SWF is loaded.
View 3 Replies
Feb 16, 2011
I was told that if you load a new SWF into a loader that has an existing SWF that the second SWF will replace the object(the first SWF) in the loader and in the display list.
Does this mean that the first SWF is removed from the stage once the second SWF is loaded? I am asking because I would like to know if my this.addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler1); in the first SWF will fire once the second SWF is loaded.
View 0 Replies
Aug 16, 2010
I am currently play with the document class (the class acts as main) constructor for a SWF file.
package {
import flash.display.*;
import flash.events.*;
public class TestSymbol extends MovieClip
{
public function TestSymbol()
[Code]...
View 9 Replies
Dec 7, 2010
In the setOne_mc I have three buttons close_btn, min_btn and max_btn....I want the movie clip to be removed from the stage if close is released.I seem not to be conecting with the buttons...the clip appears on the screen.
menuBar_mc.dropMenu_mc.subMenu01_mc.onRelease = function() { holder_mc.attachMovie("setOne_mc","setOne_mc",2,{_x:0, _y:0}); halt();};holder_mc.setOne_mc.close_btn.onRelease = function() { go();};function go() { this.removeMovieClip();}
function halt() { menuBar_mc.dropMenu_mc.subMenu01_mc.enabled = false; menuBar_mc.dropMenu_mc.subMenu02_mc.enabled = false; menuBar_mc.dropMenu_mc.subMenu03_mc.enabled = false; menuBar_mc.dropMenu_mc.subMenu04_mc.enabled = false; menuBar_mc.dropMenu_mc.subMenu05_mc.enabled = false;}
View 8 Replies
Jun 8, 2008
I've recently worked on creating different classes for movieclips within my library so when i create/attach them they have built in functionality.My question is simple how do i destroy them so that other objects don't recognise their existance.There are two classes involved.The first is a Ship Registry Class and the Secound the Ship:
Code:
//inside the ship init class
ShipRegistry.RegisterShip(this);
[code].....
View 2 Replies
Dec 3, 2008
This post is related to another post I have in the forums: "Dynamically adding containers".[code]...
View 3 Replies
Nov 18, 2009
I'm making a OSX-finder-type file browser in CS4.The Structure for the folder and files is being generated by a PHP in a XML, heres an example:(sorry the xml is not sorted, but the command i'm using in php doesn't sort it)
Code:
<root>
<dir name="images">
[code]....
View 2 Replies
Jul 14, 2010
I have a movieclip which contains other movieclips/loader. Does removing the parent movieclip removes all the children objects?
View 5 Replies
Dec 31, 2011
I know it is possible to make instances/children interact with other objects by adding an eventListener to each child/instance.But how do you make a random instance/child interact with another random instance/child?Example: let a bunch of spaceships get damaged by a bulletrain by using addChild to place both spaceships and bullets on the stage.
View 2 Replies
Apr 30, 2011
I have a website [URL] when I go there if I click the video archives button then play a video then click on the home or photos button or one of the alternate background buttons on the left the video goes away as it should but not always the audio (especially when I click while the video is still buffering). Is there a command I can use to kill the sound from the flvPlayback component and nothing else(I have a mp3 player there also I so I don't want to use the SoundMatrix class. btw the videos are all played on an instance of the flvPlayback component.
View 7 Replies
Jun 21, 2011
I have two symbols. player and wall. The player symbol has a custom made class.For some reason a player object on the stage is a child of the stage but the wall objects are not. Why are the wall objects not children of the stage?
View 3 Replies