ActionScript 3.0 :: MovieClip Add Itself To A Chosen Parent DisplayObject In Its Constructor Method?
Dec 16, 2009MovieClip add itself to a chosen parent DisplayObject in its Constructor Method?
View 5 RepliesMovieClip add itself to a chosen parent DisplayObject in its Constructor Method?
View 5 RepliesI have a class. I can call the constructor (initialize the class), and the constructor can then call a function/method inside it's own class (so I know it works), but when I try to call the same function/method myself from the instance of the class I just initialized, I get an error.
View 3 RepliesFirstly, I've created a global variable called mc to store a movieclip instance:[code]Later on inside a function, I've created a new instance of my movieclip and added it to the stage.[code]Now, this is working fine most of the time. But at one particular point in my program, after many other things have happened, when trying to remove this movieclip it throws the 'display object must be a child of the caller' error.So, I'm thinking if mc isn't a child of the stage, what is it a child of? Tracing mc.parent returns null - so it seems to be telling me that the parent (which was definitely the stage when it was created) has wandered of somewhere and abandoned my movieclip!I have no idea how this has happened, and as the whole program is several thousand lines long I can't post it here. So, does anyone have any idea what might cause a display object which is added to the stage to become orphaned like this?
View 1 RepliesHow can I check what the parent of a displayObject is? What is the parent of myObject for example.
View 1 Repliesi was caught in the situation that i need the DisplayObject to access its parent.variable.
I have a Loader"B" was inside MovieClip"A"(with a variable"v") and i want called A.v like this:
Code:
trace(B.parent.v);
the above code is not working. and I need something similar. is it possible??
by the way, it has to be dynamic because i need to use it with function:
Code:
function doSomething (d:DisplayObject):void
{
trace(d.parent.v);
[Code].....
I'm getting an error that says Method cannot be used as a constructor - and I can't seem to find what that means exactly.
Here's my code (the line that is getting the error should be in bold):
stop();
var currentAnimation = new mapIdle;
makePlay();
[Code]......
S there any way filters applied to a DisplayObject (drop shadow, glow, bevel) can scale relatively with the parent (the DisplayObject it is inside)?And what about other properties like .distance for drop shadow?For example... If I have a 100px rectangle with a 10px glow inside a container object, and I set scaleX/scaleY of the container to .1, I want the glow to inherit the scale change from the parent (1/10th the size) just as the display object does that the filter is applied to.Instead, if you try this, you will see the glow stays at 10px no matter what scale the filter target or the container is transformed by.Pseudocode example (steps to reproduce),
1) create a sprite called _myOuterSprite on stage at scaleX = scaleY = 1
2) create a sprite called _myInnerSprite inside _myOuterSprite at scaleX = scaleY = 1
3) draw 100px rectangle into _myInnerSprite
4) apply 10px glow to _myInnerSprite
5) transform scale of _myOuterSprite to .1
Result:
- child sprite (rectangle) scales to 1/10th the size
- glow stays the same size
How can I make it so that glow scales to 1/10th as well?
...without capturing and scaling bitmap data
...without losing interactivity on objects
...in a way that would work visually for every filter, not just glow (drop shadow has distance property too, etc)
I'm making a kind of image showcase, what has a fluid width and height, depending on browser window dimensions. Everything is okay, I have other kind of issue: in constructor function in this gallery class I can't use stage property, I have to get it from main class. Why Flash treats me this way and how I can avoid this currentStage variable?
Main code:
package dev {
import flash.display.Sprite;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.MovieClip;
[Code] .....
(i'm using flashdevelop / flex sdk)IS there any way filters applied to a DisplayObject (drop shadow, glow, bevel) can scale relatively with the parent (the DisplayObject it is inside)?And what about other properties like .distance for drop shadow?
For example... If I have a 100px rectangle with a 10px glow inside a container object, and I set scaleX/scaleY of the container to .1, I want the glow to inherit the scale change from the parent (1/10th the size) just as the display object does that the filter is applied to.Instead, if you try this, you will see the glow stays at 10px no matter what scale the filter target or the container is transformed by.Pseudocode example (steps to reproduce),
1) create a sprite called _myOuterSprite on stage at scaleX = scaleY = 1
2) create a sprite called _myInnerSprite inside _myOuterSprite at scaleX = scaleY = 1
3) draw 100px rectangle into _myInnerSprite
4) apply 10px glow to _myInnerSprite
5) transform scale of _myOuterSprite to .1
Result:
- child sprite (rectangle) scales to 1/10th the size
- glow stays the same size
How can I make it so that glow scales to 1/10th as well?...without capturing and scaling bitmap data ...without losing interactivity on objects...in a way that would work visually for every filter, not just glow (drop shadow has distance property too, etc)
overloaded constructor method is there in flash? Iam trying the following code but it is giving error like this "A class must have only one constructor."
Code:
function Login(userName:String, userPassword:String) {
this.userName = userName;
this.userPassword = userPassword;
[code]....
Some constructor methods I've seen have the return type :void, even though they can't actually return any values anyway. If it's not required, is there a standard/best practice for that?
View 4 RepliesI just posted a message asking how to call a method from the constructor which has the parameters e: Event. I mistakenly ticked that post as answered when in reality it isnt. I was told I could add = null in the parameter of the function to make it work, like this:
[Code]...
I have got a problem with my actionscript class. This is my code:
package {
import flash.display.MovieClip;
public class Main extends MovieClip
{
public function Main()
[Code]...
class A:
[SWF(width='800',height='600',frameRate='24')]
public class A extends MovieClip {
private var b:B;[code]....
this.graphics calls do nothing in draw method, but work fine inside B`s constructor, what i am doing wrong ?
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 RepliesI'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 RepliesMy issue today is a DisplayObject error I'm getting when remove a child object. I have code that will launch(addChild) a video container and video controls as well as add a close button. Now the close button works fine and everything, removing the video and controls and I'm able to choose another video again, but when you click close a 2nd time I get this error: ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild() So I've narrowed down the problem to where I remove the videoContainer (which holds the video object) My code to play the videos:
[Code]....
I loaded external swf named child.swf from parent.swf. i am having a function called parentFunction() in parent.swf. I want to call parentFunction() from child swf.
View 2 RepliesI have looked around a fair amount and cannot find any information as to whether this can be done.
I want to know if it is possible to entend functions of a parent class i.e.I have a parent class which has a draw method and extends sprite. I want to draw something in this class e.g. a Box. Then I have a child class which extends the parent class. I then want another draw function in this class so that it still draw what is in the parents draw class as well as what is in the child draw class.[code]...
To my knowledge, there are 3 options:1 - parent.publicPropertyOrMethod.2 - using static vars/methods.3 - dispatching events.Under best practise for OOP development, which is the "best" method? Are there any more?I dislike #1 and never use it as it and can easily descend into hideous parent.parent.parent references that are easily broken. #2 has it's own problems whereby attempting to get/set instance variables doesn't always work through a static function (I am yet to completely understand this). #3 is great for triggering methods (I use this the most) but sucks for altering class properties and suchlike.
View 1 RepliesI have a custom class called ToolBar which is attached to a library item. The library item has other clips within it and each is an instance of ToolBarButtonA, B, C etc and these all extend the generic class ToolBarButton. If I set an event handler for CLICK within each ToolBarButton to trace 'parent' it comes back [Object ToolBar] which is what I expected but if I try to then call a method through 'parent.methodName()' it fails saying 'call to possibly undefined method'
View 9 RepliesI am using this guide for passing data to modules "Using interfaces for module communication". For getting child module instances they have done this
var ichild:* = mod.child as IModuleInterface; (mod = moduleLoader)
What should I do to get instance of parent application inside module? How can I call parent methods inside modules?
I just recently been using a lot of prototype javascript stuff, and was wondering there was anything like the "bind" method, for use in AS3. It's proved quite useful to be able to look both at the event.target as well as the class object the handler function might be associated with.
View 5 Repliesknow you can pass a parameter to the constructor of a class extending movieclipas in .... new (someParam)how do you pass a parameter like this if I use a loader to load in a swf.I want to pass something to the constructor inside the swf
View 1 RepliesIt's coming from this line of code:var dropTargetXML:XML = XMLTemplate.template.component.section.question.(@question_questionID == nNode.parent().@question_questionID)[0];nNode is an XML node sent as an argument to the function this is called in. The code runs,and does everything expected but the compiler sends out that warning. Do I have some formatting issue?P.S. I've tried telling it that it's XML like this:var dropTargetXML:XML = XMLTemplate.template.component.section.question.(@question_questionID == XML(nNode).parent().@question_questionID)[0];
View 1 RepliesI have several movieclips on the stage. They are linked (via properties - as linkage) to a class I created (GeoPuzzle).
The constructor calls several methods and has several properties that I set in the main timeline.
These methods are never accessed. I'm missing something obvious, but I don't know how to make these methods run, since they are in the contructor.[code]...
In a project, I need to pass in a DisplayObject to a container in a specified frame of a MovieClip. (for example a "container" instance at Frame 15)
I thought it should be just okay with this code:
Code:trace(mc.currentFrame);// Output 1 - we are at the first frame of this mc.
[Code]...
If the timer delay is set to 1, the container is still not available, but if it's set to 100, it's okay. Then I make this delay bigger and bigger, the threshold value is 25. (My FPS is 30)
I would like to be able to quickly check if a given DisplayObject is a descendant (not in the inheritance sense - ie. child, grandchild, great-grandchild, great-great-grandchild, etc.) of another DisplayObject. There doesn't seem to be a native way to do this and I can only think of two ways to achieve it: Create the mother of all nested loops. Seems a bit, I dunno, wrong? Dispatch a bubbling event at the 'child' and check if the potential 'parent' receives it.
[Code]...
Is there a way to detect the type of a DisplayObject with a switch case statement?I noticed that you can check if the displayobject compared to the type returns true or false.
Trace(mydisplayObj is Sprite); //return true or false
Trace(mydisplayObj is MovieClip); //return true or false
But isn't there an option to get the type of the displayObject directly?
like,
switch (typeof(mydisplayObj)) {
case Sprite:
break;
[code]....
I've got a simple class:
package somepackage
{
import flash.display.MovieClip;
public class NewMc extends MovieClip{ public var myVar:String = "something";}}
And there is a question now: how can I assign a "real" MovieClip object to my created-class object?
I mean: var realMc:MovieClip = new MovieClip();
[Code]...