ActionScript 2.0 :: Predefined Arguments In A Constructor?
Nov 21, 2005Is it posible to have predefined arguments in a constructor so if the user doesn't enter one it takes the default value? I tried doing it this way:
[Code]...
Is it posible to have predefined arguments in a constructor so if the user doesn't enter one it takes the default value? I tried doing it this way:
[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]...
I'm having a weird behaviour with some some classes that I'm making. It seems that the Boolean values from arguments get changed on the way. I have two classes. On is called Carousel and the other Activity. The Carousel main task is to instantiate several Activity objects and place them in a way that resembles a carousel. This part is done, but there's a problem passing arguments from Carousel to Activity. Some data to instantiate the Activity come from an XML file. The XML resembles something like this:
[CODE]...
I'm making a game in action script 3. In it, I have an actor class from which player and enemy classes will be derived. I'm doing this so that unless I need to provide specific AI or fancy behavior (such as for bosses), I can just make a new clip in the library for each enemy without making an actionscript file.
However, I've run into a problem.
Whenever I try to pass arguments to the construction of an enemy (make it spawn with more health), I get error 1136 (Incorrect number of arguments.)
This is because the constructor created automatically at runtime doesn't have the same arguments as it's parent class. Is there any way to get around this without making a class file where I copy and paste the parent constructor function for each of my hundreds of enemies?
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
I've drawn a pretty button in Flash and given it the Class name PausePlayButton. It extends PlayerController, which allows it to toggle on and off and control whether a MovieClip is playing or not.When I instantiate it, I want to pass a reference to the MovieClip it controls into the contructor so that PlayerController has access to the MovieClip's public methods. However, I can't pass a reference into the constructor of PlayerController, unless I can pass it into the constructor of the symbol itself and call super. But where is that constructor? How do I give the button a reference to another object?
View 1 RepliesI have created a class:
Code:
package net.icsna.website
{
/**
* ...
* @author Kyle McKnight
[code]...
And then I create a new instance of the class:
Code:
var scroller:Scroller = new Scroller(_contactDisplayPage.getChildByName("contactInfoHolder"));
And I'm getting an error 1136:Incorrect number of arguments. Expected 0...
I'm having trouble with the constructor for a custom Class tied to a library MovieClip.
Say I have a MovieClip in my library named Circle, which is tied to the class com.shapes.Circle . I want the Circle class contstructor to take 2 arguments, xScale and yScale:
public function Circle(xScale:Number, yScale:Number) { }
However, if I try to call that from in code, for example Circle ball = new Circle(3.14,2.0); , I always get an "Incorrect number of arguments. Expected 0" error.
Is it possible to have a custom class tied to a MovieClip that can take arguments, or does Flash not allow this? I'd asked about this before and thought I figured it out, but from looking at it now I apparently hadn't figured it out and had resorted to a sloppy workaround; I'm hoping to fix it now.
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]
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 like finding out about tricky new ways to do things. Let's say you've got a class with a property that gets set to the value of an argument in the constructor, like so:[code]That's not exactly a hassle. But imagine you've got... I don't know, five properties. Ten properties, maybe. Rather then writing out each individual assignment, line by line, isn't there a way to loop through the constructor's arguments and set the value of each corresponding property on the new instance accordingly? I don't think that the ...rest or arguments objects will work, since they only keep an enumerated list of the arguments, not the argument names - I'm thinking something like this would be better:[code]
View 2 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.)
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 have a class with constructor and overloaded methods in it. When i try to import that class using blazeds i get an error saying [RPC Fault faultString="Unable to create a new instance of type 'some class'." faultCode="Server.ResourceUnavailable" faultDetail="Types cannot be instantiated without a public, no arguments constructor."] How to import class having overloaded methods using blazeds
View 1 RepliesI have a "format" method that works in a similar manner to the C# String.Format method, with the following signature:
[Code]...
I've got a movie clip that's basically a grid with small little boxes that total 84 rows, and 20 columns...I'm trying to get the user to be able to snap to the y position of one of the small little boxes.You click on a square, and position it over one of the small boxes in the grid, but it always snaps "wrong". I've tried --square_on_grid.y = Math.round(square_y/g_gridSpacing) * g_gridSpacing;
View 7 RepliesI have been working on this for several days and I cannot get the right results. Im trying to load an external SWF into a predefined area or in this case a box on a frame. my script is
loadSWFFile();
function loadSWFFile():Void
{
[code].....
i have a small challenge calculating and evaluating a predefined path
here is my challenge in short.
- i got a path as a single color line on a white background (bitmap object but could as well be a vector shape)
- the path is a closed loop path (like a twisted and bend circle, let's call it a bean shape).
- i then need to move an object along this path in x steps but only once and stop exactly where it started
This means, i need to:
- find a start end point
- calculate the length of the path
- set keynodes along the path with X amount of spacing between (length/x)
- it got to be semi precise (within 1-2 px.)
one idea could be to loop throught the pixels till to find a color pixel and use this as the starting point, then use an vector with a predefined length (ex. 5 px) "rotate" it till it find a new color pixels and mark this as a new node, repeat the process till you get close to the starting point, and by using Trial and error you'll eventually have mapped the path, but this method is clumsy and not very accurate, if you don't hit the starting point spot on the first time, you'll recalculate everything over again.
I am trying to create a script that spawns cubes with one second (30 frames) delay, then places it into one of the 10 predefined positions.
spawnTimer = 0
function onEnterFrame()
{
[code].....
List all of the global variables that are predefined by Flash ActionScript 3? For example, like the current time, or the current frame, etc.?
View 2 RepliesDoes anyone know any good tutoriols on how to create a "slideshow" or "playlist" in ActionScript3? The slide can be either a simple picture, a soundfile or a video. I want to be able to jump back and forth in the slideshow/playlist, and also see how long a slide will be shown. The playlist will be loaded from a pre-defined XML-file.
View 1 RepliesI am trying to create movieClips in a loop based on a predefined amount. most importantly I want to have the variables defined as btn1, btn2, btn3 etc.
this is what i have done but i don't know how to put the number as part of the variable(i have all of the other code in place such as the languagesIndex set etc - this is the part of the code i am working with)[code]...
Code:
onEnterFrame = traceMe("test")
traceMe = function(param){
trace(param)}
If that won't work then would someone explain how you get something to execute a predefined function and pass a variable...
I'm using Flash Catalyst ( Sorry i�m not sure if there�s any difference between code written in Flash and Flash Catalyst) and I want to implement a link to an external html-page...But I�m trying to open the link at a predefined window size, like a popup! I have found a code in the net but it�s not working.[code]...
View 1 RepliesIs there anything to opposite of setMask. Actually I want that, when I click a button then a movieclip will be masked by some predefined shape (working as mask object). when I click another button he mask will be gone. That means the object under the mask will go out of the mask.
View 1 RepliesI'm trying to build a functionality into a Flash app, which would calculate the number of days that have passed since a defined date.
The idea is that a start date would be defined in the script (in whatever format) and the application would count and return the number of days since that date. According to that number the app would determine the availability of a set of links listed in the style of a calendar. I'm gonna be using a date variable from my servers to determine the current date.
How should I proceed with this? How should the varying number of days in months be handled? What about leap year?
I need to create a small dice game in Flash. The random number generator is external and I have to create a 3D realistic dice animation with that outcome. I'm using Away3D engine and JigLib for physics. So far the best idea I've had is to do many simulations and create a list of outcomes and their corresponding input parameters (initial position, initial orientation and the forces added to the RigidBody). This is not working so well. Sometimes for the same parameters the outcome is different. What is the best way to do this?
View 1 RepliesIm giving a action script for drawing a predefined process shape that is used in flow chart. There are action script to draw a square, rectangle, circle and triangle. Can anyone in the forum give code for drawing the shape.
View 1 RepliesI am new to Flash & ActionScript 3.0 platform.My issue is: I am loading an image onto the stage dynamically using Loader & URLRequest classes. Whenever I click on existing circle[which gets created when I click on the loaded image, which is of Sprite type], the size of the circle should be increased to some extent(let us assume, basically circle(Sprite)is created with radius=3 when we click on the image, but, when we click on the created circle, it's radius must be increased to 5). It is the requirement.
So, for this to implement, Do we have any property or method to change the Sprite object's size directly?
[Code]...
I am working on an application in which i have put one Multi line input text box. I want to allow user to enter data only up to 8 Lines. User can not enter more than 8 lines. So is there any solutions..??? I dont want to use MaxChars as it can restrict user to not enter more than predefined number of characters. I want to restrict user from entering more than predefined number of lines.
View 4 Replies