Actionscript 3 :: Passing Custom Class As Parameter To Custom Class Where Parameter Class Not Constructed?
Jun 16, 2011
I have a custom class being constructed from my main class. In the custom class it has another custom class that is passed in as a parameter. I would like to strictly type the parameter variable but when I do, 'the type is not a compile type constant etc'.This, I understand, is because the custom class used as a parameter has not yet been constructed.It all works when I use the variable type ( * ) to type the parameter.I suspect this is a design flaw, in that I am using an incorrect design pattern.It is actually hand-me-down code, having received a large project from someone else who is not entirely familiar with oop concepts and design patterns.
I have considered using a dummy constructor for the parametered class in my main class but the passed in class also takes a custom class (itself with a parametered constructor). I am considering using ... (rest) so that the custom classes' parameters are optional.Is there any other way to control the order of construction of classes? Would the rest variables work?edit)in main.as within the constructor or another function
var parameter1:customclass2;
customclass1(parameter1);
in customclass1 constructor:
If I set my variables as type MovieClip instead of the type of the class for the MovieClip I am calling them as, will this affect my presentation in any way? Say I have a movieClip Walls with a class definition Walls. Will
var newwall:MovieClip = new Walls(); or var newwall = new Walls(); be any different than var newwall:Walls = new Walls();
In class Main I am instantiating a custom class NavLabel that creates a textField. With in NavLabel I dispatch a custom event CustomEventWithParams on a reference to class Main that passes the parameter theLabelWidth along with it. from with in class Main i can trace the theLabelWidth for each of the instantiated NavLabel objects. I want to hold those values in an array labelWidthArray and then use them to position the NavLabel objects. how can I do this?
I'm trying to create a class which will create a tween for several different instances of an object. I am creating the instances in the Document Class. The trick is, I would like to specify how long each tween will take.
As you can see, I have a variable "myTime" which syncs the timer and the tween. This causes to tween to repeat and the clouds to continually scroll across the stage. How can I determine the var myTime at the time I create each instance of the Movie Clip mcCloud?
I am calling java servlets from flash using the following code [below is a sample Flash code for calling a java servlet in Flash which I am using]: String url_String="[URL]"; var req:URLRequest = new URLRequest(url_String);
In this case, the servlet is called/working fine only in my system where the flash application is deployed & not working when I execute the application in different system using the "IPAddress" of my system. So, What changes I need to make in above Flash code in order to call the same servlet successfully from my system and as well as from other systems? (OR)
Is there any need to pass the servlet-url's relative instead of absolute? If so, How can we pass relative-path of url's in Flash? && Can anyone explain me with an example? How to change my above code to pass the url 'relative' rather than 'absolute'? If I pass the url relatively, does my issue gets resolved?
I need to pass a struct and a string in a web service. I am using a WebService components to do so.upon my search, there is no struct type in actionscript and so I used a class for that one.
public class UserInfo{ public var name:String; public var dateAdded:Date; }
and I'm filling it up so that I can pass it on the web service like this:
var newUser:UserInfo = new UserInfo(); newUser.name = "myName"; newUser.birthdate = new Date(); webServComponentId.operationToCall(newUser, "password");
Upon sending this request, it prompts me an error of Error #1088.
the component that is being called by webServComponentId.operationToCall(newUser, "password"); is this:
I'm working on an accordion component and I was thinking that it'd be cool if I could write a very basic one and then set it up so that it would be possible to pass in any kind of container class and child class so long as they subclassed a particular parent or implemented an interface (haven't really gotten that far yet).
What I've noticed though is that I can't setup a default class for my constructor parameter. For example I'd like to do this:
Code: public function DropDownList(containerClass:Class = ContainerSprite, childClass:Class = ChildSprite) However it gives me the following error: 1047: Parameter initializer unknown or is not a compile-time constant.
I am new to AS3, as well as Flash in general, so forgive me if this seems highly elementary. All I am trying to do is create a custom class that extends the MovieClip class and contains a custom property of "marker". I want to be able to use and change the value of this custom property on the timeline for an instance of this class and have it behave just like any other (Ex: this.x ==> this.marker).
I have a custom function with parameter. I'm trying to pass the parameter to the gotoAndPlay as follows. This is where the function is called...
Code: myButton_btn.onPress = function() { myFunction("Apply"); } This is the function... Code: myFunction = function (fLabel) { trace(fLabel); gotoAndPlay(fLabel); }
Basically "Apply" is a frame label that I'm trying to send the playhead to. The fLabel paramater traces out properly, but the gotoAndPlay doesn't send the playhead to the appropriate frame label. It sends it to 4 frames before the end. It's really weird. Even if I add frames to the timeline, it still sends it to 4 before the end. I can get it to work perfectly in a "new" flash document, but not in my existing document.
This is my first time working with a class attached to a movieclip that is nested inside a class attached to a movie clip.I've tested all the properties and methods of PTListItem.as and they work properly but when I try to call them on the list item through PTListTop.as it returns undefined.The end goal is to dynamically load a checklist via a txt file.
I have created a custom class. It seems to work (at least no errors), but when I create a button in the actual FLA that calls on the class, it doesn't change what I want it to change. Here is the class:
[Code]...
When I call for the class to make the button, it works. It also successfull calls the default.png from the class, but in the FLA the icon_retrofit.myIcon doesn't change the image to 'images/b.png'.
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.
Im a complete beginner in Flex programming. I have an application with a main .mxml file, and a certain class Foo that I call from the .mxml. In Foo, I make a URLRequest and listen for the Complete event. Then I found myself with the returned data in a Foo function, but I have no idea how to communicate it to the .mxml part of the application ! I looked into ArrayCollections but I can't seem to understand how they work. Isn't there a way to modify, from inside the class, a variable with a global scope ?
If I have a Document class that extends MovieClip, and I want to use it as the basis for another Document class, is it possible to create a subclass that extends the main document class and use that for a different FLA?
For example,
fla1.fla has a document class of MyMainClass: public class MyMainClass extends MovieClip fla2.fla has a document class of MySubClass: public class MySubClass extends MyMainClass
I've tried, but now I'm getting errors that all of my variables that reference stage instances aren't being found.
get a bunch of objects in my library to inherit from (or even be) one class that i have made, but without having to make .as files for every single one is this possible, or is there any other way to give objects another classes functionality in an auto-generated class?
I keep getting an "undefined property" error when I try to call an external function from within the Doc class. I added the error message to the Doc Class below so you can see where it occurs.
If I take the code from the Tooltip.as below and place it on the FLA's main timeline I can get things working fine, but I would like to move all script to classes. The document class structure looks like this:
Drag_and_Drop.as
Code: package { import Tooltip;// Import custom class public class Drag_and_Drop extends MovieClip {
[Code]....
I realize that I could just combine all the code in the Doc class to get it working, but it would be nice to separate out this particular code which has only one use.
the website I'm work on has the document class Main. Within this website I have a movieclip on the stage which I built a custom class for its functionality and I linked this movieclip to this class to make it work. There is no reference to this movieclip or class in Main.
Now, I need to communicate between these two classes. Can I do this? Can I dispatch an event from the custom class linked to the movieclip and have the document class listen for an event? How?
I have a document class called Main.as In the class constructor I have the following listener:
enter code here var listeningFORModeChangeToStudent:Sprite = new Sprite; listeningFORModeChangeToStudent.addEventListener(TellAllModeChangeToStudent.STUDENT,exp); addChild(listeningFORModeChangeToStudent);
[code]....
In a third class I make a call to the despatcher in the previous class:
enter code here var ThisTellAllModeChangeToStudent:TellAllModeChangeToStudent = new TellAllModeChangeToStudent; ThisTellAllModeChangeToStudent.tellAllModeChangeToStudent();
I have trace statements in eveything and from this I know the despatcher in TellAllModeChangeToStudent is being called.The problem is that the listener in the main.as is not calling the function exp.I cant see why and I dont know how to check if the listener is actually seeing the dispatch event?
I understand it's probably best practice to name your custom classes differently than the built-in AS3.0 classes; however, what kind of problems could I run into if I don't?Specifically, I have a class which, ideally I want to name DataProvider. But, as you know, there is already a DataProvider class on the Flash platform (used for list-based components and such).Now, I don't think I'll ever use BOTH of those classes, so I'm assuming as long as I reference the correct DataProvider class in my import statements I should be ok?What if I DO need to use both, is that even possible?
I want to dispatch a custom event from the Country() sto the MenuButton();[code]When a country is hovered a custom event is dispatched which I want the MenuButton to listen and if the parameter passed is the same as its name to get highlighted. The Country Class is the Base Class for my countries movieclips I have on stage and the MenuButton the Base Class for the menu button.
In a nutshell I have a custom event that I am dispatching from one class that is not getting picked up by the other class even though i have added the appropriate addEventListener calls on its constructor.Here's how the classes are laid out:
The NetworkManager class extends the MovieClip class as does the LoginScreen and Application classes as well.Now within the oLoginScreen class I dispatch the ValidateCredentialsEvent by calling it this way:
ActionScript Code: dispatchEvent (new ValidateCredentialsEvent(ValidateCredentialsEvent.VALIDATE_CREDENTIALS, oLoginData, true, false));
Then when I debug the code, I can step through and see that the ValidateCredentialsEvent is being generated but it is never picked up by the oNetworkManager class whatsoever.Is this occuring because the NetworkManager and LoginScreen classes are children of the Application class and because of this can't capture events raised by one another without using the Application class as the intermediary to redispatch these events? My whole idea here was to create a generic network managing object that could be called from anywhere within the application, by any object, using custom events.
Im trying to use an AS3 modification of gskinner's collision detection class, but this being the first custom class i've ever tried to implement, i dont what i'm doing.How do i implement it into my flash? Do I just put it in the same folder as my .fla and .as?Do i have to initiate it in the main class?From what i understand it creates a rectangle, what would i need to turn it into a simple true/false?
I'm not allowed to import classes into other classes but I am not sure how to achieve what I want. I want 2 custom classes to pass data one from another directly. I have 2 custom classes I want to use: one extends the XMLSocket Class:
class Game extends XMLSocket { import XMLParser //not allowed to do this I know! var parser:XMLParser = new XMLParser();[code]....
As I say I realise I am not allowed to import the parsing class into my Game class (or any class for that matter) but I don't know how to pass data directly between these two classes without referencing them in the main FLA.
I have the following situation:I have an event handler, that displays small messages in my application's statusbar.These messages get passes through by dispatching events from custom components.A simple message could be like "HTTP Error" or so.Now, the main event listener, in the main application file, listens to the event dispatched by any custom component,but seems to refuse listening to events dispatched by custom AS classes.Here is my code for the custom event:
package components { public class templateSelection extends VBox { static public var tempSelectionBag:Dictionary;
[Code]....
I want to have a custom class tempSelection with a Dictionary as a public accessable property of that class. If I use this code, the compiler tells me:
1046: Typ wurde nicht gefunden oder war keine Kompilierungszeit- onstante:Dictionary
Which translates to:
Type was not found or was not a compile-time constant: Dictionary