Forum ActionScript 3.0 objects arent being removed?

Problems and discussions relating to ActionScript 3.0 here.

objects arent being removed?

Postby kuvi » July 26th, 2013, 7:35 am

Ive made a significant coding breakthrough since this post so readers should jump down to my second post

The following is a detailed description of my problem, readers may wish to skip to the last paragraph for a strait forward question without the detailed scenario laid out


ok so in my game the server invokes a create arrow(as in bow and arrow) method, flash recieves this message and builds the arrow, first i create a playerarrow:object = new Object(), then i will give this object properties, such as, hp:int = 100, startx:int = 50, starty:int = 50, and so on. The last property of this object is the movieclip to be shown -- playerarrow.theicon = new theplayerarrow() //theplayerarrow is a library graphic of an arrow, this is exported for actionscript with the flash extends movieclip during the create symbol process

ok so newarrow is invoked, object playerarrow = { hp:100, startx:50, starty:50, theicon:theplayerarrow }
so essentially now i have a movieclip that can have very dynamic properties for later, not just its coordinates, but also things like hit points remaining, thearrowID which is an increment sent by the server for easy referencing etc

now that my object[property, property, property, property, movieclip] has been created, i push this into myarrowarray.push(playerarrow) and gw.addChild(playerarrow.theicon) //gw is just another movieclip i have on stage, you can just think of gw == stage for this example.

so now i have been invoked by the server to create a new arrow, so i built this object dynamically with some passed in variables such as hit points, attach a movieclip representation of the object and then add the OBJECT to an array, and add the object.theicon extension itself to the gamewindow

now when i run the program i can extend my arrow objects icon and my enemy objects icon and hit test them versus one another, this is my actual code

for each(var d in myenemyarray){
if (npa.theicon.hitTestObject(d.orcicon)){ connection.send("arrowhitmonster", npa.arrownumber, d.monsternumber) }}
//npa stands for newplayerarrow

this sends the arrows id and monstersid to the server which is relayed back to all players in the game, then there is a recieved handler function which just takes in the arrowID and monsterID and then gets rid of the monster and the arrow from the stage, the following is just the arrow portion:

===========================================================
//DELETE AND REMOVE ARROW FUNCTION (comprised as two functions to prevent trying to delete already deleted object)
var toDelete2 = false //starts by pretending the object was previously deleted
var indexToDelete2 //the index reference if the object appears in the array

//checks if the arrow exists
for each(var d in myarrowarray) {
if (d.arrownumber == arrowid) { //goes through array and figures out oh, hey, it does exist
trace("this arrow exists")
toDelete2 = true //momentarily flip on the 'if flag' for deletion
indexToDelete2 = myarrowarray.indexOf(d)}} //the index we need to delete it from array

//the actual delete method
if (toDelete2 == true) {
toDelete2 = false; //immediatly flip off ability to delete this object, then proceed
trace("index of arrow is " + indexToDelete2)

var temparrayobject = myarrowarray[indexToDelete2]; //easy reference to the array.index.object
gw.removeChild(myarrowarray[indexToDelete2].theicon); //successfully removes graphic representation

myarrowarray.splice(indexToDelete2.theicon, 1); //code that worked in a previous game for removing array movieclips, however, now that its objects its getting fuddled
**********************************************************
//example :
myarrowarray.splice(indexToDelete2, 1); //this is essentially what i WANT but i get the trace error implicit conversion of object to movieclip
===========================================================

ok now the problem, so even though i can successfully remove the movieclip on myarrowarray{([0], property, property, [movieclip])}, it seems i cant remove the parent object, of type object, from the same array

additionally, in a similar fashion, i can remove the moiveclip (.theicon) potion from the gamewindow-movieclip(or stage if you prefer to think of it) but after the graphic goes away the object must be remaining because this now pictureless object can still hit subsequent monsters behind the first one it touched

OK, so the answer im seeking: clearly the problem lies in that im trying to apply a movieclip built in method addChild, and removeChild to an object and theres a conversion error, what i need to know, in short, is what would be the syntax for the exact same thing but for an object class instead of the movieclip class
Last edited by kuvi on July 26th, 2013, 8:32 am, edited 1 time in total.
kuvi
 
Posts: 11
Joined: March 29th, 2011, 12:32 am

Re: objects arent being removed?

Postby kuvi » July 26th, 2013, 8:25 am

Again i give a lengthy description, readers may choose to skip to the bottom for the most concise question

ok since writing this i did some experimenting and got rid of having to make objects with extended movieclips, i now know how to attach variables directly to movieclips thereby eliminating alot of code and confusion.

so even though now i have an array of movieclips, when i remove the movieclip from the stage and array, its invisible movieclip still moves to the right interacting with other objects, namely, after having an affirmative collision detection, the movieclip(with properties attached to it) is removed from stage, it is also spliced from my old-object-array-now-movieclip-array, and although its visually missing its still physically colliding with all the other monsters.

so heres my guess, even though i removed the movieclip, which has some child properties, from the stage and array -- i think its child properties are still remaining, namely my event.addlistener.enterframe

so now what the question boils down to is -- how do i not just remove a movieclip, but also all of its contents (in this case variables and event listeners)

im hoping for a simple built-in function that takes care of it for me, or even a possible itterative loop for all qualities belonging to the clipToBeRemoved to be removed one at a time, but the last thing i want to do is manually remove variables and event listeners, cause in the long run this will become an overly cumbersome process

====Question: 1====
so basically i need someone to tell me the syntax of the following psuedo code
stage.removeChild(newarrow<and all my child properties including but not limited to variables and eventlisteners>)
OR
stage.removeChild(myArrowArray[6]<and all my child properties including but not limited to variables and eventlisteners>)

====Question: 2====
my attaching variables to a movieclip is brute force, what would be the syntax that would make this all one statement?

var newarrow:MovieClip = new playerarrow();
newarrow.theowner = username
newarrow.thespeed = speed
newarrow.thegravity = gravity
newarrow.thepower = power
newarrow.arrownumber = arrowid
kuvi
 
Posts: 11
Joined: March 29th, 2011, 12:32 am


Return to ActionScript 3.0



cron