ActionScript 3.0 :: Better Way To Abbreviate Constructor?
Feb 11, 2011there is a better way to abbreviate the following code??[code]
View 7 Repliesthere is a better way to abbreviate the following code??[code]
View 7 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 RepliesYou can declare variables outside of the constructor in a class, so what is the point of a constructor in AS3?
[Code]...
I do know that you cannot call functions, however what is the purpose of the constructor when the code in the class is executed? Why not allow functions and make it simpler?
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]......
I am trying to things efficiently and put as little code as possible on the timeline.
I have a document class loading and working at runtime.
It creates a button that takes me to a different frame on the timeline.
I have a movie clip there. I put a trace in the constructor of the class of that movie clip but it will not show the trace comment in the output window-its not working. There are no errors.
I also tried instantiating the same movie clip from the document class-which worked-but the trace in it's class's constructor still does not output.
I'm having a problem with a .swf which when loaded into another .swf has its constructor function ignored
when i'm running local it works fine, but when theres a real loading the constructor doesnt run, also making timeline code ignored ( since timeline code is just addScript call in the clip constructor)
anyone else has had this problem?? same problem happens either using Loader class or BulkLoader, also happens when simulating download in the IDE
Is it possible to define 'public properties' of an object in the constructor method when you create the object ? similar to..
var leftmain_scrollertext = new TextField({length:10});
I have a TextField and I want to set its maxChars, x, y, width etc.
when I specify one or more of these I get... 1137: Incorrect number of arguments. Expected no more than 0.
am I forced to specify each property I want individually after I have constructed it ?
I have an object that has been added to the stage, exported properly for actionscript, and given an instance name.It's class file is this:
PHP Code: [code]....
And yet none of this works. The trace doesn't even go off, meaning the constructor is never activated. It's linked properly; if I go to the movie clip's preferences and hit "edit class file" it takes me to the proper one.It's possible that the problem lies with the frame numbering. The first time this object is added to the display list is in Frame 2...and it says "export in Frame 1" but I'm not exactly sure what that means or how it affects the class definition or how to get around it. I tried adding it (var sb:SoundButton = new SoundButton in the first frame,
I am going through the book gameprogramming university and checked to make sure my code matched.
I am using 2 classes the main class attached to the timeline, and an airplane class that contains a symbol in the library with different frames.
the main class is
Code:
package {
import flash.display.*;
public class airraid extends MovieClip {
[Code].....
when i execute it i am getting the error:
1136: Incorrect number of arguments. Expected 0.
This is at line 7 where it is creating the airplane object.
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 RepliesI have a shuffleList.as file with this code...
[Code]...
When run this file the compiler report this error: "A constructor cannot specify a return type." Where I'm wrong; I'm new in actionscript..
I have three classes (shown below, after the problem description).The first class (InteractiveStrategy) is the main class definition. In there I declare and instantiate two variables, download and upload, both of DataTxRx class.
On instantiation the folowing error pops up>> 1203: No default constructor found in base class strategy:DataTxRx public function Question(){ The second class, DataTxRx does two things only, either to download data or to upload data. As shown in its constructor, if the required parameter 'direction' is equal to DOWNLOAD, it calls the DownloadData() function. Similary, it calls the UploadData() if the required parameter is equal to UPLOAD.
The third class, Question extends the DataTxRx class, but itself has no constructor. However it has other methods(not shown) for adding, modifying and deleting questions anomg others.
package strategy{
import flash.display.Sprite; import flash.events.*;
import strategy.*;
[code]....
I'm getting the following error:TypeError: Error #1007: Instantiation attempted on a non-constructor.at Website()[/Design/The Silver Collective/_classes/Website.as:42]
This is line 42:var top = new top();
package {
import flash.display.*;
[code].....
what i am trying to do is by pressing zero_btn which is an object in the library to print a number in the dynamic text box ( result_txt ) which is also an existing object in the library and on stage. my knowledge in actionscript is not much and messing with .as files is totally new to me! then thing is that this code when i locate into to .fla file works fine. there is no error with the code i posted, but am sure something is missing ... like calling the constructor of the .as file.In the library the name of it is Zero_btn and the instance name of this object is zero_btn and it is a button.[code]
View 11 Repliesam trying to pass a movieclip reffrenc to a class, but i want it to be optional, so am trying to initialize it, but it dossent work, why?
public class CoverFlower extends MovieClip
{
var playBtn:BigPlay = new BigPlay();
[code].....
I'm gettnig the following output on the code below - Its driving me mad trying to find th eproblem..
TypeError: Error #1007: Instantiation attempted on a non-constructor.
var nc:NetConnection;var ns:NetStream;
var nsPlayer:NetStream;var vidPlayer:Video;
[code]....
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] .....
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 RepliesIn Flex ActionScript, a new object can be instantiated via the parameterless constructor with or without (). Example: var array:ArrayCollection = new ArrayCollection()
var array:ArrayCollection = new ArrayCollection
Is there a difference between the two? Is one preferred over the other?
For Example:
package{
public class A {
var test:String;
public function A()
}} class B{
}
The code is in the same file, we call B is inner class, then how to call the constructor of class B
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].............
let's say I have a class:
public class SomeClass{
var name:String;
public function SomeClass(n){
name = n;
}
}
If I do var s:SomeClass = SomeClass("test");, it tries to convert a string to SomeClass. How do I prevent it from doing that?
basically my program has this part in it where it emulates this menu system that's on a piece of hardware. So in my code I just have a bunch of objects in a hierarchy to represent the menu. Each object constructor has references to other screens. When these buttons are pressed, they go to one of the screens referenced in the constructor.
[Code]....
I have an as3 package which looks like
package {
// imports
public class ColoredSquare extends Sprite {
[code]........
I've got a class which attempts to call a method upon Event.ADDED_TO_STAGE firing. Instances of this class are obviously added to my stage (I can see them) yet my onAddedToStage method never gets called.
HTML Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
[Code].....
I know, every class needs a constructor. But, in the book there's a practical tutorial of a media player to demonstrate all of the concepts of OOP. So the author first created a class called MediaController and then another class called FLVController which extends MediaController. In the FLVController the author did not include a constructor function, instead he has just overridden some of the MediaController class. Actually, I never knew this is possible... but in this case, does FLVController use the constructor of MediaController? what if both class should be constructed differently, does that mean I have to include a constructor in FLVController as well or override it in some way?
View 2 RepliesI wrote a script to make a random image from an array appear and float up through the stage. The problem is that at some random time in the movie, i get the error: TypeError: Error #1007: Instantiation attempted on a non-constructor. at Untitled_fla::MainTimeline/enterFrame() This occurs at random intervals. From that point on, the script stops working. There must be something wrong with the way I generate MCs from the array.[Code]...
View 1 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 RepliesI'm doing something - probably very stupid - with an external library swf. That swf so far contains two buttons each with their own classes 'Simple_Button' and 'Simple_Pop_Button'. In the library swf document class I set up an object that lists the available classes:
Code:
oClasses = {"Simple_Button":"com.Home.Button.Simple_Button",
"Simple_Pop_Button":"com.Home.Button.Simple_Pop_Button"};
In the swf that loads the library swf I process that object and create another object with proper class references based on it:
Code:
function initHandler(event:Event):void {
defineLibraryClasses(event.target.content.getClasses(), event.target.loader);
addBtns();
}
[Code]....
first it might be valuable to mention that i have a one document class and a child of that class, which is the one im having problems with. My library objects is added to the stage perfectly, but after i wrote the last code (in bold), i get:
TypeError: Error #1007: Instantiation attempted on a non-constructor.
at Entity/moveE()
[code]...