ActionScript 3.0 :: _Deleting_ A Movieclip From Inside Its Own Class (not Using RemoveChild)?
Mar 7, 2009
I have started learning AS3 after a long stint doing work on AS2, and to test my abilities, I decided to make a quick breakout game. It has gone fine so far until I get to the part where I need to remove the bricks when they are hit. My current code for the class of a Brick is attached, and is started when a Brick is minstantiated on the Stage. However, when I use:
parent.removeChild(this);
it makes the Brick invisible but the AS3 code still runs and the ball bounces off where the moveiclip of the Brick used to be; the eventListener for ENTER_FRAME I added still runs even though I have deleted the MovieClip. This doesn't work either:
this = null;
I have to say I don't like the whole Garbage Collection idea of AS3; it seems half-hearted and uncontrollable; being a .NET developer I am used to more control than this. What was wrong with "this.removeMovieClip();" and how can I correct this? My current swf: http:[url]....(there are other things wrong, like bad collision detection,
View 3 Replies
Similar Posts:
May 3, 2011
I created two children from my document class "MainClass". One (hero) is of the class "HeroDo" and another is from the class "canDy".
Code:
public static var hero:HeroDo=new HeroDo
public static var blue:canDy=new canDy[code]....
...
Now the simple thing I want to do is to remove the "blue" child from within a function of the "hero" child and the hero child to remove itself from "its inside".I tried this, but it gives me an error. :C
Code:[code]...
View 6 Replies
Jul 24, 2009
I have a flash button that once clicked that adds an existing movie clip in my library to the stage. Basically what I am trying to achieve is like a popup window in flash so it opens a movieclip and then I have a close button inside the movieclip. Now what I want to achieve is to close the movieclip once I've added it to the stage.I'm trying to use the removechild but I'm getting errors e.g. The supplied DisplayObject must be a child of the caller.at flash.display::DisplayObjectContainer/removeChild()The way I add the movieclip to the stage is by using the following code:[code]
View 4 Replies
Feb 3, 2009
Ok, this is one of those walls that I know once I can jump over it, I will be a much happier developer again.
I've done tons of reading, and think I have a firm understanding that the general consensus is that if you want to reference something, it needs to be added to the display list, using addChild().
I hate to be defiant, but what if I don't want to?
Or at the very least, what if I want to add a movieclip class to the stage using addChild, and then reference objects inside it?
It is much easier this way than what most people recommend - adding 15 objects via addChild, then setting the x and y for the, etc.
That said, I'm all about using classes and using as3 the way it was meant to be used. So what this is, is a best practices question I guess.
HERE ARE THE STEPS I'M TRYING:
- Create new flash document
- Draw graphic symbol bg, with text field over it, select them, convert to movieclip symbol, and export class name "box", then delete it from stage
- Add document class .as file, which simply adds that class "box" from the library, to the display list using a simple addChild()
- Set a name for that box using box.name = "test" let's say
- Do a simple trace like the following - "getChildByName('test').textFieldName" - it shows up great
- So then, I'll now try to set the text by doing this - getChildByName('test').textFieldName.text = "yo";
That last line above, is what doesn't work. I know I'm referencing wrong, but how would a pro as3 developer, reference something on the stage within a movieclip class, from the document class?
View 1 Replies
Mar 29, 2009
I would like to be able to load in my mcs with class objects attached inside a different movieclip on the stage called game
currently i spawn my mc like this - vertex = new Ball(); -and it loads them to the stage, how can i load them into the game mc
I want to do this because i use a giant mc with my game inside to scale and move around to simulate zooming and panning of a camera
View 2 Replies
Nov 21, 2011
The attached SlideshowExample.as file works quite nice when I use it on stage directly. But when I tried to use it in Gallery_mc movie clip, it doesn't work
View 3 Replies
Nov 11, 2010
I'm just starting with as3 object oriented programming -- i've always liked the idea, but could never "see" how the whole objects/classes worked with actual game development.in my fla file i have this...
Actionscript Code:
var moveBob:MoveMan =new MoveMan()
in my MoveMan.as file...
Actionscript Code:
package { public class MoveMan { public function MoveMan() { bob.x = 5 } }}
and on the stage i have a movieclip with the name set as "bob" If i use this line in my fla file... bob.x = 100 it works.But when i try to move the movieclip inside the class i get this.1120: Access of undefined property
View 1 Replies
Feb 3, 2011
i'm trying to use compiled assets and code from a swc. Inside a new fla I select the swc to be included when exporting. When create the instance in the timeline of the code works and I can see assets that are inside the swc and trace a propertie from the same object. The problem is only when doing the same inside a movieclip, can't reach the assets (movieclip) but I can still trace properties from the class. I've uploaded the working files: master.fla is the one that creates the swc. template.fla is where I test the swc. files (This are cs4 .fla + .swc + .as)
[Code]....
View 2 Replies
Aug 17, 2009
I can't acces my MC that was created inside my class. 've got a MC "bttn" on my stage, if u create an instance of the BttnClass a copy of the MCbttn is made and given an other position, than I want to play the bttn's(contains multiple frames) and NOTHING happens. The Bttn's are copied,but I can't play them. So my class works but how can I play my buttons?
Class file:
ActionScript Code:
class Bttn {
//variables
private var num:Number
//constructor function
public function Bttn(i) {
[Code] .....
View 1 Replies
Dec 13, 2010
I'm making a sidescroller for school and im trying to get my hit test working.
I'm having trouble because I'm not sure how to properly reference an movie clip that i added in my game engine (zombie_mc), to a seperate class for my bullets the code for adding my zombie to the stage
Quote:
if (zombieTime < zombieLimit)
{
//if time hasn't reached the limit, then just increment
zombieTime++;
[Code]....
View 4 Replies
Jan 4, 2011
I have a movie clip symbol placed on the main timeline. The class linkage to that movie clip is Sheet. Inside Sheet class, I make a public string call _textRow. Inside the Sheet's constructor, I create a new TextField call values_txt. Inside the Sheet class again, I create a public function call updateTable().
The document class is Main. From the Main.as, I need to call updateTable() function to update the text inside values_txt. And I need to find a way to get to values_txt. That's where my problem lies.
Actionscript Code:
package{//imported stuff herepublic class Sheet extends MovieClip{public var _textRow:String = " Lorem
Lorem again";public function Sheet(){addEventListener(Event.ADDED_TO_STAGE, initSheet);}public function
[Code]....
Basically, I need to run Sheet's updateTable() from Main.as and update the values_txt.text with _textRow string. But I don't know value_txt's target path.
View 9 Replies
Jun 15, 2010
I have been trying to add a movieclip to my .fla file from a class.my main fla file: main.flaactionscript file: script.asthey stay in the same directory.script.as file as follows:
package {
import flash.display.*
public class MyClass extends MovieClip
[code]......
View 1 Replies
Jul 18, 2009
Is it possible to access properties from a movieclip on the stage from a class attached to another movieclip?[code]...
View 1 Replies
Jul 22, 2009
I'm using Flash CS3. Inside my document class, how can I create a child MovieClip that loads an image from a URL? what I did wrong? I tried changing the Main class to a Sprite, still not working.
[Code]....
View 2 Replies
Aug 11, 2009
I'm trying to reference the document class from inside a MovieClip that's dynamically added to the stage. I'm using this script:
Code:
documentClass(root).someVar;
Where "documentClass" is the name of my class (duh).
This works fine, however -- when I move the class file into a folder (and make all the necessary revisions to point to the file) this doesn't work (everything else still does). I get a "not found, possibly undefined method" error. The class name is technically com.documentClass now, how do I point to that? The file is an Adobe Air file.
View 5 Replies
Aug 7, 2011
How do I connect to the same class from the stage as well as from inside a MovieClip?
In other words: I've set a document class in my properties panel - I cannot access the class's methods from inside an MC. Why?
What are the different ways to connect a fla-file to a class (as-file)?
I've been playing around with AS3 for a few years now, but always avoided classes. But now the day has come for me to finally trying to get a hold of it.
View 1 Replies
Oct 8, 2011
I am making a game in Flash CS4 using AS3. This is the point. I have a MovieClip called Menu which holds a button with instance name ButPlay. Menu MovieClip is linked to Menu.as script. This is whats inside the Menu.as:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
[Code].....
When i run the animation i get the this error: TypeError: Error #1009: Cannot access a property or method of a null object reference. at Menu()
When i try to trace the ButPlay inside the Menu i get null object.
View 5 Replies
Jan 21, 2009
How do I reference to a Movieclip on the stage from inside a Class.as?
View 1 Replies
Apr 11, 2012
I want to turn my previous background in a platform game with his alpha as 0, so i tried this[code]...
View 14 Replies
Jan 7, 2011
there how can i use removeChild inside a SWF that i added in my timeline i mean ive got my swf i addChild it and inside the second SWF is a close button which i want to removeChild itself :S is there anyway to do that?:S
[Code]...
View 0 Replies
Nov 15, 2010
I've recently started using the cache as bitmap switch on my on-stage movieclips, to great success, while creating my isometric RPG. What I can't grasp though, is how to apply it to AS-instantiated classes/object.How can I turn on cacheAsBitmap inside a class that extends movieclip? Alternatively, how can I do it from outside the class, from another class that adds mentioned movieclip to the stage?
View 1 Replies
Mar 18, 2009
I'm trying to place an instance of a movieclip (instance name: tehMovieClip) from the library within another movieclip (instance name: parentMovieClip) on the stage. tehMovieClip, the movieclip going inside another movieclip, belongs to a class called CollisonDetection (linkage properties, class:CollisonDetection, Base Class: flash.display.MovieClip). When I put tehMovieClip inside parentMovieClip, I get this runtime error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
If I just place tehMovieClip on the stage by itself, it works fine but I need it to be inside parentMovieClip.
View 6 Replies
Oct 14, 2011
I created a movieclip symbol and exported to actionscript, I created the .as file:
class BRIQUE extends MovieClip
{
function BRIQUE()
{
[Code].....
"graphics" is an image imported on the stage inside my symbol, but it seems not to be accessible this way (I get an error), nevertheless it works this way in as3 then what is the right way in as2 ?
View 1 Replies
Sep 3, 2009
I have recently experienced problems with attempt to remove DisplayObjects that were placed at design time.I have some class "Locator" inherited from Sprite. Several instances of it are placed at the stage at design time.Locator constructor fills parent variables and tries to remove the instance itself from parent:
ActionScript Code:
public function Locator()
{
// give parent some important data
[code]....
All instances now process constructor, but only one of them processes event handler.
View 9 Replies
Nov 16, 2010
I'm having some trouble finishing an interface i'm working on,the function indica() adds a menu listing of items (indicadores) inside a mask because its too large, and i added a scrollbar that allows to scroll through the items but now i need to add the buttons inside the movie clip indicative,i can add symbols and buttons, but i'm having trouble having them call functions inside the same class that the function indica() is running.[code]
View 2 Replies
Mar 30, 2009
This is something I'm experimenting with, but haven't seemed to figure out... I have several MovieClips, basically the same, only different colors. As each one plays, I'd like it to "overlap" whichever one is already there. Right now I have each button linked to a gotoAndPlay function, but I don't think that will ever get me what I want. You can see how I have it now here: [URL]
Instead of having the content MovieClip go back to all white when a button is clicked, I'd like the preivious one to remain, and get "covered up" by the new one. You continue to see the old color, and the new color overlaps it. I have a feeling I need to use a variable and then addChild, with a removeChild for the old MovieClip after the new MovieClip has loaded, but I'm not getting any good results yet.
View 1 Replies
Jan 25, 2012
I have a Button that is inside MovieClip1 which is inside MovieClip2; yet when i click the Button it doesn't dispatch Event.
View 5 Replies
Feb 28, 2010
I have an external class added to the document when a menu is opened. When the menu is closed the function is removed.
But then the document tries to run onEnter function of the class, which references stage and I get the null error. How should I set it up so the document doesn't run the class after removeChild()?
[Code]....
View 5 Replies
Jul 10, 2009
I wanted to create a class that you send a display object to and it tweens out (lets just say fades out for now), and then removes it from it's parent, and nulls it. So this is what I came up with:
Code:
package com.TweenOut{
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
[code]...
but, i'm getting this error.. TypeError: Error #1034: Type Coercion failed: cannot convert com.Pages:esignPage@2786f9d1 to com.TweenOut.TweenKill.So, obviously it can't convert _livePage.. but.. am I misunderstanding the error, is it trying to convert it to com.TweenOut.TweenKill, or is it just not able to convert it to a DisplayObject like I assume??
Also, I should note that _livePage is a subclass of a custom class I wrote, and that class is a subclass of MovieClip.. Doesn't that mean that _livePage would be a DisplayObject? Does this have to do with calling the super() in either of those super classes?
I'm making great headway into understanding all of this as3 stuff, but some things still get me. I'm having trouble understanding the big picture, I feel like there has to be a better way to handle "page changes" or "section changes". For instance, am I doing it a weird way by making a class that tweens out anything I send to it? Should I just be doing the tween and removal inside the class that the DisplayObject is a child of?
View 6 Replies
Jul 23, 2009
I'm working on a game where I'm adding a symbol (an enemy unit) from the Library via addChild() to an instance on the Stage. The symbol has Linkage/Class enabled so I can stick stat variables directly on it for easy access.The problem is that I want to use the same name for enemies (like en0, en1) in different areas, but if I try to removeChild(), I get Error 1067: Implicit coercion of type Class to type DisplayObject.
View 1 Replies