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

Only see what is inside the bounds of a container in Flash AS3?
Attempting to start a tween returns a null object reference
How to cast a JSON DateTime to actionscript3?
AS3 removing all children from array in a class from parent class
Sending Ready Signal through Socket in flex
as3 how to trace which movieclip is dispatching event
AS3 enemies double speed?
photo load order mess up as3
Layer objects in Flash with their own buttons to pull the object up and lay on top of the prior. How do I setup the Action Script 3?
AS3 Using a variable inside removeChild to remove currentLevel
Playing & Stopping SWF file trough a movie clip
Other ways of counting number of keywords in a complex string
Wrong data in custom LabelItemRenderer
Adobe AIR AS3 - Front facing camera
AS3 MouseEvent.CLICK Interaction on Different Indexes
Why is inheriting from Event not working in this case?

Categories

HOME
asterisk
qlikview
gulp
repository
stata
intellij-idea
pyspark
cluster-analysis
jenkins-pipeline
ldap
aix
richtextbox
schema
apache-httpclient-4.x
repeater
infopath
template10
simd
cherrypy
serenity-js
dev-c++
typedef
multipart
opengraph
tcpdf
rancher
expressionengine
formtastic
launchd
jbossfuse
ios9
wordpress-rest-api
visual-studio-debugging
machine-code
angularjs-resource
pymunk
sdl-2
motherboard
device-driver
area
wicket-tester
vertical-alignment
android-graphview
autodesk-data-management
codepen
risc
serverless-architecture
geminabox
dcom
skype-bots
playframework-2.3
htop
android-vectordrawable
zedgraph
trusted-computing
cardview
ldd
visual-web-developer
csc
laterjs
archiva
mod
periodic-processing
wizard
ooad
sqldataadapter
opendolphin
windows-kernel
musicbrainz
tess4j
litedb
asp.net-2.0
firebase-tools
dojox.grid
uiblureffect
breeze-sharp
vundle
oxygenxml
fscanf
serializer
winrun4j
code-smell
pidgin
infor-eam
kernel-density
mixradio
php-amqplib
xml-validation
grape-api
tlbimp
google-checkout
symbian3
junction-table
gssapi
motordriver
big-endian
mvcmailer
parsec
commonsware
datejs
apache-commons-email
netduino
lgpl
qprocess
dynamic-scope
dojox.gfx
data-formats
retrospectiva
djangoappengine
projectgen
j++
moores-law
ironpython-studio

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App