ActionScript 3.0 :: AddChild Function In Another Class?
May 13, 2011
I am trying to pull a funtion that adds a child to a container. This function gets pulled in another class. All the traces do work by the child doesn't show.
pulling the function from StickerBook_Class
---------------------------------------------------------------------- -----
public static var stickBook_Class:StickerBook_Class = new StickerBook_Class ;
how can I change the txtField.text without using the addChild function in the main class?? because the Content Class is already visible when you compile it.. and when I remove the that addChild function, the txtField.text is still in its default value which is "Lorem Ipsum"
I'm trying to have a class file which can add objects to the stage via addChild; however, when I call addChild from within the class file, I get the error "1180: Call to a possibly undefined method addChild." I've tried importing flash.display.* and that doesn't fix the problem. Does the class file have to extend Sprite or MovieClip to be able to add objects to the stage?
I have downloaded Box2d ([URL]) and created a project that looks like this: [URL]. catalyst is the green cube and it has the base class "shapes.box", it is inside "world" which has the base class "wck.World". What i want to do is to add another "catalyst" from the library inside "world" when i click on add_btn. I tried to accomplish this by this code:
[Code]...
Symbol 'buttons', Layer 'Actions', Frame 1, Line 41061: Call to a possibly undefined method addChild through a reference with static type Class.
I have an FLA in which there are a number of MovieClips in its library. I also have a document class for this FLA, which I will refer to as Body.as from here out.From Body.as, I call other classes designed to put stuff together and allow for organization due to large amount of MCs I have to use in the FLA. For reference, these classes are called as such: Head.as, Chest.as, Arms.as, etc etc.Now, where Body.as is the document class, and is therefore functioning to operate all areas in the FLA, I wanted to use these additional class files to be used to manage anything related to them, including any MCs I have. I'll use Head.as for explaining. To that end, I have four MCs, each named as follows:hat1hat2hathat4s part of trying to organize it all, I want to be able to call a singular function in Head.as that will retrieve these MovieClips and add them to the stage (Or, as I hope to do once I get a bit further in, add them to a larger MC that will then be added to the stage).
i want to add to stage a movieclip in another class not the .as file as the same name of .fla file how can i get this.When i run same code in main.as i get the result but in another class it runs but no result.
When I do this there are no errors, but the 'addChild' function is not working. if I put the addChild function in the Main.as then everything works just fine. So my question is: How can I Let the addChild function work from another class then the main class.
Works great until I try to addChild to that textField from either Frame 1 or the class itself. I can trace it perfectly, trace the class, trace the functions, trace everything in the functions but I can not addChild.
I would like to create a function that adds a child to whatever mc i choose like this where targetMc is the mc that i want the child (libraryMc) to be added to
PHP Code:
functionName(targetMc,libraryMc);
so right now my function looks like this
PHP Code:
function functionName(targetMc:MovieClip,libraryMc:MovieClip):void { var libContent:libraryMc = new libraryMc(); targetMc.addChild(libContent); }
i know this is wrong as new libraryMc() is also being replaced with the libraryMc:MovieClip and that is probably why it's not working.
I think maybe I need to import something else? because I am getting the following error.TypeError: Error #1006: addChild is not a function.at Function/<anonymous>
I have some problems working with "static function"For example:
Code: Select all public static var someText:TextField = new TextField(); public static var FORMAT:TextFormat = new TextFormat("Arial", 12, 0x000000); public static function myText():void
I have this class called AD. Its attached to my stage. AD then calls a class file called setupBoxes.
setupBoxes sets up a box using box2d (which has nothing to do with my question so dont stop reading here), attaches a movieclip to it, and attempts to "addChild". No errors, but no results.The thing is, in setupBoxes i even tryed using this code which i found on another forum.
PHP Code:
improt AD; //creation of class and brakets and things. public static var ad:AD; //long box2d and setup process and more brackets... ad.addChild(container);
For a school assignment I'm making a panorama version of my own room using a cube with 6 pictures in it. It created the panorama, it works great.But now I want to add clickable objects in it. One of the requirements is that my code is OOP focused. So that's what I am trying right now.
Currently I got two classes
- Main.as (Here i make the panorama cube as the room)
- photoWall.as (Here I want to create my first clickable object)
Now my problem is: I want to addChild a clickable object from photoWall.as to my panorama room. But he doesn't show it? I think it has something to do with the scenes. I use a new scene in Main.as and in photoWall.as. No errors or warnings are reported This is the piece in photoWall.as were I want to addChild my object (photoList):
private function portret():void { //defining my material for the clickable portret var material : BitmapFileMaterial = new BitmapFileMaterial('images/room.jpg');
I am trying to add an object to my main stage via the addChild() method. Normally, when working within the FLA itself, using addChild(myObject) works just fine. However, it does not work within an external AS class.
All of the other tutorials I have found showed me how to do something like this, which is not what I need:
var myMovieClip:MovieClip = new MovieClip(); myMovieClip.addChild(myObject); // Works great, but not what I need
how to add an object to my main stage via an external AS class.
Code: var rockSpawn:rock; function doCollision():void { trace("collision detected at "+collisionLoc+", Time: "+flash.utils.getTimer()); rockSpawn = new rock;
[code]....
This function spawns a rock object from the library at a given location, and then moves it to the right every frame until it reaches the edge of the screen, at which point it's deleted. The problem: when a rock is spawned, it moves to the right, but when a new rock is spawned, the previous one stops dead. Each rock moves progressively faster, as if each rockSpawn.x++ is stacking to make the object move 1 pixel faster each time the function is called.
How would I modify this code to spawn separate instances of a projectile that behave the same? Also, how would I reference them for say, collision detection? That is:
Code: if (a rockSpawn instance collides with the movieClip ship) { do stuff; }
lets say i have document class 1 that loads class a and class b to the stage. I have a button in class a, that when clicked it should addChild to the mc governed by class b.... is this possible?
I have an array of a custom class. The class includes 3 movieclips that all share the same position. I have 5 items in the array, and in the document constructor I fill them as such:
ActionScript Code: glassArray[0] = new glasses(spot, beam1, glasses2, "index/nav/aboutus", new Point(156, 400));(different string and point for each of the 5 items)
Here's the glasses constructor: ActionScript Code: public class glasses extends MovieClip{ //I am the Constructor. public var spot:MovieClip; public var beam:MovieClip; public var glass:MovieClip; protected var target:String; [Code] .....
It then goes on to fill each of those mclips with properties based on the point received. How to addchild from the class, I've got a simple for loop in the document constructor that adds them all in. Everything works, except what I'm seeing is that as each item in the array is added in, it overwrites the previous items' properties. In effect, I can create 5 items and give them each a different position, but when I go to addChild I see that all of them have taken on the position of the 5th one.!
I can't do many simple things in AS3 that take 1 second to do in AS2,
All I want to do is attach a movieclip to the stage via a .as file that ISNT the document class.
So for examples sake lets say I have Main.swf - Main swf file with a movieclip called "PreloaderGUI". Main.as - The document class, this loads Preloader.as. Preloader.as - This preloads the movie and attaches PreloaderGUI.
I'm working on a Flash Lite 3.0 application using AS2 and I've created a class that extends MovieClip. The problem is that I'd like to dynamically add Child Movieclips using the addChild method... but it doesn't work, it gives me the following compiler error: "There is no method with the name 'addChild'". But I can call other MovieClip specific methods such as this.getNextHighestDepth()
heres a reduced version of my class:
class com.sck.DragList extends MovieClip { //Declarations private var placeHolder:MovieClip; private var listMask:MovieClip;
I have a main package that adds the background image to the project, from here on im trying to have seperate classes that add objects to the background as a parent and control these objects.my code in the main package:
What I describe here is not correct. My full code had some other things in it that was the reason I couln't see mc2. The code described under is actually working!
I have custom class (MyContainer) that extends Sprite. Then:
Code: var mycon:MyContainer = new MyContainer(); var mc1:Sprite = new Ball(); // Ball is a sprite in my library var mc2:Sprite = new Ball();
[Code]....
it works, but I dont want that, as MyContainer has custom variables and functions I use. A simple: if (mycon is DisplayObjectContainer) evaluates to true.
I got a background asset loaded then I want to add a textField above that asset. How do I do this. It sets behind. And I can�t figure out how to override the IDisplay class.
I'm have trouble attaching graphics to the stage from a class. I can do it on the timeline but the code doesn't work in a package.[code]this doesn't seem to work even if I import the picture in the package.[code]