Actionscript 3 :: Flash Define Variables Before Or In Class Constructor?
Dec 15, 2011what is the difference between something like
package {
public class Myclass {
var txt:TextField = new Textfield();
[code]....
what is the difference between something like
package {
public class Myclass {
var txt:TextField = new Textfield();
[code]....
Can I define a custom class to be an AsBroadcaster in the classes constructor?
Code:
class myClass{
function myClass(){
AsBroadcaster.initialize(this);
}
}
And if so will that give me the ability to addListeners to an instance of that class?
The reason I want this approach is because I want to broadcast events from inside one of the custom classes methods and I want a textField on the stage to be listening for that broadcast message.
I'm having a little trouble with my move to as3, (surprise surprise huh?) Basically when I create a movieclip, I wan't to pass some values into it, like so:
Code:
var menu=new Menu();
menu.x=50;
[code].....
I am creating a Weapon class for a game and the weapons itself will be the sub classes. The sub classes will hard code some values (such as max ammo and the weapon name).
I trying to access this declared data in the base class constructor, at the moment it's not outputting the values. Is this possible?
I've broken my Weapon class for simplicity:
ActionScript Code:
package
{
import flash.display.MovieClip;
[Code]....
My current workaround is creating a protected method in the base class to trace the information and calling that method in the sub class's constructor, this works fine but this doesn't seem like the most efficient technique?
I have a bunch of movieclips( clip A and B for this example) in my library that I want to use the same base class (MyClass.as in my example). I assigned the same base class in each clips property window and then gave each clip a unique class name which doesn't exist so flash says it will create the class automatically.
Now if I create a bunch of A's and B's on the stage via actionscript, how would I send variables to the constructor in MyClass.as without having to creating A.as and B.as to pass the variables along to the base class? if I do: Var newA:MovieClip = new A (argument 1, argument2, etc) It says it expects 0 args since the A & B classes were created automatically by flash.
I have a base class "Vehicle" and a derived class "Car".
[Code]...
Basically, I want to set a vehicle property in Car's constructor, call Vehicle's constructor with super() and have Vehicle do something based on myVar. But this is the output i get: car pre: null car post: car vehicle: vehicle Why does myVar not keep the value of "car" when the base class constructor is called? How am I supposed to implement this correctly?
i have some pretty simple code, i have my document class trying to add a santa class to the stage (simple game ) - but it will not add and i get not errors at all,Santa class:
Code:
package Classes {
import flash.display.*;
[code].....
I have a custom class, MyMC. The only argument the constructor takes is a string, which sets the text of a label inside MyMC.
In the Flash IDE I've placed an instance of MyMC, which is called mcOnStage, on the stage. Through the document's class Main I'd want to perform the constructor function of mcOnStage.
Some of the top level classes can be instantiated as well as called as a function (e.x. new Number() and Number(), new Boolean() and Boolean(), new Array() and Array()).
Usually this is used for type conversion or as a shortcut for instantiation. I would like to be able to do the same thing:
[Code]...
What I wanted to do originally was to create a logging class to interact with Flash/JavaScript, and be cross-browser compatible. I wanted to be able to use the log function as an alias of a method in the log class. This got me to wondering whether I could implement a custom casting function just because. I've now realized it's not possible, but was fun to play with anyway.
i) Create a symbol called SimpleSquare. This should consist of a simple red square graphic
ii) Create a class file to define a class called SimpleSquare. This should be linked to the SimpleSquare symbol. SimpleSquare ashould have the following functionality: When the instance is placed on the Stage, it should start to disappear by decreasing its alpha at 0.01 in every frame (hint: alpha)
recently, I research for the collection framework, and find LinkedSet(AS3Commons collection framework,it is a good opensource framework) written in ActionScript, but it can't use as dataProvider in ComboBox or DataGrid, because only implements ICollectionView can use as dataProvider. So I want to try if a class implements ICollectionView can work or not. I know Flex has build-in class implements ICollectionView, but I only want to define a class not use build-in class. The class as simple as possible.(can work is enough)
View 1 Repliesi am working on a project where i have some common code which i import in different movie clips and different files the code is in actionscript 2 in an external .as file. this is not a class its just a bucnh of functions and temporary variables.Problem is when i use the check syntax button or auto format button i get the following error."ActionScript 2.0 class scripts may only define class or interface constructs."this used to work fine in flash 8 but it always gives this error since i started using flash 9.the code works fine too. its just that my auto format button and the check syntax doesn't work.
View 5 Replieshere is the scenario we ran across while working on our Flash AS3 project today.
/main/root.fla
/main/root.as
/main/sub1/sub.fla
[code]....
We have many sub swf's that are loaded by the main root swf. The root swf shows the art on the stage of the sub swf, and also runs some code from the sub swf's document class. However, we noticed the constructor was not getting called on the second sub swf if the document class is the same name- even if they are in different folders. Note that we publish our swf files to a separate directory (with the same structure as above) so it is easily copied to the web server.
-root.swf loads sub1/sub.swf
-the constructor of the document class sub.as in subfolder sub1 gets called
-root.swf shows sub1/sub.swf assets with the correctly constructed sub1/sub.as document class
-user chooses to switch to sub2
[code]...
We decided to use a workaround where we basically changed the two document class .as files to be different names (e.g. renamed sub1/sub.as -> sub1/sub1.as and sub2/sub.as -> sub2/sub2.as, and updated the .fla's to point to the renamed document classes), and it works as expected. Hopefully that workaround is useful for someone.I realize most people just name every single file differently and keep everything in one folder, but when you have a sufficiently complicated project, things like this come up.
have a movieclip on the stage, whose Class is "com.nestor.elements.letterKey". The class funcKey extends "key" which contains a "public var val:String". I have many instances of letterKey(asdfghj.... a full keyboard), so I'd like to use the IDE to arrange and pass variables. SO, within the Flash IDE/Library, I rightclick the symbol to access its component definition, and add a parameter for the var in the baseclass name:value,variable:var,default:whatever,type:Str ing).Now, in the constructor function for the baseclass, if I trace my variable: it is null.
View 1 RepliesIs it possible to define a variable inside of function where the actual variable name will change based on what parameters the function is called with? Take a look at this [code]...
View 1 RepliesHow can I store variables like "true" or "false" to each movie clip I have on stage?Each Mc is duplicated thru AS, so when clicked the action would depent on the variable (true or false) that was definned to that particularly MC.lets say all of the MCs starts with a "TRUE" value defined to it.When it is clicked, a "FALSE" valeu have to be definned to that clicked MC and it alone.The rest of them should remain with the false value.
View 6 Repliesm new to as3 & am trying to make a platform game. i'm just not sure how to define the objects & variables. like my character & any other object i want it to collide with will be sprites, but im not sure where to go from there.
View 2 Replies(Spoiler alert: It's not an issue of my package statement not reflecting the location of my class file.) When I have a class linked to a MovieClip in my library and that class takes an argument in its constructor method. That class will compile properly ONLY when it's located in my top-level directory (same dir as the .fla and Document.as files). If I move that class to a deeper directory, say com.place, the compiler will generate error "1136: Incorrect number of arguments. Expected 0.
[Code]....
There is a library component represented by Class A. But constructor of this class requires some parameters. When the component needs to be added dynamically, it's fine because of code :
var abc:A = new A(param1,param2)
But what if my movieclip is already present on the stage. I notice it gives out error, that the parameters are null.
Is their any way to insert constructor parameters for movieclips already on stage.
I want to clone a class object. I tried following from here:
package
{
import flash.net.registerClassAlias;
import flash.utils.ByteArray;
[Code]...
BUT this only works when the class has a default constructor and not when it has parameterized constructor:
how to clone a class object when the class has a parameterized constructor?
I know what instance variables, contractor methods, local variables and constructor arguments are (I think) but I'm confused as to when or how to use them, for instance I have use this a lot and I don't really understand why it is used like this...
[AS] package standard.testing {
import flash.display.MovieClip;
import flash.events.Event;
import com.greensock.*;
[code]....
Why create a function with arguments...
[AS]public function tweenMe(mc:MovieClip, xPos:Number, yPos:Number)[/AS]
Then create instance variables...
[AS]
public var _mc = MovieClip;
public var _xPos= Number;
public var _yPos = Number
[/AS]
then create local variables with the values of the arguments
[AS]
_mc = mc;
_yPos = yPos;
_xPos = xPos;[/AS]
i have incuded an AS file in my fla. But is gives an error ball.as: Line 73: ActionScript 2.0 class scripts may only define class or interface constructs.
[Code]...
I'm tryin' to define a simple class in actionscript2 but I receive some errors.Here's the code done in actionscript editor: (name of the file is NavaSpatiala.as)
Code:
class NavaSpatiala
{ // proprietate publica numita viteza (data membru)
public var viteza:Number;
[code]....
How I can use import command in class1.fla (I mean what is the contents of class1.fla when I use command import to import external class defined in NavaSpatiala.as) if I copy this code to NavaSpatiala.as to solve this error:
Classes may only be defined in external ActionScript 2.0 class scripts. line 1
I need to get rid of this error:
Code:
Classes may only be defined in external ActionScript 2.0 class scripts. line 1
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 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 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].....
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
I'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]....
I have a bunch of sprites in my library which all behave in the same way.
now i want to put the behavior and all the common methods into one BaseClass [code]...
In the AS3 there is a remark, that a Class Constructor is just a method of the class, that is executed when an object of that class is created. So, since the constructor is just a method of a class, how can I call it directly from the other class methods?
View 8 Replies