ActionScript 3.0 :: Referencing Stage - Add Bullets To The Stage Rather Than Using Parent.parent.parent.addChild?
Jul 10, 2009
I'm currently making a platform game and when the player shoots i want to add the bullets to the stage. The players gun class is in charge of adding bullets. The "players gun" is a child of "players gun holder" which is a child of "player" which is a child of the stage. is there a better or more dynamic way for the "players gun" to add bullets to the stage rather than using parent.parent.parent.addChild (bullet);
View 2 Replies
Similar Posts:
Sep 11, 2010
if I add a clip to the stage as a child and remove the parent and set the parent equal to null, does the child get collected and removed from memory? What if the child has an image loaded into it as its child?
In my application I'm loading a series of png images as overlays that can be tinted for customizing in this app. When I trace my memory, the basic app idles at 64,000 k. The exact second I load those overlay images it goes up to 205,000k. If I remove those clips and "clear" the stage I should go back down to 64,000 k if everything is removed and collected correctly, right? It's not, it's hanging at 215,000 k. Are my images being cached and that is the reason for the memory staying up? If so, how do I prevent that. Or upon removing the parent of the image how can I un-cache the image.
If a user switches between models and loads several different items then the application actually crashes the Flash environment because of too much memory usage. It also does the same to browsers.
View 29 Replies
Oct 11, 2010
I would like to know the way to prevent a child swf from referencing its parent swf stage width/height?
for example, i created a child swf that loads image and center it on it's stage. As a stand alone its fine but i loaded it with parent swf, it centers on the parent swf instead.
View 3 Replies
Jun 6, 2011
i am slightly confused about the parent and child relationship. lets assume we have several different instances, what would be difference of adding them all as children of the stage and creating a parent-child hierarchy between them(other than the access path).
View 5 Replies
Sep 30, 2011
I'm working on a spider solitaire game and I need a way to bring cards out of their parent column and on to the main stage when they are selected. Here's my current code:
[Code]...
However, the above gives me an error on the stage.addChild line. "1118: Implicit coercion of a value with static type Object to a possible unrelated type flash.display: DisplayObject."
View 1 Replies
Feb 5, 2010
[code]All clips are squared.Ok, on the PlayerPlane, there are little soldiers, which have hotkeys. The effect I'm trying to create is I want to position the GameStage so that the currently selected soldier appears in the center of the GameClicker clip.The GameStage is movable by the player (to scan other areas of the map)by holding the CTRL key, so it's easy to kinda lose track of where your players are.I have tried using localTo Global and globalToLocal techniques, but I think I'm lost on the actual math of getting the GameStage to move the correct distance so that the selected soldier is centered to the GameClicker.[code]
View 2 Replies
Jan 3, 2010
I got a "preloader" that creates an movieclip and loads an SWF. Now in the loaded SWF i want a close button to go back to the "preloader". The preloader isn't an actuall preloader but some sort of mainclip.Now i tried this:removeChild(MovieClip(e.currentTarget).parent.pare nt.parent)But i get error:ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.at flash.display::DisplayObjectContainer/removeChild()at MethodInfo-6()
View 1 Replies
Mar 15, 2011
I am trying to access a function that is on my document class for my AS3 project, from a nested class. That is, the Document Class calls Class A which then calls Class B. So I am trying to access a function from Class B, I am trying to use MovieClip(parent).function(); but I am getting error 1120. The MovieClip(parent) (fixed to reflect my document class, etc) works when I try it from other classes but not from this nested class.
View 9 Replies
Nov 13, 2010
Simple drag and drop application where mc is dragged out of one parent mc and dropped into another parent mc.All works OK until I added 2 text boxes to the mc's -- one is a non-selectable dynamic text box (a label) which is set by the code, the other is selectable input text that the user can amend.
Finger cursor disappears when user hovers over the section of the mc that contains the text fields (even non-selectable text??) When the user trys to drag the mc by inadvertantly click-dragging anywhere within both text areas it causes this error: TypeError: Error #1034: Type Coercion failed: cannot convert flash.text::TextField@2374a381 to flash.display. MovieClip (same error appears for both text boxes)
The input text box may confuse the user - how do they sometimes click to drag and sometimes click to amend? I need to create an overlay area within the mc that is click-detected for the drag? Here's the relevant bits of code:
var itemArray:Array = [
{iname:"police",ititle:"POLICE OFFICER"},
{iname:"insurance_assessor",ititle:"INSURANCE ASSESSOR"},[code].............
View 1 Replies
Nov 11, 2009
I have a parent swf which loads many child swfs (though only one is displayed at a time). My intention was to use the loaded SWFs document class to retrieve an array of objects to be assigned a tab index, combine this with the parent's own array of objects and apply sequential tab indices to them all. But what happens is actually that the parent's objects are assigned an index, but the external swf is unaffected. In fact, the external swf retains its automatic tab indexing, when I would expect that having set a value for InteractiveObject.tabIndex, automatic tab indexing would be disabled.
I've seen similar tales elsewhere. Most posts I've read are wanting to load an external swf, give it focus and loop through those objects, then close the swf and return to looping through the parent. However I would like loop through all objects as one. including manipulating the focus manager(s), and basically fiddling with every tab-related property I know.
View 2 Replies
Dec 10, 2009
I've struggled with this for a long time and have thrown in the towel. How the heck do you climb the ladder, then go back down again into another clip?
View 2 Replies
Jun 2, 2011
I have been using:
yourbutton.addEventListener(MouseEvent.CLICK,f);
function f(e:Event):void{
Loader(this.parent).load(new URLRequest("newswf.swf"));
}
which was suggested to me in a different post to target the parent loader class, however i now no longer can reference my preloader in the parent swf (extract from the parent swf):
[Code]...
View 5 Replies
May 12, 2010
I know about Flash's localToGlobal and globalToLocal methods to transform coordinates from the local system to the global system, but is there a way to achieve the intermediate? To transform coordinates from an arbitrary system to any other arbitrary system?
I have a clickable object inside a Sprite, and the Sprite is a child of the stage. I want to retrieve the clicked point in the Sprite.
View 2 Replies
Feb 13, 2010
i have a swf (child swf) which is loaded into another swf (parent swf). I want the child swf to know the stage.width of the parent swf. If I trace "_parent.stage.width." I get output undefined. Is there a way to do this?
View 3 Replies
Jun 17, 2009
I have a loaded SWF into a simple "holder" empty movieclip I have on the root stage. Inside that SWF I have two variables that have "stage.stage Height" and "stage.stageWidth" in them. If I leave them on the code and test the root movie I get this error: TypeError: Error #1009: Cannot access a property or method of a null object reference.So basically I can't seem to get the variables to get the parent stage. Anyway to get around that?
View 2 Replies
Aug 8, 2009
is it possible to get the x of a child equal to the stage.x instead of its parent.x?
View 2 Replies
Aug 14, 2011
I have a loadedSwf that i loaded into my mainSwf. I'm trying to do some aligning with some objects in my loadedSwf file, but they're only referencing the stage of the loadedSwf so the alignment is off. Is there a way to refer to the stage of the mainSwf? I tried using parent that didn't seem to work. All the searches i found were aligning to the loadedSwf which isn't quite what i want.
View 7 Replies
Sep 29, 2011
trying to on mouse over set the parent of the moused over text field to the highest depth child of its parent i tried both of these: [code] private function
[Code]...
View 3 Replies
Nov 7, 2011
i want to pass the variable from parent to child .How Can i pass the Variable.Here i paste my code.
My Parent Class
public class PlayerStrobe_domaincheck extends Sprite
{
private var myService:NetConnection = new NetConnection();
private var _loader:Loader;
[Code]....
View 3 Replies
Dec 19, 2010
Is there a way to tell flash to instantiate a Stage subclass called "TheStage" instead of the default Stage class as root/parent of my document class?
public class TheStage extends Stage{
//code
}
Then when I do "DisplayObject.stage" I want it to return the instance of TheStage instead of the default Stage insteance. I want to do this so that I can override the addEventListener method of the Stage class. So if I call DisplayObject.stage.addEventListener I can execute my own code routine. Is that possible and how?
View 8 Replies
Feb 1, 2011
How do I get a list of all the children (Sprites) on the stage of my Document Class OR how can I get a list (length) of all the children (Sprites) of a parent (Sprite)?
View 1 Replies
Jul 10, 2009
is there a way to override a MovieClip's parent and stage properties? In a custom class extending the MovieClip class we can override the get parent() and get stage() methods. But is there a way to do it to existing MovieClip?
I mean I have an external swf content (loaded) and assigned to a movieClip. But now, how can I assign the loaded MovieClip to my custom class, so that it "doesn't see" the parent and stage properties?
Or can I override functions of existing classes? Sth like:
override public function myMovieClip["get parent"]():DisplayObjectContainer
{
...
}
I just need to prevent a loaded MovieClip from having access to the main movie's stage.
View 3 Replies
Nov 12, 2009
I'm having an issue where I am placing a timer inside of a MovieClip instance which is dynamically placed on stage. When I remove the MovieClip from the stage, the timer keeps on running. It is sometimes a bit complicated to be able to stop all the timers inside of this MovieClip so I was wondering if there was a way to either destroy the MovieClip instance and thus destroy the timers within it? or how could I go about making sure the timers stop when their parent Object is not on stage.
View 2 Replies
Feb 24, 2010
I am executing the lightbox functionality from a swf file that is loaded by a parent swf. For testing purposes, when the lightbox button is clicked, the image should fill the entire stage. Even though both the loaded swf and the parent swf recognize the same stage dimensions at all times(validated through tracing statements) and the lightbox image is positioned to the top/left corner of the stage, the image instead aligns to the top/left corner of the loaded swf. And if the stage is resized after the lightbox image is displayed, the container MC (which is located in the parent swf and centers all the sites content) re-aligns to the top/left corner of the stage .[code]...
View 1 Replies
Jul 22, 2010
I've been working on an interactive map of the counties in Montana. When a user clicks on a county, I'd like the map to zoom to the county's extent and center it on the stage. Every county is a child of a larger container (the state, names allcnt_mc). I've set things up in my function so that when you click on a county POINT variables with all the numbers you need are created. I just cannot get the desired effect and I think I am missing something basic in regards to the geometry of my stage. Can anyone see something I am missing? I set this up so that the parent is tweened to a new location equal to stage center minus the called child's x,y distance from stage center. Essentially, this should center the child over the stage center, no?
function tweenparent(e:MouseEvent):void{
//create vars for x,y cordinates of clicked county (child)
var calledx:Number=allcnt_mc[xmlData.row.NAME[e.currentTarget.ivar]].x;
[Code]....
View 9 Replies
Dec 1, 2011
Why do I get this error saying parent does not exist when I try to remove a movieclip. In the first case, the movieclip cannot exist either on screen/memory if it was not 'contained' by either a movieclip or stage. How can this happen, can somebody explain how this "movieclip" loses its parent reference to the stage or container mc. The debugger stack shows the value of movieclip.parent as null.
View 2 Replies
Mar 16, 2010
I cannot use the following in my ActionScript due to conflicts with the host application:
_level0
_root
_parent references
On a pop-up box I have a close button with an absolute reference: closeBtn.onRelease = function{ unloadMovie("_level0.Page_1.holderBox");} Is there another way to make this work without using _level0 or _parent? I've read that it is possible to use a global variable on the main timeline and ref that, but cannot get that to work.
View 7 Replies
Aug 24, 2010
I am trying to make a calculator where a user can select from a list of items. If a user clicks say "ITEM1", it should add the item to a "CONTAINER_MC". The problem i have is all my data is set inside an array containing names and prices like the code below.
[Code]...
View 1 Replies
Oct 6, 2010
Here is a working script to drag drop a ball from the stage into another target mc:
ball.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
stage.addEventListener(MouseEvent.MOUSE_UP, dropIt);
function pickUp(event:MouseEvent):void{ [code]...
It works well but I'm new to AS3 and I am having difficulty amending this script to drag the ball out of a parent mc (instead of the stage) and onto another mc (the target mc). To explain: imagine a ball, a box, a tri, + more shapes all within a scrolling mc (initial parent), the user scrolls to select a shape, then drag-drops onto a target mc on the stage.The scrolling is no problem, but how would you amend the script above so that the ball can start inside a parent mc rather than on the stage itself?
View 2 Replies
Sep 15, 2009
I want to place an object either directly on stage or in some other movieClip but I need to read parent height to align it properly from the bottom.I thought I could use this and it will work for both the stage and the movieClip and I could get away with one line of code:
Code:
trace(parent);
//[Object Stage]
trace(parent.height);
but this doesnt work for stage, I need to use this:
Code:
trace(parent.stageHeight);
which is the same as this: so obviusly I need to ask first whether the parent is the stage, so I can find the height...So what is parent.height actually outputting?
View 1 Replies