ActionScript 3.0 :: Do Something After Its Constructor Function Is Finished And The Object Has Been Created
Jun 10, 2010
I have a class which works with data and I want to do something after its constructor function is finished and the object has been created. If a class is a MovieClip, I can do this:
[Code]....
View 3 Replies
Similar Posts:
Mar 17, 2009
I am new to AS3 but not to AS2. I have written a simple class and when I import it, I don't see the object that should be created upon calling the constructor. Can you guys tell me where am I going wrong. And I am very puzzled about 'document class'. Yes, I have google numerous threads on "document class" but still very shaky on this matter. Here is my simple class which should place a button object on the stage when I create a new object of this class. Once I have created the BTN class, I have made sure that I have button component in my library, I then instantiate the object by creating a new CS3 file and importing my class:
import com.learning.as3.*;
var b:BTN = new BTN();
When I test the movie, I get the following errors:
1172: Definition com.learning.as3 could not be found.
1046: Type was not found or was not a compile-time constant:
BTN.
1180: Call to a possibly undefined method BTN.
View 4 Replies
Aug 20, 2009
why can't i acces the object outside of the function with test1._alpha = 20;[code]
View 4 Replies
May 22, 2011
I am currently trying my 5. workaround to get my menu done. . I want to move a series of 4 buttons up, after a click and when all buttons finished their movement I want the bottom 3 to move down again.
My big problem ist, that I dont get a check working to see if the function move() hast finished in order to fire the function open(). Is there any listener or so?
Here is my code:
Code:
//Setup and register with Zego Engine
import com.mosesSupposes.fuse.*;
ZigoEngine.simpleSetup( Shortcuts, PennerEasing, Fuse );
[Code].....
View 1 Replies
Aug 29, 2009
I have three functions and I want to play them one by one when each of them completes the tasks inside. How can I add an eventlistener to a function to check if it is finished?So the following is the example:
function generateIdeaBalloons():void { var ideas1:MovieClip = new idea1 (); ideas1.x = 480; ideas1.y = 248; container.addChild(ideas1);
TweenLite.to(container.ideas1, 1, {delay:0.5, x:50, ease:Quart.easeOut});}
[code].....
View 5 Replies
Mar 26, 2005
i've got this code:
[Code]....
what i want is that when you press the left or right key the back or further function is only processed when _root.done = "a" (or true something else)... but now it doesn't work... _root.done is always "a".
View 5 Replies
Mar 26, 2005
i've got this code:
Code:
_root.done = "a";
var myListener = new Object();
myListener.onKeyDown = function() {
switch (Key.getCode()) {
[code]....
what i want is that when you press the left or right key the back or further function is only processed when _root.done = "a" (or true something else)... but now it doesn't work... _root.done is always "a"...
View 5 Replies
Oct 11, 2009
I'm making a class called 'player', and really, I don't need a constructor function for it. Do you just outline the function, but don't put anything between the curly braces? Also, I'm a bit new with access levels. If I wanted my functions from my player class to be accessible from the main class, do I make them public?
View 3 Replies
Jan 9, 2010
Basic OOP question... I want to add a couple functions to the Array class so that my program will be amazing and make me rich and famous overnight. So I create a new subclass NewArray which extends Array. Do I need to write a constructor method for NewArray? If I leave it blank will it just use the parent's (Array's) constructor method?
View 1 Replies
Jan 7, 2010
If I pass variable(s) like this in document class action script file(I'm not even sure if I can pass more than one variable):
Code:
ballPointRight = new BallPointRight(ball, xDir, padScreen) ;
And now the BallPointRight's action script file:
Code:
package {
import flash.display.MovieClip;[code]....
doesnt work since it doesnt recognize variables...
View 4 Replies
May 9, 2011
Is it OK to use the constructor to set properties for a value object class or must I use dot notation and set each one, one-by-one? I recently read an article that was saying I should do it one-by-one as value objects should only contain properties and went on to say using the constructor is not OK (best-practice wise).
Code:
("not OK")
var employee=new[code].............
View 1 Replies
Feb 15, 2009
i have an animation with a series of colored squares appearing and disappearing from the stage [URL]..except that the squares appear and disappear). Each of the squares fade in and out using Actionscript, with a custom method that animates its alpha property over time. I want to pick randomly every few seconds a square, to make it disappear and put a new one in its place, and my code is more or less like this:
[Code]...
View 0 Replies
Feb 14, 2009
Is it possible to store a function constructor in an array? I tried, but getting an error for example, say this is my function:
functiom openPages():void
{
trace("pages open");
}
and my array:
var myArray:Array= new Array(openPages);
View 7 Replies
May 14, 2009
I am trying to make a subclass of flash.display.Loader, which should do something when the loader completes loading the content. So I do addEventListener(Event.COMPLETE, onComplete) on my loader subclass. But this Eventlistener is never called. Is this supposed to happen? Can't I use an Eventlistener on the class that dispatches the event? My code looks like this: public class MyLoader
[Code]....
View 4 Replies
Sep 6, 2010
I'm sure that I'm doing something daft here - I just need to remove a child that's created in the constructor through an event listener.My code is below but does not work. Can someone point me in the right direction please?
public class Main extends Sprite public function Main()
super();
var rectangleIndex:uint = this.getChildIndex(playerBackground)
[code]......
View 5 Replies
Mar 3, 2011
I´d like to know how could use the Timer class extended.I´m trying to pass a parameter to the constructor function, so I can use it inside the listener.
Here´s example:
[CODE]
package { import flash.utils.Timer import flash.display.DisplayObject public class ChangeColorTimer extends Timer { public static const CHANGE_COLOR:String = "changeColor"; public var obj:DisplayObject public function ChangeColorTimer(delay:Number, repeatCount:int, obj:DisplayObject ) { super(delay, repeatCount) this.obj = obj } } }
[/CODE]
That was the ChangeColorTimer that extends Timer.Now, I´d want to know how would I use ChangeColorTimer.I thought it was the same as using Timer.I´ve tried this:
[CODE]
public function changeColor(mc:MovieClip):void { var colorTransform:ColorTransform = new ColorTransform() colorTransform.color = 0xEE0000 mc.transform.colorTransform = colorTransform var changeColorTimer:ChangeColorTimer = new ChangeColorTimer(400, 1, mc) changeColorTimer.addEventListener(ChangeColorTimer.CHANGE_COLOR, setNormalColorListener) changeColorTimer.start() } private function setNormalColorListener(e:Event):void{ trace("called") }
[/CODE]
I called changeColor, but, I don´t get "called" in the output from the setNormalColorListener listener.
View 2 Replies
Nov 7, 2010
is it possible to get the name of a calling function or the constructor from the called function? is it possible to determine the previous function of the thread?
i would like to call some setter functions from my constructor and have my setter functions determine if it was the constructor that called them.
currently, i'm setting a boolean for this functionality, but perhaps there is another way?
public function Constructor(myNumber:Number)
{
this.myNumber = myNumber;
}
[Code]....
View 2 Replies
Jan 26, 2009
I have a document class name elevator and my constructor is also elevator as usualHow to call this constructor function within elevator class? Is is possible or not?
View 1 Replies
Feb 11, 2009
I have a series values I'm passing (from an FLA) into the constructor of a class. I just want to make clear in my mind that, the only way to pass the variable params, to the function nowDoThis, you'll need a dispatchEvent or a custom event to send it along ?
As an example:
Code:
// constructor
public function MyFunction(_param1:uint, _param2:uint, _param3:uint) {
param1 = _param1;
param2 = _param2;
[Code].....
I have only a vague understanding of using objects and dispatch events. Isn't this something that people need to do all the time?
View 3 Replies
Aug 18, 2010
Simplified ItemType Code, contained in Types/ItemType.as
Code:
public class ItemType
{
public static var SWORD:ItemType = new WeaponType(0, "Sword", null);
public function ItemType(id:uint, name:String, icon:Sprite)
[code]....
On attempting to compile, following error is displayed:
Code:
[Fault] exception, information=TypeError: Error #1115: Types::WeaponType is not a constructor.
View 3 Replies
Oct 15, 2010
I'm currently writing a class where I'd like to call the class constructor without having to instantiate the class itself. Something like this : Class:
[Code]...
trace(testString); //wil trace the text "test test123" Is it possible to somehow achieve this? When I write the costructor method like "public static function ClassName" it fails. Is there any other way?
View 3 Replies
Dec 1, 2010
I have the Class and the parameters of its contructor as an object. What I need to do is a function that returns an instance of this class, passing this parameters to the constructor.
This is the code:
Some random and unmodifiable class:
public Foo {
public function Foo(a:int, b:String) {
// constructor
}
}
And some function (in some another class):
function bar(params:Object):* {
var baz:Foo = new Foo(params.a, params.b);
return baz;
}
What I need to do is make this function generic, without pass params as parameter to Foo constructor because I can't modify it. Something like:
function bar2(clazz:Class, params:Object):* {
var baz:* = new clazz(/*some magic way to transform params in comma separated parameters*/);
return baz;
}
View 3 Replies
Sep 30, 2011
I am working on a side-scrolling platformer game. Because of this, I have a class that acts as a floor. I also have a class representing enemies. I am having problems with passing a parameter to a custom class' constructor. The class (SkullDemon.as) extends MovieClip. I am trying to pass an instance (called "floorL1") of a customer class called "FloorLevel1." "FloorLevel1" also extends MovieClip (I do not have a written .as file for "FloorLevel1"; I just exported the floor MovieClip to that class).
I am trying to pass an instance of "FloorLevel1" so that the "SkullDemon" object can land on the floor just like in a platformer. My main class is called "TME2_Main." This is the class from which I try to pass the "floorL1" instance to the "SkullDemon" class. This is how I try to create a Skull Demon instance and pass "floorL1" to its constructor:
[Code]...
What am I doing wrong here? I have spent a while looking for solutions (including moving code outside of TME2_Main's constructor),
View 1 Replies
Oct 11, 2009
I have a class in my .fla's library called StatBar_object. StatBar_object is an inherited class that extends from a custom class StatBar, while StatBar extends from MovieClip.
However, StatBar's constructor has a parameter (the constructor reads "public function StatBar(target:int)"). Thus, I continually get an output of:
"ArgumentError: Error #1063: Argument count mismatch on StatBar_object(). Expected 0, got 1.
at actionscript.stat::StatBox_object()
at actionscript.modes::battle_mode()"
Is there any way to get StatBar_object's constructor to include StatBar's parameter?
View 8 Replies
Apr 19, 2010
I want to serialize ThugtrisShapes' children (heritage/polymorphism) but his children like Right_LShape take constructor parameters,i have to assign it a default value (in my case null because they receive an Array type), but i get this error even when implementing IExternalizable.
Take Note: IForm extends IExternalizable.
here is a link i found about it but it still does not work...[URL]
Code:
public class ThugtrisShapes extends Sprite implements IForm
{
var squares_:Array;
var numsquares_:int=MAX_SQUARES;
[Code]....
I know that not all class' can be cloned , but cloning is an important aspect of OO programming.... There should be a solution for my problem,besides taking the parameter out of the constructor and add a setter.
View 8 Replies
Jun 13, 2003
I have the component Hadlab Newsflash on my stage.I have a button that, on rollover, changes the color of the component.When the button is clicked, the component fades out (tweenning) and the movie goes on. The problem is that the constructor keeps telling the component to be #FF0000(red) and the fade out tweenning doesnt work anymore because the mouse is on the button. Here is the code:
Code:
// cria a funcao "onRollOver" para o btnEnter
btnEnter.onRollOver = function() {
[code].....
View 1 Replies
Aug 11, 2010
Is it possible to set a listener or something like it to run a function once the flash movie itself has finished loading?So something like:When this flash movie has finished loading, activate function.Btw. I'm not trying to do this with a swf file loaded into another flash movie. I need this to be done by the movie once it self has finished loading.
View 1 Replies
Apr 7, 2009
I am new to AS3 and writing classes and keep having a hard time with these error messages I am getting. I have the following AS:
public class PrevNextNav {
public var back_next_nav:MovieClip;
public var next_btn:SimpleButton;
public function PrevNextNav() {
back_next_nav.next_btn.alpha = .3
} .... etc.
The class works fine, except when I try to set the alpha to 30% in the constructor function, I get this error in the output window.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at _classes::PrevNextNav()
at InteractivePilotDocument()
If I comment that line out, all is good. What does this mean?
View 8 Replies
Jun 9, 2009
I worked out a way to call a function whose name is in a String variable. That is:
function myFunction()
{
trace("Hello!");
}
[Code]....
View 3 Replies
Jan 1, 2012
I have a main.as scipt whereby i put the following in the constructor main function.
L1: LoginScreen.enterBtn.addEventListener(MouseEvent.MOUSE_DOWN, checkLogin);
L2: map.visible=true;
it will execute checkLogin function but stuck at Line 1. how do i make it run Line 2?
View 1 Replies