Questions about classes

Hi,
I finally upgraded from Flash 5 to CS3 - big difference :-)
Reading the first half of an ActionScript 3 book left me
quite confused about classes - what they are, how you handle
multiple classes, how you use one class from within another etc.
Are there any simple-speak tutorials out there that explain
more about how to use classes?
Specifically:
I am trying to use classes to run multiple animations at the
same time, i.e. using randomized movement for multiple objects on
my stage.
First issue is: If I do what I learnt in the book and simply
create one .as file and have that be the document class, how can I
prevent it from being run before all the elements on the stage have
been loaded through a slow network connection?
Second issue: I'd rather have "dormant" classes sitting
around and call them once my stage is ready, but I have no idea how
to handle multiple classes. I played with it for a while and then
gave up and put my code into a frame, but that caused further
issues. Again, any tutorials out there or any other advice you can
give me? I am trying to start some class code at a certain time and
use it to attach a Frame Event listener to a Sprite that I create
inside the class.
It looks easy in the book, but when I try to do my own stuff,
it just won't do it...
The book assumes (so far) that you want to run your code
immediately once your movie starts, but I don't want that...
Thanks!

Yes, I realized later that _root etc. is actually as1 code
from my days of Flash 5 :-)
All I need is to know how to access a movieclip on the stage
that was placed using the IDE from within a class, and how to
access a class and call its methods from within another, and I can
teach myself the rest...
So, if I place something with the IDE, doesn't it show up in
the display list? I should be able to control those elements, too,
shouldn't I?
Or do I have to use Actions rather than classes for those
elements?
I probably read 5 different articles/ebooks on the topic of
classes and OOP in AS3 already, and none gave me the answer I
needed.
But I will have a look at the site you mentioned.
Thanks!

