Loading a movieClip from a class

Hello all,
I'm attempting to write an AS 2.0 class using Flash through
which I can load and control multiple movie clips in the library
and from external files. I've attempted multiple different ways,
don't quite seem to be able to get the images to show up on the
screen. After some time searching, I've been unable to find a good
example online. Please excuse my inexperience with AS classes.
I'd like to write a class that extends MovieClip and is used
to control multiple 'sub' movieClips, all from methods inside the
instantiated class.
From .fla file, I call instantiate my class as follows:
var theScene:sphere3D = new sphere3D();
In the constructor of my class file, I'm attempting to attach
or load a movie. I simply want to get it to show up on the screen,
when I test the .fla movie. I've tried using attachMovie and
loadMovie with not luck.
dynamic class sphere3D extends MovieClip {
function sphere3D() {
this.attachMovie("shadow","shadow",1); // shadow being a
movie clip in the .fla library with linkage
shadow._x = 100;
shadow._y = 100;
this.createEmptyMovieClip ("shadow2", 100);
shadow2._x = 100;
shadow2._y = 100;
shadow2.loadMovie("images/cube.png");
What am I doing wrong? Suggestions for stuff to test would be
welcome.
Thank you,
dana.

Ah, thank you, that make sense now. The solution you
suggested worked great.
I did also find two other solutions, for anyone else who
might read this. One is to essentially create an empty movieclip on
your timeline. From the linkage window for the empty movieclip, I
made sure I set the Class field to the name of the class I'd
written, something I didn't do previously. This attaches all the
class actionscript to the empty movieclip, and even automatically
runs the constructor when the empty movieclip is placed on the
timeline. It also automatically provides a 'reference' to the main
timeline when I refer to this.attachMovie() from inside the class.
So it worked, but isn't as elegant as doing everything from the
actionscript (unless you are building a component).
The last reference I came across is the
Object.registerClass() method used to attach as class to an object,
similar to using the Linkage method above. But I haven't
successfully tried it yet.
Thanks again for the help kglad,
dana.
Dana Sheikholeslami
Art Institute of California

Similar Messages

  • Loading property files from a class and not a servlet...

    Hi, I was wondering if anyone has a good solution for loading property files from a class instead of a servlet. I would like to load the property file similarly to how it is done from HttpServlet.
    Here is the large picture. I have a tag library that calls a class which needs to access a database. The class needs to know what DB to access so it needs to look at some property file. The problem is that I don't want to hardcode the properties or the path of where the property file exists. I hope this all makes sense.
    Thanks.
    -PV

    I use the getResource method in the java.lang.Class class. Read about this method in the api.
    Anyways this is roughly how it's : you must put your properties file in the classpath. Then in your class :
    Properties prop = new Properties();
    URL url = this.getClass().getResource("/config/db.properties");
    prop.load(url.openStream());In this case, you must put the "config" (where you've written your db.properties file) directory's parent in the classpath.

  • How to load a movieclip from libary with a button?

    Hi!
    I am kinda new to Flash and i have a queston.I made a
    movieclip that i keep in the libary. I have a button that i want to
    load the movieclip on the screen while pressing it. Queston is: how
    or what kind of code do i put for the button to load the movieclip
    wich is in my libary? As i see there is no simple soulution for
    this with the script assistent? I got the option load movie but it
    only loads external files or i get error messages when trying to
    load my movie.
    Please help me with this.
    /Tobias

    there are a few things you'll need to do in order to achieve
    this, but it's not to complicated. First right-click the MC in the
    Library and select 'properties', then in the 'Linkage' section
    select the check box 'Export for ActionScript' and the type a name
    in the 'Identifier' field, hit OK. now you can access the MC by the
    linkage ID.
    the next thing you will need to know is 'where' you want to
    place the MC, figure out the x,y position. then on the main
    timeline, handle the 'button' code and we'll use 'attachMovie' to
    bring the MC to the Stage. within the attachMovie method we'll also
    pass the position you've decided upon. so it would look something
    like this:

  • Manipulate movieclip from custom class

    Hello.
    I have a movieclip (instance name preload), inside of it, I have another movieclip (bar) ... what i'm trying to do is a preloader for external files... i have a custom class and i what to manipulate my movieclip preload from it... you know verify the progress of the load:
    Inside my class a have this function
    public function loadProgress(e:ProgressEvent):void {
                percent=e.bytesLoaded/e.bytesTotal*100;
                rutaDos.preload.bar.scaleX=percent;
    rutaDos is a reference to the stage... it works, I'm sure of it... the problem is:rutaDos.preload.bar.scaleX; I upload the files but it doesn't verify the progress of the load.
    thanks for the help

    the complete class is:
    package com.ludwing{
        import flash.net.*;
        import flash.events.*;
        import flash.display.*;
        import fl.transitions.*;
        import fl.transitions.easing.*;
        import flash.display.Stage;
        import gs.TweenMax;
        import gs.easing.*;
        import gs.events.*;
        public class Transiciones extends MovieClip {
            public var url:URLRequest;
            public var loader:URLLoader;
            public var rutaDos:MovieClip;
            public var imgLoader:Loader;
            public var movie:MovieClip;
            public var container:Sprite;
            public var bg:Boolean;
            public var porcentaje:Number;
            public function Transiciones(mRuta:MovieClip, miRuta:String,isBG:Boolean,contain:MovieClip) {
                rutaDos=mRuta;
                bg=isBG;
                movie=contain;
                container=new Sprite();
                url=new URLRequest(miRuta);
                imgLoader=new Loader();
                imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaderComplete);
                imgLoader.load(url);
            public function onLoaderComplete(e:Event) {
                imgLoader=new Loader();
                imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgComplete);
                imgLoader.contentLoaderInfo.addEventListener(Event.INIT, imgInit);
                imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
                imgLoader.load(url);
            public function loadProgress(e:ProgressEvent):void {
                porcentaje=e.bytesLoaded/e.bytesTotal*100;
                rutaDos.preload.bar.rotation=90;
            public function imgInit(e:Event) {
                movie.alpha=0;
                rutaDos.preload.alpha=1;
            public function imgComplete(event:Event) {
                rutaDos.preload.alpha=0;
                movie.addChild(imgLoader);
                var myTween:TweenMax = TweenMax.to(movie, 1, {alpha:1, ease:Circ.easeOut});
                myTween.addEventListener(Event.COMPLETE, onTransitionFinish);
            public function onTransitionFinish(e:Event):void {
                //MovieClip(root).gotoAndPlay(2);
                //rutaDos.ext.gotoAndStop(2)
                /*var my_parent:MovieClip=parent.parent as MovieClip;
                my_parent.nextSection=2;
                my_parent.gotoAndStop(my_parent.nextSection);*/
                //rutaDos.stage.addEventListener(Event.RESIZE, resizeHandler);
                if (bg==true) {
                    rutaDos.gotoAndStop(14);
    I try to use an empty movieclip to load a external swf (instance name: ext) this way:
    var transicion:Transiciones=new Transiciones(this, "welcome.swf",true,ext);
    The external swf loads correctly, but when it is loading (i mean de progress load), the preload doesn't work....

  • Load java main from java class

    Is it possible to load a java main of some class
    from other java class?
    example:
    public static void loadClass(final String name, final String param) {
    try {
    Class c = Class.forName(name);
    Class[] cParams = new Class[1];
    cParams[0] = String.class;
    Method m = c.getMethod("main", cParams);
    Object whatisthisobject = null;
    String args[] = { "" };
    Object o = m.invoke(whatisthisobject, args);
    catch (Throwable t) {
    System.out.println("error: " + t);
    public static void main(String[] args) {
    loadClass("Test", "abc");

    Anything you can do with an ordinary static method can be done with main.

  • How do I reference a MovieClip from a class

    Hi. Trying to learn AS3 and having a hard time ; (
    I'm working on a game. I have a Ship class that uses addChild
    to add a linked Bullet MovieClip to the stage. The Bullet MC is
    linked to the class below. I've got it working so it moves up the
    screen, but now I need to build a hitTest, however I cant get
    access to a movie clip I've placed on the stage, "enemyDisplay_mc".
    How do I reference this MC? In AS2 I would just do a _root.
    Thanks!
    package {
    import flash.display.*;
    import flash.events.Event;
    public class Weapons extends MovieClip {
    private var _thisWeaponMC:MovieClip;
    private var _enemyHit:DisplayObject;
    private var _speed:Number;
    public function Weapons () {
    this.addEventListener (Event.ADDED,Initialize);
    private function Initialize (event:Event):void {
    //trace ("Weapons");
    _thisWeaponMC =
    MovieClip(this.parent.getChildByName(this.name));
    trace ("_thisWeaponMC: " + _thisWeaponMC);
    _thisParent = event.currentTarget.parent;
    trace ("_thisParent: " + _thisParent);
    _enemyHit = this.parent.getChildByName("enemyDisplay_mc");
    trace ("_enemyHit: " + _enemyHit);
    _speed=20;
    this.addEventListener (Event.ENTER_FRAME,moveShip);
    private function moveShip (event:Event):void {
    this.y-= _speed;
    }

    This code is called from my Ship class.
    The Ship class is the Base class of the ship movie clip.
    VulcanShot is the linkage class name of the bullet movie,
    it's base class is Weapons.
    Thanks!

  • Load New JFrame from different class

    Hi, Im making an application that has a login jframe when it loads. If they login with the right info, I want the login jframe to dissapear, and I want the main menu jframe to open...
    The login jframe is: FearlessUI.java
    The menu jframe is MainMenu.java
    Anybody know the code to do so?

    Here is the code of MainMenu.java:
    * MainMenu.java
    * Created on December 19, 2006, 6:25 PM
    package my.FearlessForce;
    public class MainMenu extends javax.swing.JFrame {
        /** Creates new form MainMenu */
        public MainMenu() {
            initComponents();
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 400, Short.MAX_VALUE)
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(0, 300, Short.MAX_VALUE)
            pack();
        }// </editor-fold>                       
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MainMenu().setVisible(true);
        // Variables declaration - do not modify                    
        // End of variables declaration                  
    }

  • Access movieclip from class

    Hi,
    I would like to tell a movieclip on the stage to be visible from a class.  Is that possible?

    if that class has a reference to a displayobject, yes.

  • Load xml file using gerResource() from a class in jar

    Hi,
    I have a jar file. I set the classpath for the jar.
    I have an xml file in the directory of jar.
    ex: /example/test.jar (jar file)
    /example/test/test.xml
    I would like to load the xml file by using a class in the jar file like:
    URL url = Test.class.getResource("/example/test/test.xml");
    Test.class is in the jar.
    But it is not loading and giving URL as null.
    I couldnot figure out how to load any file outside of the jar file from a class file in the jar.
    Any solution can be appreciated.
    Thanx in advance.
    Sridhar

    Try
        URL url = ClassLoader.getSystemResource ("/example/test/test.xml");

  • Howto find out location from where class was loaded

    Hi all.
    Is there any way I can find out from which directory, jar or url a certain object/class was loaded?
    Somewhere in the code the object is instantiated (class is loaded). E.g. like so:
    SomeObject someObjectInstance = SomeObjectFactory.getInstance();
    Can I use this object to find out from where in the file system it was loaded? E.g.
    someObjectInstance.class.fooMethod() or
    someObjectInstance.class.getClassLoader.barMethod()
    Thanks for any help.
    Joe

    Usage is actually like so:
    MyClass myInstance = (...)
    myInstance.getClass().getResource("/package/MyClass.class") returns the url object, pointing to the class;
    if you want a string instead, simply append toString():
    myInstance.getClass().getResource("/package/MyClass.class").toString()

  • Nulling a movieclip made from a class - does it make it trashable?

    Hi
    I instantiate a class that makes some movieclips within it, and from the class that instatiated it, I add some event listeners to the moveiclips...
    (simplified)
    var myClip:MCClass = new MCClass();
    myClip.mc1.addEventListener(MouseEvent.CLICK, doSomething);
    If at some stage I state myClip = null, does that make the event listeners eligible to be garbage collected, or do I need to removeEventListener them prior to myClip = null?
    Cheers!

    You have to both remove MyClip from the stage and also make it null to make the object that has the functions that are being used as event listeners available for garbage collection.
    For example:
    public class Obj1 {
         protected var _obj2:Obj2;
         public function get obj2():Obj2 {
              return _obj2;
         public function set obj2(value:Obj2):void {
              if (value != _obj2) {
                   //should do this so the event listeners don't fire after obj2 nulled in larger context
                   if (_obj2) {
                        _obj2.child.removeEventListener('someEvent', listener);
                   _obj2 = value;
                   if (_obj2) {
                        _obj2.child.addEventListener('someEvent', listener);
         protected function listener(e:Event):void {
              //do something
    public class MainClass {    
         protected var _obj1:Obj1;
         protected var _obj2:Obj2;
         protected function init():void {    
              _obj2 = new Obj2();
              addChild(_obj2);
              _obj1 = new Obj1();
              _obj1.obj2 = _obj2;
         protected function tearDown():void {
              removeChild(_obj2);
              _obj2 = null;
              //if you don't null _obj1.obj2, the listener will keep firing until it is garbage collected
              //but obj1 will eventually get garbage collected
              _obj1=null;

  • MovieClip not adding from my class

    If I have the following on the timeline in my FLV, it works and attaches my movie from the library to the stage. If I do the same from my class, it does not. What could be the issue?
    var myMC:ToolTipMc = new ToolTipMc();
    addChild(myMC);
    Thanks a lot for any help!

    Brian914,
    You have added the ToolTipMc to the display list of you class but is your class added to the display list of the Stage or Document root. Check and see if your class is a display object like MovieClip and that it is added to the stage. bellow is an example.
    package {
         import flash.display.*;
         public class MyToolTip extends MovieClip{
              public function MyToolTip():void{
                   //code for your tool tip
    package {
         import flash.display.*;
         import MyToolTip;
         public class MyToolTipHolder extends MovieClip{
              public var tTip:MyToolTip;
              public function MyToolTipHolder():void{
                tTip = new MyToolTip();
                   addChild(tTip);
    Now if you are trying to put the tooltip on the screen you wil need to first add the MyToolTipHolder to the displaylist then it will add MyToolTip to its display list and it will show up. If you want to add the ToolTipHolder to any other display Object like flv, then add the myFLV.addChild(toolTipHolder);
    Hope This Helps
    Edithson Abelard
    Passion 47

  • How to load function from derived class from dll

    Dear all,
    how to access extra function from derived class.
    for Example
    //==========================MyIShape.h
    class CMyIShape
    public:
    CMyIShape(){};
    virtual ~CMyIShape(){};
    virtual void Fn_DrawMe(){};
    // =========== this is ShapRectangle.dll
    //==========================ShapRectangle .h
    #include "MyIShape.h"
    class DLL_API ShapRectangle :public CMyIShape
    public:
    ShapRectangle(){};
    virtual ~ShapRectangle(){};
    virtual void Fn_DrawMe(){/*something here */};
    virtual void Fn_ChangeMe(){/*something here */};
    __declspec (dllexport) CMyIShape* CreateShape()
    // call the constructor of the actual implementation
    CMyIShape * m_Obj = new ShapRectangle();
    // return the created function
    return m_Obj;
    // =========== this is ShapCircle .dll
    //==========================ShapCircle .h
    #include "MyIShape.h"
    class DLL_API ShapCircle :public CMyIShape
    public:
    ShapCircle(){};
    virtual ~ShapCircle(){};
    virtual void Fn_DrawMe(){/*something here */};
    virtual void Fn_GetRadious(){/*something here */};
    __declspec (dllexport) CMyIShape* CreateShape()
    // call the constructor of the actual implementation
    CMyIShape * m_Obj = new ShapCircle();
    // return the created function
    return m_Obj;
    in exe there is no include header of of ShapCircle and ShapRectangle 
    and from the exe i use LoadLibrary and GetProcAddress .
    typedef CMyIShape* (*CREATE_OBJECT) ();
    CMyIShape*xCls ;
    //===================== from ShapeCircle.Dll
    pReg=  (CREATE_OBJECT)GetProcAddress (hInst ,"CreateShape");
    xCls = pReg();
    now xCls give all access of base class. but how to get pointer of funciton Fn_GetRadious() or how to get access.
    thanks in advance.

    could you please tell me in detail. why so. or any reference for it. i love to read.
    i don't know this is bad way.. but how? i would like to know.
    I indicated in the second sentence. Classes can be implemented differently by different compilers. For example, the alignment of member variables may differ. Also there is the pitfall that a class may be allocated within the DLL but deallocated in the client
    code. But the allocation/deallocation algorithms may differ across different compilers, and certainly between DEBUG and RELEASE mode. This means that you must ensure that if the DLL is compiled in Visual Studio 2010 / Debug mode, that the client code is also
    compiled in Visual Studio 2010 / Debug mode. Otherwise your program will be subject to mysterious crashes.
    is there any other way to archive same goal?
    Of course. DLL functionality should be exposed as a set of functions that accept and return POD data types. "POD" means "plain-ole-data" such as long, wchar_t*, bool, etc. Don't pass pointers to classes. 
    Obviously classes can be implemented within the DLL but they should be kept completely contained within the DLL. You might, for example, expose a function to allocate a class internally to the DLL and another function that can be called by the client code
    to free the class. And of course you can define other functions that can be used by the client code to indirectly call the class's methods.
    and why i need to give header file of ShapCircle and shapRectangle class, even i am not using in exe too. i though it is enough to give only MyIShape.h so with this any one can make new object.
    Indeed you don't have to, if you only want to call the public properties and methods that are defined within MyIShape.h.

  • Controlling MovieClip properties from a Class that it's linked to

    Hi all,
    I have a Moveclip with a Dynamic text field instance name of
    "optionName". The movie clip is linked to my custom Class "Toggle".
    Is there a way for me to access "optionName" from my class?
    Basically I am getting this error:
    Thanks.

    Thanks, much appreciated.

  • Is it possible to call a movieClip from the Flash library using XML?

    Instead of using "test_1.swf" or "test_2.jpg" in the <IMAGE> tags shown below, we are wanting to call a movieClip from the same library as the .FLA via XML.
    Is this possible using XML and AS3?
    < ?xml version="1.0" encoding="UTF-8"?>
    < all>
         < GROUP>
              <IMAGE>test_1.swf</IMAGE>
              <QUESTION>Question example #1</QUESTION>
              <OPTION1>Option A example</OPTION1>
              <OPTION2>Option B example/OPTION2>
              <OPTION3>Option C example</OPTION3>
              <IMAGE>test_2.jpg</IMAGE> 
              <QUESTION>Question example #2</QUESTION>
              <OPTION1>Option A example</OPTION1>
              <OPTION2>Option B example/OPTION2>
              <OPTION3>Option C example</OPTION3>
         < /GROUP>
    < /all>

    data.xml:
    < ?xml version="1.0" encoding="UTF-8"?>
    < all>
         < GROUP>
              <IMAGE>MC1</IMAGE>
              <QUESTION>Question example #1</QUESTION>
              <OPTION1>Option A example</OPTION1>
              <OPTION2>Option B example/OPTION2>
              <OPTION3>Option C example</OPTION3>
              <IMAGE>MC2</IMAGE> 
              <QUESTION>Question example #2</QUESTION>
              <OPTION1>Option A example</OPTION1>
              <OPTION2>Option B example/OPTION2>
              <OPTION3>Option C example</OPTION3>
         < /GROUP>
    < /all>
    // a.s.
    var urlLoader:URLLoader=new URLLoader();
    urlLoader.addEventListener(Event.COMPLETE,completeF);
    urlLoader.load(new URLRequest("data.xml"));
    function completeF(e:Event):void{
    var xml:XML=XML(e.data);
    var instance:*=stringToClassInstanceF(xml.GROUP.IMAGE[0]);
    addChild(instance);
    function stringToClassInstanceF(s:String):*{
    var C:Class=Class(getDefinitionByName(s));
    return new C();

Maybe you are looking for