ActionScript 3.0 :: Can't Add Children To The Stage Via A Class
Jun 3, 2009I am trying to addChild(displayObject) via a class, and nothing appears when I add it to the stage.
[Code].....
I am trying to addChild(displayObject) via a class, and nothing appears when I add it to the stage.
[Code].....
I'm slightly new to Flash CS3 + AS3 combo, so its more of a lack of practice question. My question stems from the problem described here http:[url].... . Note, its not the same problem, its a new one.The Problem ,So I have multiple library assets (which are on teh stage) and I want to assign similar functionality to all of them.
Attempt 1: So I create the n assets, create a custom class in AS3, link them to Flash CS3 and obviously enough it gives me the error that multiple assets can't be linked to the same class.Obvious enough to understand (well not completely, because from a programmers background it doesn't make sense).
Attempt 2: Same as attempt 1, but instead of linking all the assets to the same class I make the base class the same class, and let the derived class be dynamically created by Flash on compile time.So the linking works, but the problem is, in my base class I have a method which does something (say an tween) on a child of the library asset. So if the assets on the stage/library are called asset1, asset2, asset3 (same name for asset name, class name, id name), each of them has a sub-movieclip called ... say 'foo'. now if I manually wrote a class for each asset, I could do 'this.foo' to play with the sub-movieclip. However since this functionality is in the parent class, I'm unable to do it.
P.S. If you're form a programming/OOP background, its basically a abstract class problem. My Base class knows how to doSomething(), but it needs aSomething, which is defined in the Derived classes. However I found out that AS3 classes don't support virtual(C++ )/abstract (Java) in the true sense of the word (unless I missed some obvious documentation).
I have a class called shapeC that only creates a rectangle and then addChild(rectangle);. That class is instantiated on the main timeline. Currently, the only way you can see that rectangle is to add the instantiated class to the stage via addChild(shapeC);. My question is, is there a way that the shapeC class can add the rectangle to the root stage without requireing the instantiated class to be added to the stage?
View 4 RepliesI'm making a OSX-finder-type file browser in CS4.The Structure for the folder and files is being generated by a PHP in a XML, heres an example:(sorry the xml is not sorted, but the command i'm using in php doesn't sort it)
Code:
<root>
<dir name="images">
[code]....
I have two symbols. player and wall. The player symbol has a custom made class.For some reason a player object on the stage is a child of the stage but the wall objects are not. Why are the wall objects not children of the stage?
View 3 Repliesim making a game and it has enemies randomly spawning at the top of the screen going down to the bottom, so far it all works fine, except for when i try to remove the enemies I get this erro.[code]
View 1 RepliesI'm doing a simple navigational menu and the idea is that when you rollover certain buttons, a linked movie clip appears in a certain spot and any other linked movie clips disappear off the stage. I heard about a bug with AS3 in CS4 and tried the following method but it's not working. All the movie clips stay on the stage. Nothing disappears. Where am I screwing up?
[Code]...
I have been using a lot of swapChildren, setChildIndex,addChild, removeChild on stage and also a lot switching children when buttons rollover and rollout. I want to know is there a method to trace or keep track of all the depth of children in the output panel??
View 2 Replieswhat could I write to display how many/what children are on stage and it be displayed in the output window in a trace statement?
View 3 RepliesHow 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 RepliesWhat I'm trying to do is just iterate through stage children and trace out what the child is and the index. Here is some code.the problem area seems to be the actual recurseStage() call at the end. As well as the if statement before that. I know not all children will have the property .numChildren but I'm not sure what to use instead. This should be an easy fix but my brain just isn't helping me out right now.
View 1 RepliesI added children to the stage on frame 1, however they still exist on frame 2 even though there is no code there. Can I erase the stage? Or do I have to throw every object into an array and use removeChild in a loop?
View 2 RepliesI am creating an AIR nativeWindow. I am adding two children, an HTMLLoader and a Sprite. The child Sprite has two children, a TextField and a Sprite that will be used to draw. I have set stage.scaleMode = "noScale" and stage.align = "TL", which the HTMLLoader seems to respect. However, the child Sprite scales its children whenever I set a height.
public function BaseWindow(){
var winInit:NativeWindowInitOptions = new NativeWindowInitOptions();
winInit.type = NativeWindowType.NORMAL;[code]..........
How do I prevent the distractor Sprite from scaling its children?
I am trying to trace stage.name in child view after addChild:
import flash.events.Event;
import flash.text.TextField;
public class TestView extends TextField {
[code].....
I am trying to add children to a dynamically added swf file, using AS3, before I add it to stage
Here is the code I have thus far,
AS3:
var mLoader:Loader = new Loader();
var mRequest:URLRequest = new URLRequest(glo.bal.base_url+"videos/vid_1.swf");
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler_one);
mLoader.load(mRequest);
[Code].....
Inside the vid_1 swf there is a movie clip called box_one, I would like to append a image to box_one, and only have the swf added to stage after the image file has been added to box_one.
I am working in on a Flex / Air application (using PureMVC) written virtually entirely in ActionScript 3 (i.e. we use very little of Flex). View components are added to a Canvas object in the main application window and these Views then load other movie clips, images files, etc.When I remove a View from the stage, I do so using application.canvas.removeChild(). This fires an event in my PureMVC mediator for that View, which removes any event listeners that were set up and everything appears to be dandy.However, the movie clips are still playing in the background. They are not causing any trouble on screen but they are simply there, playing somewhere in memory (e.g. I can see trace statements from them) and I want them gone. I suspect the View that was removed from the Canvas is still there too, but I can't prove it.
Setting the View to null doesn't do anything. I'm surprised that AS3 doesn't include any method to simply and effectively destroy a Display Object and all of its children.Is the only way to do this to tediously unload all of the movie clips, etc. and then hope that Flash will clean them up?
I have 9 movie clips which are all of the same object, they get larger or smaller as the mouse gets closer to their respective centers. The functionalilty for this is in an AS3 class file that extends flash.display.MovieClip.How do I go about swapping depths so that the largest one is in the foreground, I am new to AS3 and dont seem to be able to find a way of getting the depth of the movieclip I am currently inside (this) and if I try to access the stage to call swapChildren I get the following runtime error:
View 6 Repliesjust thinking out the setup of a sidescroll/platformer..i want the player not to fall through the floor or go through walls i know how to hittest with a single object, but what i have is various objects that extend the class wall. if I hittest with wall will that also apply to the serrated_floor and portcullis classes that extend wall?
View 1 RepliesI have 2 swf files. One is loaded and loading an externally loaded swf into it.Here is the code in the first loaded swf: #1
var logo:Loader = new Loader();
logo.load(new URLRequest("images/Logo.png"));
logo.contentLoaderInfo.addEventListener(Event.COMPLETE, LoadLogo);
function LoadLogo(e:Event):void
[code]....
EDIT:I am having major SANDBOX issues now when I make the clip load from an external URL. I am also coding for an ANDROID using FLASH CS5.5. Its not allowing me to use Security.allowDomain("*");
For this example, I will use 2 classes, Entity and CSpawner. CSpawner is a children of Entity.I want to perform the following condition:if((new CSpawner()) is Entity)It works just like intended.But I want to do this test, without creating a new CSpawner object, something like this:if(CSpawner is Entity)But it doesn't work, because CSpawner is a Class.How do I perform that kind of conditional without creating a new CSpawner object?
View 2 RepliesSprites, Shapes and MovieClips added as children of the main class just aren't visible. There's no error message at compiletime, no error message at runtime, everything seems to work perfectly except that the child (and its children, whatever they happen to be) just doesn't manifest on the screen. It might be worth noting that not all DisplayObjects have this problem. Bitmaps and TextFields, for instance, both show up perfectly.
If it matters, I'm running Flash Player 10 on 32-bit Windows Vista, compiling using Flex 4 with a command line instruction of the following form:
"mxmlc.exe" -as3 -static-link-runtime-shared-libraries=true -target-player "10" whatever.as
I've already tried basically all the obvious tests I can think of to narrow down the problem. Aside from the object being invisible and apparently not responding to mouse clicks, everything works exactly as expected.
I have a class, called fCont (I know, I should use capital letters for class names... oh well), and I need to remove all instances of it from my MovieClip.I'm making a Facebook browser for a uni assignment. When you go to the Friends page, it loads 15 friends, and that's fine. The code below is called on the "Next Page" button press.
Code:
function nextFriendsPage(e:Event){
var friendFace:Object = stage.getChildAt(0);
[code].....
I am dynamically creating a UI component based on XML templates stored in database. Now I want to access one of the child component of this UIComponent Class. I dont see any children property in this class? How could I possibly traverse through each child comppnent of this class and set its properties according to some logic in code(which I could not do in templates itself).
[Code]...
I am trying to find out why when I place trace(parent); in the timeline of my child swf I get [object Loader]but if i place trace(parent); in the constructor of the child swf's document lcass I get null.Why is this and how would I access the parent swf from the child document class if it shows as null?
View 2 RepliesI have a class which loads images for one photoalbum category
Code:
dynamic public class Submenu extends flash.display.MovieClip
{
[code]......
In this game attached I need the old Children (rats) to hurt the character when he walks into them, however only the most recently added Child is active in that way... also the rats seem to appear above the character instead of below, is there any way to resolve these issues??
View 4 RepliesI have a Sprite called pageContent. Inside pageContent are 12 more Sprites with unique names, a couple of Buttons, and some TextFields. Inside each of the 12 Sprites I have either one or two TextFields and one TextInput. My question is, since they are children inside a child of pageContent, how can I access them? Here is how I am trying to do it:
[Code]...
In my mind, this should totally work. But surprise, surprise, it doesn't. I have debugged it and it works fine for the first two lines, but when it tries to get numChildren of a Child of pageContent (line 3), I get this error: PHP Code: 1119: Access of possibly undefined property numChildren through a reference with static type flash.display:DisplayObject.
can you tell me a simple and clean way to pass the dimension of the stage to another class, imported in my documentclass?
View 2 RepliesI want to have a rollover effect of a movieclip (mo1) inside a movieclip (mo) of another movieclip (popup1).Is it possible to do that? I try calling it using this code in the frame 1 of my flash, am i doing wrongly?
Code:
popup1.mo.mo1.onRollOver = function() {
popup1.mo.mo1.gotoAndStop(2);
[code]......
Is there a way I can reference a Movie clip I have on the main stage from a custom class of a document class?[code]
View 1 Replies