ActionScript 3.0 :: Best Practices For Removing Objects?
Apr 3, 2009
I have a question about how best to remove display objects.removeChild(object);Given that there are no other reference to this object, does using removeChild alone make the object eligible for garbage collection, or does it also need to be given a null value as well?[code]In both these cases, I get the classic 1009 error. That leads me to believe that if you use removeChild, you don't also need to give the object a null value.?url...
View 2 Replies
Similar Posts:
Mar 7, 2006
I thought i'd start this thread to uncover peoples habits and practices when it comes to the simple operation of adding and removing elements on stage. I ask because there are so many alternatives, and I keep wondering what might be the best/most eficcient way of doing it. Let me explain by giving an example:
Your user has chosen to click that flashing button that says "Sign up for our mailing list" and you need to prompt the user for a valid e-mail address by presenting him/her with an alert box on top of everything else. Do you.[code]....
View 3 Replies
Oct 3, 2011
I have an application with about 20 models and controllers and am not using any particular framework. What is the best practice for using multiple remote objects in Flex performance-wise?
1) Method 1 - One per Component - Each component instantiates a RemoteObject for itself
2) Method 2 - Multiple in Application Root - Each controller is handled by a RemoteObject in the root
3) Method 3 - One in Application Root - Combine all controllers into one class and handle them with one RemoteObject
I'm guessing 3 will have the best performance but will be too messy to maintain and 1 would be the cleanest but would take a performance hit.
View 3 Replies
Jul 10, 2009
i am having a problem removing objects from the stage and their associated arrays. basically when a "shark" is added to stage i want all "cans" to be removed and i dont want any "cans" to be added until the shark has left.my problem comes as i dont want to keep using for loops as i already have two or three for "cans" alone and i heard thats not good for the code!
Code:
var canTimer:Timer=new Timer(2000);
canTimer.addEventListener(TimerEvent.TIMER, addCan);
canTimer.start();
[code]....
im not 100% sure were to put this in my code-i didnt really want to put it in a function of it's own as it would mean using another for loop?i get a output error when a shark is added like this:
Quote:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display:isplayObjectContainer/contains()
at dolphinmoviegame_fla::MainTimeline/canHitTest()
even though all "cans" are removed.
View 1 Replies
Feb 23, 2009
I have a utility function:
function removeFromArray(item:Object, arr:Array):Object {
for(var i:uint = 0; i < arr.length; i++) {
if(item == arr
[Code]....
This function searches through an array and sees if an item exists in it, if it does, it removes it and returns a reference to that item.
This works fine for most things. But I just ran into a problem where I need to remove an array from an array.
so my array looks like this [ [item1a, item1b], [item2a, item2b] ]; and i need to remove [item1a, item1b] from it. But passing in the the array to remove and the full array to remove it from does not work because i guess of the casting to an object in the parameters list. Can the functionality i want be used? if so how?
View 1 Replies
Oct 15, 2009
I have a problem with this code:[code]There are two overlapping objects on my stage: character_mc and vanish_mc. As soon as i start the scene [Ctrl+Enter] vanish_mc is VISUALLY removed. But the code still sees a collision somehow. How can i Entirely remove the object vanish_mc?
View 7 Replies
Mar 19, 2010
i don't understand why none of my display objects are not being removed. when i press the button, i'm expecting a trace and removal of both shapes and the button, but nothing happens:
[Code]...
i realize there are better ways of accomplishing this, but i'm learning and therefore only interested in why the above code doesn't work.
View 3 Replies
Feb 4, 2010
I have made a class that creates a dotted line following a moving object. The dotted line is small circle added to the stage (and to an array) every half a second at the object's position.
First I add the circles to the stage, when the object stops moving I remove them from the stage.
This, however, only works twice, after that it throws a "display object must be a child of the caller" warning.
ActionScript Code:
public class Path extends MovieClip {
var tInterval:Timer=new Timer(50,500);
var pathArray:Array=new Array ;
[Code].....
View 2 Replies
Feb 22, 2012
I'm making a banner rotator that reads image urls from an xml file and adds them to a sprite on the stage, then tweens them into position. Here's the relevant code:
[CODE]....
View 2 Replies
Sep 14, 2010
I seem to be running into some garbage collection issues. I'm making an RTS game with a side scrolling map. I have a "game" layer on the stage which scrolls left and right, all the troops, vehicles, bullets, etc are within this layer. If I scroll the game layer to the far side of the map from some tanks placed at the other end, the tanks disappear. I can only assume flash is "helpfully" removing objects it thinks are too far away form the action to be of use any more. I'd rather it didn't.
View 2 Replies
Dec 10, 2008
I've created a navigation system using Flash 3D functionality. It consists of a MovieClip with a rounded rectangle + a text with no-antialias bitmap font. I'm using Tweener to modify the z co-ordinates of the mc to make it "slide onto" the stage. However when the mc is completed animating it is notably blurry (the text at least). I was wondering if it might just be because it's in 3D-space the perspective (which hasn't been modified) is throwing the rendering off. So onComplete of the animation I try assigning null to the z-value in hopes of removing the item from the 3D space. I've attached the package code I'm using to create and animate the navigation feature.
View 1 Replies
May 14, 2009
I was just wondering--and it's probably an obvious question really--if I make an object null and that object had one or more event listeners registered, are the listeners removed?
for example:
Actionscript Code:
object.addEventListener(Event.SOME_EVENT,callBack);
function callBack(evt:Event):void
{
object = null;
[Code].....
In this case have I removed 'object''s listener when I made the object null?
View 1 Replies
Jul 19, 2011
I use this piece of code to create some eyecandy of debree falling. When an object is destroyed i spawn some rubble and let is fly over the screen. But... when i use this a lot, slowdown is there and even when all the objects are gone the slowdown stays. The good old 50fps won't come back anymore
public function destroyBlock(xPos,yPos,nrObjects) {
for (var debree = 0; debree < nrObjects; debree++) {
debreeObject = new mc_ground();
[Code].....
View 2 Replies
Jan 1, 2010
I have an animation of footprints being left on the ground as if by an invisible man or ghost. the animation consists of:
1 movieclip containing --> 5 footprints each one is an individual movieclip. Each print fades in and out using the Tween class with an alpha effect
The main timeline uses the following code to create random instances of the animation:
var myTimer:Timer = new Timer(12000);
myTimer.addEventListener("timer", timedFunction);
myTimer.start();
[Code].....
so it looks like the function is being called correctly and removing the first instance of FOOT from the stage. but the 2nd iteration generates the error. Is this is a problem with the timer? I would like to send this to someone for examination and assistance.
View 3 Replies
Oct 15, 2009
I'm trying to make a Starfield program as practice for ActionScript 3. I'm using a timer event in the document class to create Star objects which are defined by an object class connected to the movieclip Star in the Library. The object class has a timer as well, and at each tick it repositions itself a few points away and scales up, creating the image of a star shooting towards the sides of the stage. When the star has gone past the boundaries of the stage or when it has scaled to a certain size, it removes itself from the display list with the command: this.parent. removeChild(this);This removes the star from the display list just fine, however after that I can't get the star to set itself to null so that it will be removed from memory, and I'd like some suggestions on how to do this properly. An idea I had was to make a function in the document class that the child objects can call, something like this.parent.KillMe(this) which would give itself as a reference to the function, which could then use a local variable reference to set the child to null, removing it from memory. This all seems terribly complex, so I'm sure there's another way.
I haven't noticed a memory leak or slowdown, however, so I'm curious if objects without references that are removed from the display list are automatically removed? That could be both good and bad, as the object might want to add itself to the display list again at a later time; not in this Starfield program, but perhaps in another I write.
View 11 Replies
May 1, 2010
I'm moving two objects accross the stage at different rates using the same function:
Code:
function moveClip(clip,speed){
clip.addEventListener(Event.ENTER_FRAME,moveIt);
function moveIt(event:Event) {
[Code]....
In AS2 I'd just use dot notation as above and it would work from anywhere or perhaps _root.red....
I've tried root. stage. childbyname Not sure where to from here.
View 2 Replies
Jan 2, 2010
I am trying to add some Sprite objects as the contents of an array, and I would like to be able to "clear" them from the stage. I would assume that if there are loaders involved, I need to do
_imgArray[i].close();
_imgArray[i].unload();
And if I am using a sprite, I can do:
removeChild(_imgArray[i]);
None of the above work.
Currently I try:
for(i = 0; i < _localXML.length(); i++) {
var tmp:BMLink = new BMLink(_localXML[i], _bw, _bh, i);
_imgArray[i] = tmp;
_imgArray[i].x = (_bw + _mainpad) * i;
_base.addChild(_imgArray[i]);
But this doesn't work.
The class instances that are populating the array are all extending sprite, but they have their own individual loaders inside w/ progress events etc.
View 2 Replies
Apr 18, 2011
I've got an array of coins, which are called within the array coin1, coin2, coin3, coin4 etc. I'm trying to reference them to say if the character hits coin 2, then coin2 will disappear. Here's my array (so far):
ActionScript Code:
var coinArray:Array = [coin1, coin2]; //an array which contains all of the coins
And here's the script I'm working on:
ActionScript Code:
function coinCollect(evt:Event){
if (collisionTest (character, coin/*[n]*/){
var i:int = /*the number from coin[n]*/ - 1
remove coinArray[i]
}}
But I'm missing some major things, mainly how to reference which coin has been hit, and how to take the number from that coin and take 1 from it to reference it's correct position in the array? (the code in /* */ tags represents things I'm not sure on the code of).
View 2 Replies
Mar 7, 2011
Im creating a game. When the current game has finished, I thinking to do this:
removeChild(game)
game = null
then
game = new Game()
Doing this way, it automatically removes the games object instances? It automatically removes the games object instances events? That would be an easy way to restart the game, if yes for both questions.
Can I do like that, or I have to remove all objects and events manually?
View 4 Replies
Sep 23, 2011
After adding an image to the stage, turning it into a Movie clip, and setting linkage in library to Export for Actionscript, I'm now using a timer to add a bunch of roses to the stage as a video plays.How can I get rid of all these clips once the video is over?Do I need to add all of them into an extra container and then just removeChild that container at the end? Or do I need to use something like getNumberOfChildren and then create a loop that removes them one by one?The clips (myRose) are fairly small and do not have any event listeners added to them. I just use TweenMax to move them from top to bottom of the screen.
public function roseTimer():void
{
MonsterDebugger.trace(this, "in roseTimer");[code]......
View 4 Replies
May 31, 2010
Is this at all possible? I just finished re-building my entire portfolio site in AS3 because I can't change the frame rate for loaded content in AS2. Now I find out after completely rebuilding this thing that AS2 content gets stuck in Flash Player 9's memory and won't erase on Loader.unload. All my work from years back is in AS2.
View 0 Replies
Mar 21, 2011
I've asked this question before but had no answers... so here I go again I have a structure of objects: Top object A has as children (addChild children that is...) one or more objects B_1 to B_n. The B_n may in turn have one (1) associated object A' (Same type as top object, not displayed to begin with). When I click a B_n two things may happen:
1. If it has as associated object a A', put it on the stage (as child to B_n).
2. Otherwise it is a leaf and it does other things.
If '2' happens I want to collapse the tree, that is remove the top and all children of same type from being displayed. I thought a recursive approach should work:
[Code]....
View 4 Replies
May 8, 2009
So a small example of my situation...On my stage I have 5 items labeled item1_mc, item2_mc, item3_mc and so forth...they all have two keyframes on their respective timelines, one labeled "active" and the other "inactive". My code contains 2 arrays, inactiveArray and activeArray and a variable known as energy that regularly goes to and from 0 - 100.
What I am looking to achieve is basically the function of...
if energy >= "insert given items 'active threshold' 20, 40, 60, etc..." then add it to the activeArray, if it is not, remove it and add it to the inactive array.
all objects in activeArray gotoAndStop("active");
all objects in inactiveArray gotoAndStop("inactive");
I have tried many different ways of achieving this effect but I always end up with duplicates and extras or something doesn't move when it's supposed to, where it's supposed to, it just ends up into a giant cluttered mess and I start from scratch.
View 8 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
May 28, 2011
currently i am removing objects when they reach the edge of the screen with
[Code].....
i understand this does not delete the object? without removing event listeners before removing the object the error log fills up, i believe its due to the stage isnt there after its removed. this makes me think that removechild does not delete the object? i will be creating and deleting many objects during runtime, and i dont want to slow down or use too much memory, how to properly free up the object
View 3 Replies
Oct 27, 2010
Using CS5 AS2.I'm creating a website in flash (all the files will be in one directory/folder on SharePoint) and want to make sure that what seems to be working fine is best practice.I have an index.swf with many buttons which will take the user to landing pages/content/other swfs. On these different buttons I have the script [code]The movie transitions nicely to name.swf and on this page I have a button that returns the user to the index.swf on (release) {loadMovieNum("index.swf", 0);}Things move back to index.swf nicely and user can chose to go to another landing page.It looks like I'm on the right track, bc nothing is going awry? but want to check. Am I following best practices for moving from one swf to another within a website?
View 3 Replies
Jul 16, 2011
I'm using this simple code to retrieve a value from a PHP script:
package
{
import flash.display.MovieClip;
[code]....
View 1 Replies
Feb 27, 2010
I've been working on a game the past few days where there is to be a LARGE amount of stored data. By a large amount, I'm talking something like 200+ entries of around 12 fields.The game is being designed with the intent of playing it online (per say), so I can't rely on storing specially made files on one's computer (Not that I think I could and do it in a way where players cannot modify it). I also do not want to rely on a stored XML file on the internet or on a database, because if the website that has this data goes down or if the person loses internet access, then the game becomes unplayable.So, I need to store this data in the game itself, but I am unfamiliar with the best way to go about doing this. I've normally worked with outside sources for data storage, as they were designed in closed environments (aka intranet) or the website that the SWF would be on would also be where the database used is stored. Neither apply to this game, as the game will likely be put up on Flash portals like Newgrounds.
View 17 Replies
Nov 25, 2009
We have recently deployed Flash Media Streaming server 3.5.2 and Flash Media Encoder on a Windows 2003 machine. Do you guys know of any security best practices to follow for the FMS server deployment on a Windows machine, could you please point me to that resource.
View 2 Replies
Jul 18, 2010
What are, nowadays, the best practices for uploading a large file (which may cause a timeout) with ASP.NET Web Forms and/or MVC? Increase Server.ScriptTimeout (only for the specific POST request); Use some flash client-side uploader like swfupload ([URL]) or plupload ([URL]), but Flash uploads have some issues with proxies; Use some gmail-like javascript (like [URL]
View 2 Replies