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 test flash cs5 app on the iPad
How can I pass parameters from a web application (JSP) to a Flex application (mxml file)
Not able to Embed images in Flex action script
TCP Socket frames 'queuing' up on Windows. How can I force each message in it's own frame?
How can I break down a view in a flex application?
Add a % sign and color it
Error #1010 (Probably an object error)
OSMF Playing Event
as3 error says “Stream Error”, but when loaded manually it's there
How to load an image in memory with Flex/ActionScript?
Check if Class Implements a Specific Interface
Scrollbar-Button jitters when reaching maximum/minimum
Can a Flex-based project be released under the GPL v2? [closed]
Read Text File with AS3 and Tween Each Word from Small to Large out of the screen
Flex button script
AS3 button firing off multiple times if clicked fast only

Categories

HOME
redux
primefaces
android-ndk
lithium
crash
opc-ua
overrides
mingw
localhost
confluence-rest-api
soap-client
velocity
urllib2
opendaylight
react-select
owncloud
pylint
template10
views
scotty
keystone
restructuredtext
multipart
hololens
windowserror
akavache
cloudformation
typeclass
csproj
folder
edsdk
wordpress-rest-api
visual-prolog
wunderground
certbot
repeat
border-layout
maven-2
julia-jump
office-interop
keychain
rbac
sknode
wicket-tester
g77
enet
playframework-1.x
selection-sort
liferay-ide
opticalflow
huawei
easy68k
indoor-positioning-system
jira-agile
hfp
db2-zos
wizard
video-embedding
alchemy
skbio
markerspiderfier
wonderware
imageicon
updating
web-standards
page-refresh
tidesdk
crtdbg.h
qxorm
pysvn
jsonmodel
os.walk
lwuit
telerik-appbuilder
banana-pi
netbeans-plugins
mobile-robots
zend-db-table
usersettings
stringstream
qmainwindow
urlfetch
cryptarithmetic-puzzle
scsf
wdm
digg
backlight
opendir
jexcelapi
service-layer
browser-state
dgml
lts
coderush-xpress
weak-typing

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