Similar Messages

  • Question about Classes

    I have a question concerning classes. In my main program I have a list box. I have gotten the index (using getSelectedIdex method) from the list box to use with my array. What I want to do is match the list box index with the array index to get the correct price from the array. I can do this in the main class, but was wondering if I could just do the calculations in another class. Can I pass the index of the list box to another class in order to do the calculations? I figure I could put the array in the other class too and match them. In order to do this, what would the class data member look like for the list box index that I have passed? I have tried and get errors, so was wondering if there was another way I can do this
    Thanks so much for your help

    I have a question concerning classes. In my main
    program I have a list box. I have gotten the index
    (using getSelectedIdex method) from the list box to
    use with my array. What I want to do is match the list
    box index with the array index to get the correct
    price from the array. I can do this in the main
    class, but was wondering if I could just do the
    calculations in another class. Yes you can, but why? The only reason to do this from a design point of view would be to seperate the logic into another class so that;-
    1. you might reuse the class in the future.
    2. the main method class has become large and cumbersome making it difficult to find all the methods.
    3. There are a variety of methods and subroutines in your application so that the logic in your program will be improved in terms of readability and future maintenance by creating seperate class files.
    4. 'whatever' other reasons (?)
    Can I pass the index of
    the list box to another class in order to do the
    calculations? I figure I could put the array in the
    other class too and match them. In order to do this,
    what would the class data member look like for the
    list box index that I have passed? I have tried and
    get errors, so was wondering if there was another way
    I can do this
    Sooner or later the would-be java programmer has to change or make the transition from using java as a procedural language and develop programs along more OOP lines. The answer to your question is "yes of course you can do this" and simply from the point of view of learning how to pass an argument to a different class, then yeah, learn how to do this.
    >
    Thanks so much for your help
    Gazoontite xxx

  • Question about classes/Directories

    I've been using Java to learn programming for a while now, so this question may not belong here. It seems to be more of a general question, however, not code related.
    How does java work with directories? Say I had a project, and for some reason I wanted different java class files to be in different directories. How does java handle this? Say for example:
    1.) Main class is in C:/blahblah/Project/ and the other classes were in C:/blahblah/Project/src/?
    2.) Main class is in C:/blahblah/Project/src/ and the other classes were in C:/blahblah/Project/?
    3.) Main class is in C:/blahblah/Project/src/ and other classes were in C:/blahblah/Project/bin/?
    I know these may be kind of stupid examples, but I just wanted to know how such things worked for future reference. Thanks a ton!

    {color:#3D2B1F}It sounds like you need to learn about packages: [http://java.sun.com/docs/books/tutorial/java/package/index.html] {color}

  • MenuStrip and a Question about Class win32_product

    Hello,
    I have a bunch of questions I'm hoping someone can answer.
    1.) I would like to add a menu separator and a checkbox under a dropdownitem for a toolstripmenuitem
         Similar to what you would see in ISE or Internet Explorer.
         I then need to pass the state of this checkbox into a function
    2.) I have created a file menu item and would like to create a separator and then add a list of MRU items restricted to only displaying the five previous opened config files.
    3.) Can someone propose an alternative to using the get-wmiobject win32_Product class
    The below function I wrote to get the Product Version for some VMware products, but it is slow making the initial connection.   Looking at the Uninstall registry key won't work because it doesn't contain the product version.
    I know it looks odd.  I could not find a good way to detect which servers the products were installed on.   So instead I pass the servers that would host these products based on our build standards.
    Function get-version($vcenter,$sso,$vum,$credentials) {
    Write-Host "Getting Version information. This usually takes awhile. Be Patient " -NoNewline
    $Roles = "VMware vCenter Server","VMware vCenter Inventory Service","VMware vSphere Web Client","vCenter Single Sign On","VMware vSphere Update Manager","vSphere Syslog Collector"
    $i = 0
    $output = @()
    $Servers = "$vcenter","$vcenter","$vcenter","$sso","$vum","$vum"
    $ErrorActionPreference = 'silentlycontinue'
    ForEach ($input in $Servers) {
    IF ($psversiontable.psversion.major -ge 3) { Write-Progress -activity "Getting Version Information - Takes awhile. Be Patient." -status $Roles[$i] -PercentComplete (($i / $roles.Length) * 100) } Else { ticker }
    $object = New-Object PSObject
    $object | Add-Member NoteProperty "Role" $Roles[$i]
    $object | Add-Member NoteProperty "Hostname" $Servers[$i]
    $object | Add-Member NoteProperty "IP Address" (Get-WmiObject Win32_networkadapterconfiguration -ComputerName $Servers[$i] -Credential $credentials | ? {$_.IPEnabled} | Select-Object IPaddress).IPaddress[0]
    $object | Add-Member NoteProperty "Version" (Get-WmiObject win32_Product -ComputerName $Servers[$i] -Credential $credentials | Where-Object {$_.Name -eq $Roles[$i]}).version
    $output += $object
    $i++
    IF ($PSVersionTable.PSVersion.Major -ge 3) { Write-Progress -activity "Completed Getting Version Information" -Completed } Else { write-host "...Done!" -NoNewline }
    write-host ""
    $output
    } # End Function get-Version
    Walter

    Your code doesn't relay make much sense.
    What is this line for:
    $Servers = "$vcenter","$vcenter","$vcenter","$sso","$vum","$vum"
    Funtion get-version($vcenter,$sso,$vum,$credentials
    Why are you using credentials.  Only and admin can call remotely?
    Are you trying to get all of these roles? Aren't these produces?
    $Roles  = "VMware vCenter Server","VMware vCenter Inventory Service","VMware vSphere Web Client","vCenter Single Sign On","VMware
    vSphere Update Manager","vSphere Syslog Collector"
    ¯\_(ツ)_/¯

  • A question about class and interface? please help me!

    the following is program:
    interface A{
    public class B implements A{
    public static void main(String [] args){
    A a = new B();
    System.out.println(a.toString());
    }i want to ask a question, the method toString() is not belong to interface A, why a can call method toString()? the interface call the method that isn't belong to, why? please help me...

    because a.toString() call the method toString() of class Object because B implements A, but extends Object and in the class Object there is a method toString(). infact if you override the method toString() in class B, a.toString() call toString() in class B.
    try this:
    interface A {}
    public class B implements A
      public String toString()
        return "B";
      public static void main(String [] args)
        A a = new B();
        System.out.println(a.toString());
      }by gino

  • General question about classes

    Hi every one,
    I have an application that works but i'll like to optimize it, regarding about speed and system ressources. For resume and represent diagrammatically the application I wrote, there is a first frame (the main menu) with severals buttons. When I push a button I show a new frame with a query resultset displayed inside.
    Theses second frames are all very similars, just a few things are differents between one and another (sql string of the query, and some controls may be visible or not).
    So there are many solutions to write it :
    1- I can make a class representing this second frame and each time I push a button from the main menu, I create a new Object with this class and when I quit this frame I do a "dispose" of it.
    2 - (the solution I got) I create an Object with the model of this second frame once and for all, and when I push a button I set visible this frame and call a method to change some parameters, when I quit the frame I set it hide.
    I think second option is not to bad and the first one is very heavy, but If I created a class B that extends my second frame A (that contains the main code for displaying results) and each time I push a button from the main menu I created an object from B type, is it a good idea ??
    Hope you understand my problem, and hope anyone will give me an idea...

    Hi rainek and ty for your attention,
    Yes you understood right :
    my app creates Frame 1 with buttons and show it, and I create on the background a raw version of Frame 2 shown, and with changed parameters when button is pressed.
    But I don't not extend Frame 2 with a SubFrame 2, I just wonder if it would be a good thing to create subframe 2 and instance it each time I push a button from Frame 1, instead to use the same Frame 2 raw version (storing it in a file config indeed) from the background. I wondered, if when I instance for the second time a subframe 2 it was speeder because an object subframe 2 as already been instancied before.
    You know my problem was also that when I created Frame 2 in the background before create Frame 1, it gave my troubles with Frame 1 display (cf. my topic :http://forums.java.sun.com/thread.jsp?forum=57&thread=231897), so now I create this frame 2 raw version the first time I push any button, but of course there is a litte big longer time answer this first time. (I thank too, to create Frame 2 raw version in a thread to avoid frame 1 display troubles)
    Hope I'm clear and you understand me, for resume in a generic problem, I wonder know if when i have this config :
    Frame 2,
    Subframe2 that extends Frame 2
    if i do
    Subframe2 myframe_a = new Subframe2 (<parameters_a>) and
    Subframe2 myframe_b = new Subframe2 (<parameters_b>)
    myframe_b is created more quickly because myframe_a as been instancied before
    Any way ty very much for your answer rainek !!

  • A question about classes

    Hi all,
    This is a general question, hope it is in the right forum.
    Lets say I have a main document class, declared in the property window. I can easily create new instances of a movieclip in my library by simply creating them in my document class and then using addchild to put them on the stage. Now lets say I have a separate external class that I am importing into my document class. How do I create instances of the movieclip from my library in that external class. All I want my document class to do is import classes and let them do the work so to speak. I know I can create the movieclip instance in the document class and pass it as a parameter when I import the external class but what if I want to create it there?
    I hope that makes sense, I am sure it is very simple but I am tired of having massive long document classes!
    Thanks in advance.

    Hi, sorry I know you answered this but I have just done a quick test file to try the instantiation,
    the movieclip is not showing, the movieclip is linked out with a class of mcSquare.
    //document class
    package {
        import flash.display.MovieClip;
        import external;
        public class document extends MovieClip
            public var externalClass:external = new external();
            public function document()
    //external
    package {
        import flash.display.*;
        import flash.utils.getDefinitionByName;
        public class external extends MovieClip
            public var square_mc1:mcSquare = new mcSquare();
            /*public var square:Class = getDefinitionByName("mcSquare") as Class;
            public var square_mc1:Object = new square();*/
            public function external()
                //square_mc1.x = 43.5;
                //addChild(DisplayObject(square_mc1));
                addChild(square_mc1);
    The commented code is just attempts after googling.
    Again apologies for reposting, I thought that had cracked it
    Thanks

  • Question about classes hyargie

    hello, my english is very bad so, but i think you can understand my problem:
    i'm creating a game, in Java using jEdit and have 3 classes: one application with the static main, called Memory. That one creates another one, called Game. It's a canvas. Till here no problem.
    But when I try to create from the the class Game a class Kaart, he'll give an error:
    the code looks like this
    public class Game extends Canvas
    private Kaart kaartje;
         public Game( int dinges )
    kaartje = new Kaart( 27, 16 );
    add( Kaartje ); //<---------------------
    this is the error:
    C:\Jan\proggen\Game.java:34: add(java.awt.PopupMenu) in java.awt.Component cannot be applied to (Kaart)
              add( kaartje );
    ^
    1 error
    anyone know about this..?
    thanks jan

    What are you trying to do?
    The message says that you need to pass a PopupMenu to add (you are calling add on the Canvas). So, apparently, kaartje is NOT a PopupMenu (or subclass). What does Kaart look like?

  • Question about class icons

    So I learned today that a child class's icon is created by merging the child's icon as displayed in the class properties with the parent's icon as it appears in the parent's properties (the child's icon being the top image in the merge and the parent's the bottom). This isn't obvious from normal operation since the default icons are the same size and thus the child's icon perfectly overlaps and thus displaces the parent's. However, I drew an icon that extends a little bit beyond the bottom of the border of where the default icon normally goes (in the parent icon). This change was propogated to my numerous child classes, and now the icon is cut off on like 100 vis and it looks dumb.
    Technically, this doesn't change anything about my program. Since I never actually place the child vi's on a block diagram, I never see the icons except when editing the child vis or when they are calling each other (one child vi calls the other, which is rare). The code is only brought into the main vi via dynamic dispatch. That said, I'd love to know if there is a way to override the default behavior of how labview builds these vi icons. It's driving the pedant in me crazy.

    Hi majoris
    could you post an example of this so I can look at it more closely?
    Joe Daily
    National Instruments
    Applications Engineer
    may the G be with you ....

  • Question about class PackedInteger.

    Dear All,
    i was searching for sth that can read an integer by using FileInputStream , i mean to take it in the form of an integer not bytes as usual , and i found this class called PackedInteger on that link :
    http://www.oracle.com/technology/documentation/berkeley-db/je/java/com/sleepycat/util/PackedInteger.html#readInt(byte[],%20int)
    mm actually i'm not sure about the source of that class , or who published it , alsoo i'm not sure if it would be useful in my case ,
    can any body help me ?, if u have any ideas about how to read and write inetegrs from to files i would be grateful to hear from u .
    thanks in advance.
    Regards,
    D.Roth

    hey guys , i found this also , what do u think ?
    readUnary
    public int readUnary()
    Reads a unary integer from the already read buffer.
    Returns:
    the decoded integer
    , in a class called BitFile .

  • Question about class design

    Hi:
    I am trying to design a web game using JSP, servlets, etc. I have some ideas about the classes I have to create and how to split the work among them. I.e:
    class Player
    - contains the player data like name, nickname, age, etc...
    - have a static method getPlayerById(id) which calls load(id) method.
    - load method calls DBPlayer.load(id)
    class DBPlayer
    - uses Database objetct to get the connetion.
    - static load(id) method executes a "select" query and gets the data from database and create a new Player instance sending the data by constructor
    class Database
    - get the connetion data and connect to database
    I could have a JSP page named showPlayerInfo.jsp which gets the player_id by request. The page calls Player.getPlayerById(player_id) ans shows the data in html format.
    would this be correct?
    If I would like to show the list of players of a game. Could I have a GamePlayerList servlet which uses Database object, get an array of Player objects which can be shown using a JSP page or the GamePlayerList servlet? should the "retrieving player list data" be in DBPlayer instead?
    Thanks in advance for your advices

    There is no right answer. What you have is a model object (Player) a data access object (DBPlayer, normally this would be named something like PlayerDao) and a utilities class to connect to the database (Database or you could call it DatabaseUtil or DatabaseHelper, whatever) Another option for your Database class is to instead call it AbstractDao, have PlayerDao extend it, and in AbstractDao place methods like connect(), rollback() and commit(). One reason you want these methods in either a helper class or a superclass is so you can place your try-catch blocks there and not have to worry about cluttering up the rest of your code.
    In terms of an overall architecture, you should take a look at the MVC pattern. Your Player and PlayerDao objects are your model. Your servlets are your controllers. And your JSP's are your view. It's a fairly standard way of organizing your application.
    You have several options for how to load new players. The first would be as you have done, to place a static factory method in Player. Another option would be to create a separate PlayerFactory object that can create new or return existing or delete existing players. The Servlet would call the PlayerFactory which would delegate to the PlayerDao returning a Player object. In this design, your Servlet would either invoke the PlayerFactory or PlayerDao to save, etc. If you instead want a bit more encapsulation at the price of separation of concerns, you can have the Player object itself have methods like save(), delete(), etc.
    There is no right answer. Designs involve trade-offs and to a large extent personal (or corporate or academic) preference.
    - Saish

  • Question about Class.forName()

    I am trying to get an instance of a class by its name. Now, I have tried both creating it with the class's actual name and with the class's name including the package path and both times I got a java.lang.ClassNotFoundException: my/package/MyClass.
    I am reading the name out of a properties file and that's working just fine according to my logging information btu here is the code anyway:
    Properties prop = new Properties();
    try{
         java.io.FileInputStream in = new java.io.FileInputStream(inv.getPath());
         prop.load(in);
         String temp = prop.getProperty("myclass1");
         Class c = Class.forName(temp);
         rollen.put("user",c.newInstance());
         temp = prop.getProperty("myclass2");
         c = Class.forName(temp);
         rollen.put("admin",c.newInstance());
    }catch(Exception e){
         //I'm doing some more logging here, guess that's not very interesting
    }I deleted all the logging info from this code snippet to make it shorter. But I can tell you that the name does get read out as my.package.MyClass - and the package and class name are correct...
    The entries in the properties files look like this:
    myclass1=my.package.MyClass
    myclass2=my.package.MyOtherClass
    Can you help me fix this, please?

    Is your classpath okay? I tried this:
    pkg\MyClass.javapackage pkg;
    public class MyClass {
        public MyClass () {
            System.out.println ("Woohoo!");
    }Test.javapublic class Test {
        public static void main (String[] parameters) throws Exception {
            Class.forName ("pkg.MyClass").newInstance ();
    }This outputsWoohoo!as expected.
    Kind regards,
      Levi

  • Newbie question about classes

    Hi, everyone. I've created a class 'Parser' that compiles. Now I want to create and instance of this class and set/get the data members from another class. However, when I try to use it, as seen below, I get an 'javac' error. What am I doing wrong?
    public class Tester {
         static Parser my_parser = new Parser() ;
    public static void main(String[] args)
    throws Exception {
    .... other stuff
    ====== javac error =============
    bash-2.02$ javac Tester.java
    Tester.java:12: cannot resolve symbol
    symbol : class Parser
    location: class vocalreader.Tester
    static Parser my_parser = new Parser() ;
    ^
    Tester.java:12: cannot resolve symbol
    symbol : class Parser
    location: class vocalreader.Tester
    static Parser my_parser = new Parser() ;
    ^

    Here the problem is with the CLASSPATH variable. Make sure it is setted corectly (it must include the current directory ".").
    As for the static modifier, in this code static refers to the variable my_parser, of type Parser, which in this way is marked as class variable (and it belongs to class Tester). So this variable can be accessed with the following: Tester.my_parser. Why should he remove the static modifier ? It has nothing to do with the methods in the Parser class.

  • Academic Question about Classes Method and Constructor

    Given the similarity between the Constructor class and the Method class, why don't they have a common super class for the methods they have in common that are unique to them?

    sledged wrote:
    jschell wrote:
    sledged wrote:
    I've found that the most common reason for invoking a constructor or method through reflection is because you don't know what you need until runtime, commonly because what you want can vary based on context, or is otherwise being specified external to the bit of code that uses reflection. Not true. The fact that I don't need it until runtime never means I don't know what I need.Never? Then your experiences with the reflection API have been different than mine. Either that or I wasn't very clear. Let's take Apache Commons BeanUtils;
    It doesn't matter how you access a class. You can't use it unless
    1. You have a goal in mind
    2. That object in some way fulfills that goal.
    3. You know how that object fulfills that goal.
    And as I already pointed out you can't use a JFrame for a JDBC driver. Simple as that. Nor can I create a new class that implements, for example, ProC (Oracle method to embed access into C code) using my own idiom despite that it provide database access. It MUST match what jdbc expects.
    Sometimes it's not even clear before runtime whether a constructor's needed or a method.
    I disagree. That isn't true in any OO language.Perhaps not out the box, but it can be true when using certain tools built from the OO language. Let me continue using the Spring framework as an example. It does not know whether to use a method or a constructor to instantiate any bean defined in the XML configuration metadata until that XML file is read and it determines whether or not a given bean definition has the "factory-method" attribute. The XML file in not read until runtime, therefore with any given bean defined therein, Spring does not know until runtime whether to use a constructor or method.Not apt at all.
    As I already said those are two different idioms. Spring supports them because they are used to solve different problems not because they wish constructors didn't exist.
    >
    The basis of OO is the "object". You can't have a method without the object in the conceptual OO model. (And in Smalltalk that is always true.)
    True, but one may not always care how the "object" is provided. When the method [Properties.load(InputStream)|http://java.sun.com/javase/6/docs/api/java/util/Properties.html#load%28java.io.InputStream%29] is called, it isn't going to care whether the InputStream argument was instantiated by one of the FileInputStream constructors, or if it came from a [URL.openStream()|http://java.sun.com/javase/6/docs/api/java/net/URL.html#openStream%28%29] method call. It'll work with either regardless of their respective origins.
    That of course has nothing to do with anything. Unless you are suggesting that construction in any form should not exist.
    A factory is not a constructor.I'm not saying it is. I'm just pointing out a number of the similarities between the two.
    So? There are many similarities between RMI and JDBC but that doesn't mean that they should be the same.
    With your argument you can claim that construction doesn't exist because any method, regardless of intent, that uses 'new' would eliminate the need for construction. And that isn't what happens in OO languages.I wouldn't claim that construction doesn't exist in any OO language. But I do know that in ECMAScript construction exists on the basis of whether or not a method is called with the 'new' operator. So in ECMAScript a single method can also be a constructor.
    And in C++ I can entirely circumvent the object construction process. Actually I can do that in JNI as well.
    I would still be a bad idea.
    >
    They are not interchangable.Normally, no, but with a high enough level of abstraction, they can become interchangeable. Again, the Spring framework is a great example. It doesn't care if a method or a constructor is used, and it won't know which one has been chosen until runtime. I don't even think Spring checks the return type of a method, so you could use a void return type method. (Although I don't know what that would buy you because the bean would always be set to null, but still...)
    No.
    Based on that argument every possible programming problem could be solved by simply stating that one must implement the "doit()" method. One just need to generalize it enough.
    Different APIs exist because there are in fact differences not because there are similarities.
    Over generalization WILL lead to code that is hard to maintain. Actually generalization itself, even when done correctly, can lead to code that is actually more complex.
    Because construction is substantially different than calling a method. In all OO languages.Yes, construction is different, but the actual call to a constructor and a method is only syntactically different with the presence of the 'new' operator. With reflection the difference is between calling Method.invoke() and Constructor.newInstance(), and, as I mentioned earlier, there's enough similarity between the two methods that they could be called by a single method specified by a common super class.Which does not alter the fact that the process of achieving the result is fundamentally different.

  • Quick question about class name

    I was reading through some java code and i noticed this line on the class name
    public class SimpleList<E> implements List<E>i was just wondering what does <E> refer too? I'd appreciate any links.
    Thanks

    The <E> portion of class definition is in reference to Generics. Take a look at Generics in the Tutorial.

Maybe you are looking for

  • BP Transaction - Default values upon selection of BP role ?

    Hi All, I want to assign values to Grouping and Account Group fields in BP transaction in CRM. Is there any BADI or Userexit to achive the same. If possible kindly explain the steps to be implemented to use the BADI. Thanks & Regards, Navneeth K.

  • Where do I find files to back up in Bridge

    I am new to PS and Bridge.  I have been attaching key words to photos.  I have my photos backed up elsewhere, but: 1.  What do I need to back up in Bridge; 2.  Where is it located? I'm particularly concerned about the keywords and other information s

  • Problem with String variable

    I am new to Java Programming. I have a line of code that works and does what is supposed to. faceData.getProfile("Lisa").removeFriend("Curtis"); If I assign the strings to variables such as- String name = "Lisa"; String fName = "Curtis"; and then plu

  • Please guide (SBO)

    Hello Everyone, Can you please explain a little about Business one.Is it a ERP system which can be integrated with any other application also. The information which I got for the same is "SAP Business One u2013 the end-to-end solution platform specia

  • Received message from 50472 "Your,Cloud,Sketching,verification,code,is...",What,is,it?

    I did nothing but received sms from 50472 "Your iCloud Keychain verification code is... " What is it?