ActionScript 3.0 :: Pass Value To Document Class's Constructor?
Jun 24, 2009I want to pass values to document class's constructor form html while embedding.
View 2 RepliesI want to pass values to document class's constructor form html while embedding.
View 2 RepliesI'm working on my document class and the contructor is running twice, hence it is running almost all of my code twice.[code]
View 5 RepliesI'm learning how to work with a document class. Using the class below, I am learning that this initiates immediately when running the Fla. The problem is that the "scrol" Movieclip is not present in the first frame, which is a menu with a list of topics. Scrol comes later in and is in it's own section/frame label and goes to that section when selected from the main menu of topics.
Is there a way I could call this action only when the Movieclip is present or when that section is shown? Also, I'd like to apply it to other movieclips, not just scrol. Underneath se = new SwipeEngine(scrol,400,0); can I just add a duplicate line but change the mc name? A possible concern is that the mcs may be different sizes in length and might not need to scroll as far.
[Code]....
I've got a simple program that consist of a document class and a buttonTemplate constructor class. I need to call a function called updateText that should be in the document class, when someone clicks on a button. My event listeners for the buttons are in the buttonTemplate class. My question is, how do you call a function in the document class from a constructor class? Here is my simplified code below
DOCUMENT CLASS
Code:
package {
import flash.display.MovieClip;
import flash.text.TextField;
[Code].....
I'm trying to pass my object class as constructor argument. I have something like this:
package myclass {
import flash.display.MovieClip;
import flash.display.BitmapData;
import flash.display.Bitmap;
[code]....
Now, when I try to create my Example:
import myclass.Example;
var example:Example = new Example(myObjClass);
I get message, that I'm not passing any variable (Error #1063). Why is that? What is wrong with it?
I got an error like "Incorrect number of arguments.. Expected 0." when I was trying to make an instance of a user-defined class that I've written in the document class of my project.Here's the line in my document class:private var myNotice:myNoticeClass = new myNoticeClass(this);An untyped parameter is supposed to be the only argument to the constructor method of class myNoticeClass and the constructor is something like this
public function myNoticeClass(ref:*)
{ ......
}
[code].....
here 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.
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.
when to use this in a classes?is there any specific rule?is it wrong to use this when you want to just access the stage that way?or is it better to pass the reference to the stage in the class constructor?
View 5 RepliesFor example, I have the class Bullet, with a constructor: Bullet(start:Point, target:Point)constructor
But, if this Bullet class extends the MovieClip class, how do I pass start and target into it? Right now I am using attachMovie to create instances of the class. (They behave correctly with the static properties set by the constructor, but to be useful it needs arguments.)
I have a custom class created by a main document class, and I want the custom class to run a function in document class after some time.
How can I sent the instruction from custom class back to the document class?[code]...
I'm creating a flash project and would like to pilot the most variables (eg: colors, texts, sizes, ...) from a single XML file and then spread them in my document class.
Code:
public var yourName:String;
public var myXMLLoader:URLLoader = new URLLoader();
public function intro():void {
[Code]....
Right now I got no errors but I got nothing when tracing the "yourName" var.
In Flash CSn/AS3 you associate a Main class with a flash file which when loaded in the flash player "automatically creates an instance of the program's main class."I'd like to know how to pass arguments to the main class, since you don't write it yourself (you put its name in the Document textfield in the IDE).
View 1 RepliesI have a document class called PlayVoiceOvers; I set voiceToPlay and frameToPlay in the public function and when the voice "v001.mp3" is done playing it jumps to frame label v2.[code]...
However the new voiceToPlay and frameToPlay don't do anything even though when the soundCompleteHandler is done it traces the correct values.can I pass variable information from the main timeline to the document class, apparently I can but I don't know why the new voice over doesn't play.
I am dispatching an event from one document class and listening for it via another document class.My code in class A.
Code:
this.dispatchEvent(new MYEvent(MyEvent.APERTURE_DONE));
trace("Dispatching APERTURE_DONE");
my code in class B.
Code:
addEventListener(MyEvent.APERTURE_DONE, onDoorsOpen,true);
trace("Lisetning for APERTURE_DONE");
[code]....
My listener is registering before the event is dispatched, based on my output window, however I never get the "Open Doors" trace statement to fire.
I have a FLA (say Main.FLA) document class with a child MovieClip on the stage: into the child MovieClip I load other swf files: each of the files contains its own Document Class (every swf is a somewhat independent application, say quizzes and so on).For some reason I must use the Main document class to store data (scores or so) from the child swfs loaded into the Main swf. HOW do I reference the Main class? I can't find a way.[code]and dispatch an Event this way from the loaded swf document class to the Main class:[code]Now, first of all I don't know if this could even work. Secondly, I tried to make it work by adding an event listener to my Main class but id did not work.
View 9 RepliesSo I had a working .fla, with a document class package in the same directory. Everything was fine, until moving both to a new directory, now the fla cannot find the document class. WTF?
View 2 RepliesI'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]......
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.
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;
}
I'm passing a DisplayObject to a command that will instantiate it. Something like this:
// ViewClass is passed into this method typed as a Class
var view : DisplayObject = new ViewClass() as DisplayObject;
Is there a way to pass arguments to ViewClass() without knowing it's type? I'm assuming the list of parameters passed to any object's constructor is an array, but I'm not certain how to proceed.
I know I can do something like this:
// Assume arguments, an Array of arguments, has also been passed in
var view : DisplayObject = new ViewClass(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]) as DisplayObject;
But clearly I'd like something more dynamic, like to be able to just pass the arguments Array directly. I suppose all of this, however, goes against any type safe checking
Is it possible to pass constructor arguments to instance objects which I place on the stage? Are the instantiations of instance objects centralized somewhere as with .NET WinForms so I can just edit the xxx = new CustomRecangle() constructor?
public class CustomRectangle extends MovieClip {
public function CustomRectangle(width:int, height:int) {
this.width = width;
this.height = height;
}
}
I've got a function wich can accept a varible number of parameter with a rest operator. I want create an object passing the argument collected with the rest operator directly to a constructor without create an object and call an initializing function and without passing the entire array but the parameters ah I do with apply() function.
[Code]...
Is this possible ? If yes how ?Otherwise what's the alternatives ?
By dynamically I mean using
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading);
[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 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 the topic of "duplicating" movieclips is a hot issue with the new virtual machine. Luckily, I understand the implications. I only am [currently] interested in duplicating a Bitmap. See, I load an image from an URL using 'flash.display.Loader.load', which is a non-blocking operation in Flash Player.However,I may use multiple copies of the loaded image (which is reported to be a Bitmap, naturally) in the display list at the same time.Hence, I naturally do not want to load the image from an URL every time, because I don't want to wait for a non-blocking call to complete. Nor do I need to - I mean one copy is already loaded, so it should be possible to just "duplicate" it, right?
My idea is to do use the bitmapData property of a Bitmap and pass it to the constructor of a new Bitmap object. I have not tried the following in action, but I want to hear whether any of you did and if the following would not work, what would:
Code:
var original_bitmap: Bitmap;
var copy_of_original_bitmap: Bitmap = new Bitmap(original_bitmap.bitmapData);
LiveDocs mention that the BitmapData being passed to a Bitmap constructor is "being referenced", which to me might suggest it cannot be used twice? There is also the BitmapData::clone() method, which I am not sure is applicable here or not.I know this is a lot of talk instead of just trying this out, but I test so much Flash Player code daily just to see "what works" (which should be documented instead by Adobe),
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].....