actionscript-3,class,actionscript,superclass , When using the 'Class' datatype, how can I specify the type so I only accept subclass of a specific class?

When using the 'Class' datatype, how can I specify the type so I only accept subclass of a specific class?


Tag: actionscript-3,class,actionscript,superclass

I've got a method that accepts a parameter of type Class, and I want to only accept classes that extend SuperClass. Right now, all I can figure out to do is this, which does a run-time check on an instance:

public function careless(SomeClass:Class):void {
    var instance:SomeClass = new SomeClass();
    if (instance as SuperClass) {
        // great, i guess
    } else {
        // damn, wish i'd have known this at compile time


Is there any way to do something like this, so I can be assured that a Class instance extends some super class?

public function careful(SomeClass:[Class extends SuperClass]):void {
    var instance:SuperClass = new SomeClass();
    // all is good


If you are going to instantiate it anyway, why not accept an object instead which allows you to type it to :SuperClass?

careless(new SomeClass);

Not too much of a problem there as far as your code goes. There are a few differences though:

All that is solved by the factory pattern. Pass a factory as the parameter that produces SuperClass objects.

function careful(factory:SuperClassFactory)


Is there a class in AS3 that tells you the type of the URL protocol?

Is there a class in AS3 or Flex that tells you the type of protocol a URI or URL is part of? I was sure there was a class that broke a URL into various parts and grouped it into usable data. For example, if the URL is, "mailTo" it...

Python class design: explicit keyword arguments vs. **kwargs vs. @property

Is there a generally accepted best practice for creating a class whose instances will have many (non-defaultable) variables? For example, by explicit arguments: class Circle(object): def __init__(self,x,y,radius): self.x = x self.y = y self.radius = radius using **kwargs: class Circle(object): def __init__(self, **kwargs): if 'x' in kwargs: self.x = kwargs['x']...

My simple php class not working [closed]

I wrote a simple class. but its not working. Something is wrong. can't find error line class Host { public $scheme; public $hostname; public $www; function __construct(string $scheme,string $hostname,string $www) { $this->scheme = $scheme; $this->hostname = $hostname; $this->www = $www; } public function get_URL() { return $this->scheme.'://'.$this->www.$this->hostname; } } $site...

Dynamic Text doesn't show up through code

if I make a dynamic text on the stage, name it something like "output" And I write in the enterframe. output.text = "Something"; It doesn't even show up in the stage, and the text box is blank....

Global class comparison with inheritance

I am writing global class comparison functions with operator== for a large framework where classes tend to inherit several classes or have deep inheritance (class A inherits from B, B inherits from C, etc.). In order to make things manageable I figured I would have a comparison functions for base...

React components as plain JS objects?

Does anybody has experience in working with React components as plain JS objects instead of annoying ES6 classes and deprecated .createClass method. Maybe you have some examples of factory functions or similar to share? Thanks!...

Are interfaces a valid substitute for utility classes in Java 8? [duplicate]

This question already has an answer here: Java 8: Interface with static methods instead of static util class 4 answers For the past decade or so, I've been using the pattern below for my Java utility classes. The class contains only static methods and fields, is declared final so...

Is a Java class variable a reference to a class object?

I know such question has been asked before but I couldn't find a satisfactory answer. Assume a java class : class Foo{ public int k; Foo(int a){ k=a; } } class My{ public static void main(String args[]){ Foo obj = new Foo(5);//1 obj=new Foo(8); //2 } } I want to...

Do scala classes have “self” like Python?

For example if I have object Solution { class myClass(A: Array[Int]){ val something: Int = A.length; val another: Int = something/2; val someName = "blah" ... ... Do these variables "exist" only for a particular instance of myClass or are they "class-wide" variables shared among all objects? If it's the...

how to fix error 1009 in as3

hi i have been searhing the net for hours and have not found a solution to my problem and i have no idea how to fix it as i am only new to flash so if you know anything that might help me just comment below please all help is...

SigninActivity is not an enclosing class

I'm trying to change the activity on "onPostExecute" but it doesn't seem to work even though it works on other activities. Here's my code: public class SigninActivity extends AsyncTask<String,Void,String>{ private TextView statusField,roleField; private Context context; private int byGetOrPost = 0; public SigninActivity(Context context,TextView statusField,TextView roleField,int flag) { this.context = context;...

Downcasting doesn't work and functions called from object own class instead of where the function is (Java)

i have this classes hierarchy: public class Musician { private String name; public String instrument; public Musician(String name, String instrument) { = name; this.instrument = instrument; } public String getName() { return name; } public String getInstrument() { return instrument; } private String getClassName() { return "Musician"; } public...

ActionScript: How to listen for an event from a different XML

I have a popup screen in which the player enters their name and clicks OK. When OK is clicked I want the player's name to be passed to the main XML. How can I do this? Here is the function in the main XML that handles the popup: private function...

Issues with Array calling on classes

Day two of my journey into the world of java and I have seem to run into a road block even after scouring this wonderfully helpful website. So precontexual 411: I want an array of an unknown length to create its entries by calling on classes. I have the strangest...

converting XML data into an array of objects AS3

I'm using Flash AS4 and Ive created and array that holds xml data which works fine with the following loop for(var i:int = 0; i < uNavXML.length(); i++){ navArray.push(uNavXML..navRef.text()[i]); The XML data is actually the names of movie clips that I have on stage: xmlLIST :<uNav> <unavNavID>1</unavNavID> <navRef>navBtns.nav01</navRef> </uNav> <uNav>...

PHP get value from function called by constructor

I have a feeling I'm overlooking something simple but I can't figure out how to get a value from a function that is called by the constructor within my class. The below is a very simple example but, essentially, I need to use the userId value on my index.php page...

How to convert preg_replace from PHP to AS3?

I'm doing a fan Transformice map editor, but I've a question, "How can I do a preg_replace in Flash AS3?"... This is something like <? $mapXml = "<C><P /><Z><S><S L="304" H="65" X="175" Y="355" T="6" P="0,0,0.3,0.2,0,0,0,0" /></S><D /><O /></Z></C>"; $mapXmlDisplay = preg_replace('<S L="(.*)" H="(.*), etc..."', 'someThing', $mapXml); ?> It's possible? Thanks...

ToInt32() conversion [on hold]

Like ToStr() method, I am trying to convert to Int32() as following: class customer { public int ID { get; set; } public string Name { get; set; } public override int ToInt32() { return this.ID; } } Compiler is complaining about ToInt32() as no suitable method to override. Help?...

jQuery create a real-time array from multiple inputs with the same class

I have multiple inputs on a page that all have the same class name authority-email. Using jQuery I get the values from all the inputs using the following: var emailObj = {}; $("input[class=authority-email]").each(function () { var email = $(this).val() emailObj = email; console.log(emailObj); }); These inputs can be removed and...

C++ call a child's method from a vector of parents?

Say that you have the following class: class Parent { // methods and members go here }; then you create a child based on the parent: class Child : public Parent { public: someFunction(); }; Now class Parent doesn't have someFunction() but class Child does. Say that you have a...

How to share an instance created in main with a class in another module

I am having a problem with how to share a class instance between modules. Below is not the actual code, it is a simplified representation of what I'm trying to do. The variable in question is thePlot. If I make it a global, I get 'global name not defined' type...

Error #1502: A script has executed for longer than the default time period of 15 seconds

this is my first time using AS3 so I apologise if the cause of this problem is painfully obvious. I'm making chess and I've got a class for each piece on the board. When it's player 1's turn, all the black pieces should wait to be clicked, but when I...

Can you put a pimpl-Class inside a vector

I have a class implemented using the PImpl Ideom: class FooImpl {}; class Foo { unique_ptr<FooImpl> myImpl; public: Foo(); ~Foo(); }; And now I want to put this into a std::vector void Bar() { vector<Foo> testVec; testVec.resize(10); } But when I do that, I get a compiler error (VC++ 2013)...

Sending a Class' attribute to an outside function in the function call

I'm trying to generalise a function in my script by sending in the Class' attribute through the function call to an outside function, but since I have to call the attribute self.attribute_name inside the class and outside it, I either get an error that no self.attribute_nameexists outside the code...

Why isn't this php math code working

Hey guy's so am trying to convert this as3 code to php but its not working correctly i need it like the as3 one generating thanks! PHP: print(floor(rand() * 1000) + 3000); Result:28240000 AS3: var intCID = Math.floor(Math.random() * 1000) + 3000; var strSessionId = String(intCID); trace(strSessionId); Result:3330...

AS3: Fast hovering doesn't execute rollOut

I'm having a serious problem that is getting me nervous: I've made a button _btn that includes ROLLOVER and ROLLOUT animations with coding (an nested movieclip instance called barra that increases to half alpha when you hover over and decreases when you hover out). [Here it should go a descriptive...

Map a JSON object to a Javascript class

I want to know the "good practice" to map a JSON object to a Javascript instance Class. My example is that I have a database of Cards in a JSON file. Each Card has several attributes. I have a Class Card that has the same attributes plus several methods. How...

type conversion if flex

I am using Flerry as Java-Flex bridge for my Flex Desktop Application. How to convert List in Java to ArrayCollection in Flex Flex Code:- [Bindable]public var screenList:ArrayCollection; <flerry:NativeObject id="windowControllerObj" source="ls.window.EnumAllWindowNames" singleton="true" fault="windowControllerObj_faultHandler(event)"> <flerry:NativeMethod id="getWindowNames" name="getAllWindowNames" result="windowControllerObj_resultHandler(event)" fault="getWindowNames_faultHandler(event)"/>...

Laravel5: Access public variable in another class

I have a middleware file called LanguageMiddleware.php: ... class LanguageMiddleware { //ISO language codes: public $languages = ['en','es','fr','de','pt','pl','zh','ja']; ... LanguageMiddleware.php is in laravelProj/app/Http/Middleware/ Here's my problem: I have a blade template file called master.blade.php where I'm attempting to output a list of languages @foreach (App\Http\Middleware\LanguageMiddleware\languages as $lang) <a class=\"setLang\" href=\"lang/en\">{{...

AS3 : How to compare 2 array containing objects using 1 for loop only?

I have 2 array having objects of different length var arr : Array = [{name : "aa", id : "0"}, {name : "bb", id : "1"}, {name : "cc", id : "2"}]; var arrTemp : Array = [{name : "ee", id : "0"}, {name : "hh", id : "1"}, {name...

action script 3 whole number as a division output

hello, I want to get whole number after division. x = 3/2; //results x = 1 and not 1.5 how to do this in as3??...

Fighter class does not implement interface member

And I am getting this error: Error 1 'Fight.Fighter' does not implement interface member 'Fight.IFighter.Utok(Fight.IFighter)' This is the first time I am trying to learn working with interfaces, so sorry for dump question. Any ideas? I have following code: Interface: interface IFighter { string GraphicLife(); bool IsLive(); int Obrana(int utocneCislo);...

How to know fast if another computer is accesible in AS3 (Adobe Air)

I'm using FileStream to read files in two computers that are connected in a Local Area Network (LAN). I have no problem to read the files when the others computers are connected. I'm checking if the directory exists before writing the file I'm checking if the directory AND the file...

ActionScript: Specification of the is operator

I am having trouble googling for the expected behavior of the is operator in AS3. What I need to know is what should happen if the left side is null. I know it is possible to test, and get empirical results, but I need to know what the specification says,...

Method nonvisibility of same instanceof but differing class

I have something like the below: Item var; Depending on user input, it will be initialized as a different class: if (/*user input*/ == 1) { var = new Item(); } else { var = new Truck(); } The classes are defined as: public class Truck extends Item { public...

When to use pointer member variables?

I realize this is a very basic question but I'd like to see an example of when I should be setting some of my class member variables as pointers. I saw this class definition: template<class T> class Node { public: T data; Node<T> * next; Node<T>(const T& d):data(d), next() {}...

How return ID or all from another class with Entity Framework?

I learning Entity Framework, so don't blame me if this is easy for you I have class HomeNumber.cs [ScaffoldColumn(false)] [Key] public int HomeNumberId { get; set; } //[ForeignKey("HomeNumberId")] //public virtual HomeNumber HomeNumbers { get; set; } [Required(ErrorMessage = "Polje kućni broj je obavezno!")] public string HomeNumberName { get; set; }...

How make with AS3 downloading MP3 files in the background mode and plays it?

I need help with AS3 make downloading MP3 files in the background mode. Man goes to my site and it will automatically load MP3 file on his computer and plays it. I read these examples here but do not know how to do it? Prompt what code and how...

Can I make class accessible by the entire project?

I am making a small application, for which I want an error system. Just a really simple window that pops up, with the specified error and exit number. For that I have made a "Message" class, that makes a JOptionPane with the message, that all works like a charm. But...

Convert String to the name of a array in another class

I'm a amateur programmer and I'm wondering if it's possible to solve a problem in a specific way. public class Stats { public static int[] Hero = {20, 20, 10, 10, 10}; public static int[] Villain = {20, 20, 10, 10, 10}; public static void name(int[] name) { //If you...

In Java, How do I cast a Realm Object into the class I wish to write to the Database?

I am currently working on a project where my Database has a very large number of tables (Approx 60 total). I am working to create the Database Helper class that will function as the writer/ reader to/ from the database. And example of my write method would be this: public...

AS3 can't find the load method on a Loader

I'm trying to load an image from the internet with AS3 following this tutorial. When I try to compile the application I get the following error: Call a possibly undefined method load through a reference with static type Loader. my_loader.load(where, loaderContext); ^ Here is the code I'm using: package {...

A movie clip above a simple button makes it unresponsive

I have designed a menu in Flash CC which consists of several cloned buttons and an MC containing the text that is supposed to stay above the buttons. Each time a user switches the menu's page, AS commands the clip to switch to appropriate frames, therefore changing the text above...

AS3 LocalConnection: function is not firing

I'm building an AIR app that sends text string to a swf-file. When I export the sender and reciever apps to swf and run them in Flash players, everything works well. But when publishing the sender app to AIR things don't work anymore. I think the connection works, because there...

Building a digital signage platform in HTML5

I need some feedback! So if any help, Thank you! I'm a developer for a digital signage company. We built a platform in Flash (ActionScript 3) and it has been running really smooth for a few years now. We've been talking about trying to move to HTML5, JQUERY and PHP...

Call known function (with parameters) in class whose name is defined by string variable

I have a bunch of classes of various names and each has a performLogic function that accepts a number of preset parameters (always the same): public final class DoSomeAction extends SetupAction { public void performLogic(param1, param2... I want a way where I can call it like this: String actionName =...

Interpreting hex dump of java class file

I understand the structure of a java .class file, but when I want to interpret the raw hex data I get a bit lost. This is a hex dump of a class file, excluding the header and constant pool. I understand the header to be the magic number, minor_version and...

Adobe Flash CS6 AS3: KeyUp Handler triggers immediately after KeyDown Handler

So in my code I was attempting to make it where you had two players, each player had their own key down and key up handlers, clearly labelled in my attached code, and in their I handle the movement, player one has WSAD and player two uses the Left, Right,...

Silex namespace : class MainController does not exist

I try to use Silex Framework, but i have a problem with namespaces I think. when I instanciate my class MainController i have the following error : Class "MainController" does not exist here the namespace declaration in my MainController.php : namespace App\Controllers; use Silex\Application; class MainController implements \Silex\ControllerProviderInterface { .......

Java immutability when defining members in a function called by constructor

I have class like this: abstract class Parent { protected Parent(Raw rawData) { deserialize(rawData); } protected abstract void deserialize(Raw rawData); } class Child extends Parent { final byte firstByte; public Child(Raw rawdData) { super(rawData); } protected void deserialize(Raw rawData) { firstByte = rawData.getFirst(); } } So basically any child class...