ActionScript 3.0 :: Get Child Properties From Stage?
Nov 14, 2009
I have some code that adds a child using addChild(dragsquare); dragsquare is what I used as the class for a movieclip, mcsquare.
Everytime a child is added to the stage, it is called: ObjectX The "X" increments everytime a new object is added using ++objNum.
E.g:
Object1
Object2
Object3
etc...
When the child is added to the stage, it can be dragged, resized, rotated, etc...
I have used this code so when someone clicks the "save" button it loops through all objects on stage (increasing the last number by 1 to get the next object) and finding their properties. Here is the code I have used.
ActionScript Code:
Code:
save.addEventListener(MouseEvent.MOUSE_UP, saveObjects);
function saveObjects(event:MouseEvent):void {
for (var i:uint=0; i<numChildren-23; i++) {
[Code]....
23 children already exist on stage so I have to minus that number to get whatever is added on stage by the user.
However, scaleX is getting the childs ORIGINAL properties and not its current stage properties (where it has been resized, rotated etc..) and only returns a 1 for scaleX. How would I make it track the properties it has on stage?
View 6 Replies
Similar Posts:
Jan 6, 2012
In Flex, how do you best manage child collection property changes, specifically notifying a parent object that a property within the child collection has changed.
package
{
[Bindable]
public class Author
[Code]....
How can I notify the Author when a Book propery has changed and update the dateOfFirstBookPublished method?
View 1 Replies
Jun 10, 2010
I have a mainSwf in which I load an external swf, which loads an external swf.( a child of a child). I am trying to set the framerate via AS3 for the childs child by using stage.frameRate= 15;
It doesnt work when the children are loaded into the mainSwf. how to access the stage of a child's child? I have tried root, Movieclip, this but can not get it to work
View 9 Replies
Jun 8, 2011
Basically, I have a menu created using XML. Each menu item has a fill that fades in and out as the user scrolls over them. What I want to happen is that when an item is clicked, it stays highlighted. The problem comes when I click on the second item. I can't get the first item to "unselect."Here is the menu code and functions.
Code:
var menuHolder:MovieClip = new MovieClip();
menuHolder.x = myMask.x;
[code].....
View 6 Replies
Mar 26, 2010
I have a holder movieclip on screen, then I create a loader, load an external SWF into the loader and addChild to my holder:
var bgloader1:Loader = new Loader(); [code].....
This all works. Now if I want to come back later on and alter the alpha or position I get an error:
//Neither of these work: MyHolder1.bgloader1.alpha=0; MyHolder1.bgloader1.content.alpha=0;
TypeError: Error #1010: A term is undefined and has no properties. at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()
View 7 Replies
Dec 23, 2009
I have a sprite in which I have added other sprites. Something like:
var sp_main:Sprite = new Sprite();
var sp_group:Sprite = new Sprite();
for(i:int = 0; i < 10; i++)
[Code]....
View 1 Replies
Jun 1, 2011
on my timeline i create a new instance of the class FirstClass with the following
code:
var firstObject:FirstClass = new FirstClass();
the class looks like this:
package {
public class FirstClass extends MovieClip {
public function FirstClass() {
[Code]....
On my timeline i would like to acces the x position of the object tempObject
View 1 Replies
Apr 24, 2010
I have created a loop to instantiate tiles on a board. In the following example, "Gametiles" is an array containing objects of class "Tile" which is a class that extends MovieClip. "Game" is a MC that I added to the stage in the flash developing environment.[code]This method is a bit cumbersome though. I really don't want to have to create a var and call getChildByName every time I want to interact with these properties or methods. How can I set up these children so that I can access them directly without the extra steps?
View 1 Replies
Jul 11, 2009
Is there a way for the child of a movieclip object to not inherit the paren'ts properties? Because I scaled down the parent movieclip height and width and I'm loading external images into the parent movieclip and images are also scaled as well so I'm wondering if there is a way for it not to inherit the properties but remain inside the parent?
View 1 Replies
Nov 22, 2010
My player movie clip has a smaller movieclip within it. Because the smaller movieclip is not within the parent clip it changes the x,y,width,and height value of the player movieclip and throwing everything off! To adjust I have to add (-2ndmovieclip.height) to everything i want to do. This is sloppy and I don't like it. Is there a better way to have a child within a movieclip without it affecting the parents properties? i want the parent to keep its original x,y,width,and height properties but the child keeps adding to them!
View 5 Replies
Feb 10, 2005
i've got an inheritance chain of AS2 classes set up where i have an array in the 'child' class that i'd like to be able to access from the 'parent' class:
bottomClass.as -'parent'
topClass.as -'child'
my question/dilemma is: how can the parent access the properties of a child class...is this even possible, or am i just looking at it wrong?
View 2 Replies
Feb 10, 2005
i've got an inheritance chain of AS2 classes set up where i have an array in the 'child' class that i'd like to be able to access from the 'parent' class:
bottomClass.as -'parent'
topClass.as -'child'
my question/dilemma is: how can the parent access the properties of a child class...is this even possible,
View 2 Replies
Aug 11, 2011
If im usin function to add a mc to the stage like so:var myChild:MC= new MC();
function somefunc()
{
stage.addChild(myMC)
[code].....
View 4 Replies
Sep 17, 2008
I'm attempting to use "if" statements to determine if an dynamically loaded photo is portrait or landscape. The problem I'm having is when I try "gallery_mc.getChildAt(0).width", it returns 0.
View 10 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
Nov 24, 2011
The name of my DocumentClass is Main. So, what's the difference between :
var myClass:Main = new Main();
var mcInLibrary:MovieClip ;
/////////////////////////////////////////[code]............
View 1 Replies
May 12, 2010
If I have a textfield instanciated from the document class with a base .string set as for example "4444" and BEFORE adding it to stage, I change the .string value to say "1234", when I test the swf, I can see the 4444 for a very short time changing for the 1234.I didn't change the value after adding to stage so I don't get why the display number is changed after being added to display.How to force it to add to stage (display itself) only once the initial changes to his properties are done?
View 3 Replies
Jan 18, 2011
I need to assign a symbol that is added dynamically in a symbol, x and y coordinates (that are from the main timeline).
View 2 Replies
Mar 20, 2011
I want to set the height, width and backgroundcolor, etc on stage programmatically in a pure AS project. I'm not really sure about how to do that.
I tried to set the height and width like that but it failed..
stage.align = StageAlign.LEFT;
stage.height = 400;
stage.width = 500;
View 2 Replies
Apr 29, 2009
here is my code
Code:
package
{
import flash.events.*
import flash.display.*
[Code]....
does it have to do anything with ADDED_TO_STAGE event?
View 2 Replies
Feb 24, 2011
i can set the stage's background color, etc., using a SWF metadata tag:
[SWF(width="1024", height="600", frameRate="60", backgroundColor="#000000")]
or if i'm using Flash Professional, i can simply set these properties for the document in the UI.
while the Stage class offers the ability to set a frameRate and override width and height thru properties in actionscript, why is it not possible to set the background color of the stage the same way?
Stage doesn't have a property (public or otherwise) for background color. can anyone explain why that is? it seems strange to me but i'm assuming there is a good reason rather than this simply being a oversight.
View 1 Replies
May 12, 2011
I have an object on my stage, called obj.I also have a class called "Physics" which contains a bunch of methods for physics, such as inertia, gravity, and bouncing off walls. In order to do some of these,I need access to the stage.stageWidth and stageHeight properties.My code is as follows:
public function wallBounce(obj)
{
this.stageRef = stageRef[code]...
This is supposed to check if the object's x value is greater than the stageWidth or less than 0. When I run this code it says:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I am a semi-newbie programmer who is completely self-taught and have no clue what is causing this. I spent a bit googling it, and I think it has something to do with scopes,.
View 1 Replies
Feb 10, 2012
If I have a swf that's being loaded into other peoples' swfs (which I have no control over) is there any way I can get properties from the stage (such as height, width, fullScreenHeight, etc.) or does this have to be exposed by the loading swf?
View 1 Replies
Aug 29, 2009
I am trying to access the x and y properties of the stage so I can set an objects' x and y properties to place it on the center of the stage:
this.x=stage.stageWidth/2;
this.y=stage.stageHeight/2;
The call to instantiate the object(*.fla):
[code]......
View 4 Replies
Jan 30, 2012
I am using this code to iterate through the contents of a movieclip which contains instances of "alien2" - my alien. I have each alien in a movieclip called squadron1. They all have their own layer and follow a motion path to recreate the attack sequence in Galaga. I can add action script to them by right clicking on them, but when I do this test below I can't call any MovieClip methods on them. It is my intention to add a function to each one via code to make it detect bullets, look for the player etc, but at the moment all I can do is add the code to each one individually on the stage.
Code:
var target;
for(var item in _root){
if(_root[item] instanceof MovieClip ){
target = _root[item];
[Code] .....
View 3 Replies
Feb 28, 2012
I am trying to access a property that belongs to the stage, from a class. For example, let's say I add a textfield with an instance name of "magic_txt" on the stage. In the Document Class, I am able to access magic_txt and update the field like so:
magic_txt.text = "Magic Text"
However, since I would like to work in classes, I am having a difficult time figuring out how to access the property "magic_txt.text" from a class. I know I need a reference, but I am unsure how to set this reference.
I am coming from a strong background in Visual Basic, and in Visual Basic, the way to access a form property is to call the form name (dot) object. In actionscript, it doesn't seem to be as simple.
View 9 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
Jul 26, 2009
How do I access Stage Class properties in Custom Class?
Class:
package {
import Main;
import flash.events.*;
import flash.display.Sprite;
import flash.display.Stage;
public class Run extends Sprite {
[Code] ....
Output:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
View 3 Replies
Mar 26, 2010
I have made a very simple swf in which I have a MovieClip which I have rotated on the stage. When I try to access this rotationX and rotationY properties of this clip using the constructor of the class assigned to this MovieClip they are coming back as 0 even though they shouldn't be. If I put an on rollover event of the MovieClip and trace out these properties here I get the correct values.
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
[Code].....
I also get the correct values when I read the values from the stage timeline.
trace ("TEST "+testMC.rotationX+" "+testMC.rotationY); //returns correct value
Is there a specific event I need to be waiting for which will tell me when the 3d properties are available via ActionScript?
View 1 Replies
Mar 3, 2012
1) In my program, I am wanting to create a function that would take in the height and width of a loader object, compare them to the stage dimensions, and then scale the object in question before it is added to the display list. However, I have several different types of classes that I want to make use of this functionality. So what would be better, to create a NEW class that would have to be created each time a resize needed to occur, and is imported by all needed classes, or just have a function within each already existing object and copy that function to every class's scope that needs it? Would this be resolved by placing the function in question inside of the default package?
2) When accessing stage properties, are they a global or a relative scope? i.e.[code]would those two statements produce the same value regardless of whether they were in the default package or inside of 1300 classes? Or is the stage scope relative to some degree?
View 6 Replies