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

Differentiate variables
Problems Scripting Multiple Buttons(nearly identical) in a single Action Script
AS3 “Error: Return value must be undefined”
How to make TextField gutter less?
why is only one actionscript working at a time?
On mouseover how to highlight an object's point so that I can draw connector from highlighted point
Access a integer variable through a separate Class
AS3 Remove Child to non public variable
Try to mask a textfield in actionscript
AS3 Pageflip effect: Page reversed when flipped
Bitmap graph drawing, how do you add thickness to a line?
AS3 not recognising MovieClips - 1046: Type was not found or was not a compile-time constant: MP_00
Unable read data from Socket
how to change background color of PopUp window in flex
Why is this method causing Flash to crash without even being called?
AS3 Facebook API: Access Token Error Message

Categories

HOME
alasql
ibm
boxplot
azure-resource-manager
arguments
coordinates
mingw
ebay
msbi
resharper
virtualenv
expo
reportlab
conditional-formatting
caldav
ng-tags-input
prepros
ps
windowserror
pypy
osgi-bundle
ds-5
ios9
edsdk
ios-autolayout
wercker
ports
gitosis
aweber
hippocms
azure-storage-files
libconfig
mybatis-generator
cowboy
superclass
gridgain
niagara-ax
togglebutton
spring-data-commons
react.rb
audio-fingerprinting
enet
overhead
printer-control-language
dynatable
node.js-client
sharing
disconnect
git-cherry-pick
sprockets
angularfire
nd4j
ideavim
dcast
fadein
gtkwave
event-tracking
random-sample
php-gd
eggplant
android-networking
genome
strcpy
qf-test
diffmerge
yosemite
nsnotificationcenter
javacompiler
dotcmis
amzi-prolog
ant-contrib
code-smell
farpoint-spread
nvcc
angularjs-select2
windows-scheduler
brew
libx264
freeimage
shapado
nude.js
reflexil
isgl3d
parallel-python
moss2007-security
browser-state
system-analysis
mysql-logic
dgml
mdd
ffdshow
bootstrap-protocol
expander

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App