actionscript-3


Why can't I remove this Movieclip?


I have a TouchEvent function onTouch inside the constructor function of a item_Potion class that gets run when a Movieclip is touched. This function goes through a series of unrelated checks and then in the end it is supposed to remove itself (the Movieclip).
At the end of the onTouch function it is supposed to remove itself by doing the following:this.parent.removeChild(this);
However, this does not work.
I get the following error message:
TypeError: Error #1010: A term is undefined and has no properties.
at Function/item_Potion/$construct/onTouch()[E:\Clients\org\tcdsb\ZenithsReach\item_Potion.as:56]
at runtime::ContentPlayer/simulationSendTouchEvent()
at runtime::SimulatedContentPlayer/clientSocketDataHandler()
The line it's reffering to for the error message (Line 56) has the following:
this.parent.removeChild(this);
My imports:
` import flash.display.Stage;
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.*;
import flash.events.TouchEvent;
import flash.net.dns.AAAARecord;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;`
I know the problem is not with the other portions of my code because I have tried switching this line out with visible = false; and I get no errors. Therefore, I am certain that the issue is with the way I am removing the MovieClip, and that is where I need help.
Similiar Sources I have tried that do not work:
How to make a MovieClip remove itself in AS3?
parent is undefined in your example, hence the error "a term is undefined...".
You can avoid the error by wrapping your code in:
if (parent) {
parent.removeChild(this);
}
But based on your comment providing [object global] is sounds like you might actually want something like:
event.currentTarget.parent.removeChild(event.currentTarget);
Which would remove the object that the touch event listener was added to.

Related Links

How to use a single script for multiple frames
As3 jumping collision issue
How to fix AS3 button?
Actionscript 3 jumping animation issue
Actionscript 3 Code Keeps Giving Error 1009
Horizontal collision issue with actionscript 3 flash
Actionscript 3 FileReference load/save strings
actionscript 3, removeEventListener not working properly
Ball bounce issue in AS3
Can I colorTransform a MovieClip but exclude specific sub-components?
Update text field into movie clip from main timeline code
how to reduce button click event code in AS3
Actionscript textField to BitmapData quality
ActionScript 3.0; looping audiofiles
AS3 - Dictionary objects allocated by a simple dictionary[key]=value call
Actionscript 3; how to make a toggle button?

Categories

HOME
grizzly
optimization
openacc
glsl
nagios
conceptual
google-docs-api
localhost
uml-designer
comments
flowtype
meson-build
minimax
olap
aws-sdk-cpp
point-of-sale
mongodb-replica-set
android-notifications
lambda-calculus
webseal
project-structure
hl7-fhir
summernote
ampscript
formulas
android-navigation-drawer
lotusscript
concatenation
devexpress-mvc
ppp
oracle10g
continuous-fourier
windows-mobile
traveling-salesman
uibarbuttonitem
units-of-measurement
undo
akamai
login-required
kubectl
circle
ilog
traitsui
dropdownbox
certbot
repeat
perf
iterm2
area
file-conversion
ocpjp
emacs24
boost-regex
opticalflow
multi-targeting
cc
nls
esprima
addressbook
android-tabs
easy68k
ldd
settext
xcode7.1
tinybox2
db2-zos
window.location
mod
pebble-js
chomsky-normal-form
std
nslocalizedstring
instabug
ewam
overlapping
android-contentresolver
ios8-share-extension
jcomponent
android-togglebutton
joomla3.3
callfire
litedb
eula
waterline
method-overloading
drools-guvnor
lwuit
formbuilder
system.net
ios-enterprise
cs193p
opencobol
mixradio
node-amqp
jfilechooser
infomaker
friendly-url
dynamic-expresso
cloudmade
generator-expression
tasklist
github-archive
pdf-reader
bash4
diazo
reflexil
httppostedfilebase
mismatch
file-processing
nscharacterset
dojox.gfx
cons
asp.net-1.1

Resources

Encrypt Message