Children swf timeline code vs document class.

Hey all,
I am loading a swf into another and had a question that I can't seem to find an answer to.
I am trying to find out why when I place trace(parent); in the timeline of my child swf I get [object Loader]
but if i place  trace(parent); in the constructor of the child swf's document lcass I get null.
Why is this and how would I access the parent swf  from the child document class if it shows as null?
Thanks

The constructor is running before the swf has been added to the stage of the parent. Use the Event.ADDED_TO_STAGE event in the document class of the swf being loaded, and once it fires trace parent.

Similar Messages

  • Timeline code to document class code - best practices

    I'm starting to put all of my code in the document class instead of on the main timeline, and I have a few questions. When I was using the timeline, everything was linear. It was easy to know when things would start and end because of how the playhead moves. With the document class, I noticed for the first time that functions are executed simultaneously if you call them one after the other. What would be the best way to make them execute in sequence? Let's say I have functions f1, f2, and f3. I suppose at the end of f1 I could call f2, and at the end of f2 call f3, or use event listeners, but is that the right way to do it? By the time you get to f3, aren't f1 and f2 still "open" because they haven't terminated?

    do you want some appreciable time to transpire between executing f1,f2 and f3?
    if yes, use a timer or timers.  if no, then just call them sequentially. with few exceptions (mainly when loading some external (to flash) file executes code synchronously:
    f1();
    f2();
    f3();

  • What is the difference between document class and normal class

    Hi,
    Please let me know what is the difference between document class and normal class.
    And I have no idea which class should call as document class or call as an object.
    Thanks
    -Actionscript Developer

    the document class is invoked immediately when your swf opens.  the document class must subclass the sprite or movieclip class.
    all other classes are invoked explicitly with code and need not subclass any other class.

  • Document Class reference

    This might be tough for me to explain but here it goes:
    I have a textField in Frame 1 of a swf. that swf has a
    document class. When I compile that swf i can change the text in
    the textField easily with textField.appendText(text);
    However, when I compile a second swf which references that
    document class that textField gives me an error on compile because
    it does not exist in the document class of the swf it is referring
    to. How do I solve that? When I compile I get an 1120:Access Denied
    undefined property error. If I try to define the textField in my
    document class like private var textField; I get a confilct with
    namespace internal ....
    SWF 2 has no idea SWF 1 has no idea SWF 1 has a textField in
    its timeline when it is compiling.
    Is there a way around this or do I have to create the
    textField in my document class? There has to be a way to mix
    sprites in a timeline and sprites in the document class.

    You need to do two things to get it to compile.
    1. In Publish Settings -> ActionScript Settings UNCHECK
    the Automatically declare stage instances box.
    2. Declare your text field as public: public var
    textField:TextField;

  • Hang Calling function after Document Class' Event.ADDED

    I was trying to load an external SWF (that contains the below code in its document class) with the Loader class but i keep on receiving Error #1009: Cannot access a property or method of a null object reference. So i tried to use the event listener Event.ADDED in MyDocumentClass constructor of the external SWF to let the document class be part of the display list before i invoke createRandomGraph. But when i place createRandomGraph( ) inside onStageReady, The compilation process hangs. When i leave the createRandomGraph( ) inside the constructor, it works perfectly as stand alone but will produce Error 1009 if loaded within the loader SWF. Any ideas?
    public function MyDocumentClass( )
        this.addEventListener(Event.ADDED, onStageReady);
        createRandomGraph( )
    private function onStageReady(oEvent:Event):void
        this.removeEventListener(Event.ADDED, onStageReady);
    private function createRandomGraph( ):void
        var cRandomGraph:RandomGraph = new RandomGraph();
        cRandomGraph.x = 10;
        cRandomGraph.y = stage.stageHeight - nH - 25;
        cRandomGraph.setDimensions(nW,nH);
        cRandomGraph.createGraphBackground();
        this.addChild(cRandomGraph);

    use:
    public function MyDocumentClass( )
        this.addEventListener(Event.ADDED_TO_STAGE, onStageReady);
    private function onStageReady(oEvent:Event):void
        this.removeEventListener(Event.ADDED, onStageReady);
    createRandomGraph();
    private function createRandomGraph( ):void
        var cRandomGraph:RandomGraph = new RandomGraph();
        cRandomGraph.x = 10;
        cRandomGraph.y = stage.stageHeight - nH - 25;
        cRandomGraph.setDimensions(nW,nH);
        cRandomGraph.createGraphBackground();
        this.addChild(cRandomGraph);

  • Document Class vs Timeline code differences...

    I'm trying to hunt down some kind of class conflict I seem to be having when using TweeLite easing and found out the same code that errors in a document class works fine if I place it in the timeline.
    Example - this works in frame one of the timeline:
    import com.greensock.TweenLite;
    import com.greensock.easing.*;
    TweenLite.to(obj, 1, { x:200, ease:Bounce.easeOut } );
    If however I make a very simple document class like so:
    package
          import com.greensock.TweenLite;
          import com.greensock.easing.*;
          import flash.display.MovieClip;
          public class Main extends MovieClip
               public function Main()
                    TweenLite.to(obj, 1, { x:200, ease:Bounce.easeOut } );
    I get an error when compiling:
    1119: Access of possibly undefined property easeOut through a reference with static type Class.
    So what's the differences between using a document class and timeline code?

    Odd... seems to have been a caching issue. I renamed the class, rebooted, and deleted ASO files and now it's working. Funny thing is that I never need to delete ASO files before... any thoughts on why this would stay cached?
    And, after rebooting I can make changes and don't need to delete ASO files either.
    Thanks!

  • Execute functions in document class when main timeline reaches a frame

    Hi,
    I have 3 functions in my main document class that I want to execute when the main timeline reaches a particular frame number.
    how do I do that?
    see the code and comments
    public function mainClass()
    //stage declaraction
    stage.align = StageAlign.TOP_LEFT;
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.addEventListener(Event.RESIZE, stageResized);
    //wrap these next 3 lines in an if statement that says if maintimeline currentframe = x
    position();
    loadXml();
    initArrowButtons();
    slideTimer = new Timer(timer_delay);
    slideTimer.addEventListener(TimerEvent.TIMER, nextSlide);

    It's still undocumented, but something like this would do it:
    package
        import flash.display.MovieClip;
        public class FrameScript extends MovieClip
            public function FrameScript()
                addFrameScript( 3, frameFour );
            private function frameFour():void
                trace( "you have reached Frame 4" );
    You can test this as a documentclass.

  • Accessing document class function within timeline

    Hi have a very simple question,
    (Bear with me I'm still quite new to as3 and some of my terminology may not be solid)
    I want to access a function that is within my document class when a movie clip on the timeline has played to a specific point (being the end).
    I have already been able to call another function from the document class at the top/root level (it is called to initialize all clips and buttons when you click on the "enter" button on the splash screen.
    Problem is that I cannot call another function (in the document class) from a movie clip within a movie clip on the timeline. Is there an easy way to do this? I have considered writing a separate class for the movie clip and then adding it onto the movie clip (using the property panel). I don't really want to do it this way because I am already using a base class on that movie clip and 3 others that use a set of generic functions.

    >>I want to access a function that is within my document class when a  movie clip on the timeline has played to a specific point (being the  end).
    Your document class should add a listener to the clip and the clip should dispatch an event when it's complete. You could dispatch your own event or use one of Flash's like Event.COMPLETE. Something like:
    in clip
    dispatchEvent(new Event(Event.COMPLETE));
    and in your doc class
    clipOnTimeline.addEventListener(Event.COMPLETE, classMethod);
    >>I have already been able to call another function  from the document class at the top/root level (it is called to  initialize all clips and buttons when you click on the "enter" button on  the splash screen.
    You really should avoid mixing timeline and document class code. Better would be for your doc class to add a listener to the button and call a method within the class when it's clicked.

  • Cannot import SWF with document class (AS3)

    When I try to import a SWF-file (published from a FLA-file with a as3 document class) via the mx:SWFLoader into Flash Builder, the imported SWF is not showing up (as3 build a cube from papervision3d). Which way do you have to import such a SWF-file?
    Regards, Sjoerd

    Shitf+Ctrl+Enter:
    Attempting to launch and connect to Player using URL preloader.swf
    [SWF] preloader.swf - 9591 bytes after decompression
    [SWF] big.swf - 1785015 bytes after decompression
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at DocumentlClass()
    Cannot display source code at this location.
    My document class (simplyfied):
    package {
        import flash.display.Sprite;
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import fl.transitions.Tween;
        import fl.transitions.TweenEvent;
        import fl.transitions.easing.*;
        import flash.events.ProgressEvent;
        public class CarouselClass extends MovieClip {
            private vars...
            public function CarouselClass() {
                trace("document class triggered");
                    this.addEventListener(Event.ADDED_TO_STAGE,init);
            private function init(evt:Event):void{
                 texts = new Texts();
                carouselSprite = new Sprite();
                addChild(carouselSprite);
                topContainer = new Sprite();
                carouselSprite.addChild(topContainer);
                hitBar = new HitBar();
                hitBar.x = stage.stageWidth / 2 - hitBar.width /2;
                hitBar.y = 245;
                addChild(hitBar);
                downContent = new DownContent();
                addChild(downContent);
                downContent.y = 325;
                downContent.title_txt.text = "Learning Carousel";
                downContent.description_txt.text = "Click on one of images above to view further details";
                createSections();
            } ... (more functions)

  • Document class question

    just trying to understand the concept here.
    I have a flash animation '.fla' file with it's corresponding
    document class that provides the code to control it.
    I want to instantiate an instance of that document class in
    another class.
    Do I simply put the document class and it's
    corresponding'.fla' file together inside the package folder ?
    Once I declare the document class as a new object within my
    new class, how does the document class link to the it's
    corresponding .fla animation ?
    To summarize, what I am trying to do, is create a reusable
    class or component from this .fla file with its document class. I
    just dont know how to proceed.

    more than one swf can use the same document class. but
    "animation" or other timeline assets will not be shared.

  • Preloader and Document Class BIG question (yeap please help)

    Hy,
    I know that this its a question posted many, many times, but
    after searching the net, reading a lot of books and searching this
    forum too, I cant get out with a solution. If I'd say for sure
    there is no possibility to create something like this, I just go
    back to old methods but is not the scope of Adobe with AS3 to
    encourage the use of OOP principle or not?
    The problem:
    I have a single fla file (AS3) with a single frame on
    timeline, frame that its there when you will create the file with
    flash. In the library I have different symbols, that for simplicity
    are only jpg image, (BitmapData) checked for export for
    ActionScript and exported on frame one. An external .as file called
    DocumentClass its off course my Document Class
    This its all that I want to do with the fla, the goal its to
    create, animate etc. only with AS3 in external classes, no timeline
    script. I don't want to load external files, XML, or else in this
    movie. I just want a single swf after compilation, no additional
    files.
    Ok, how do I create a preloader that will take care of
    starting the logic after the whole swf its loaded and in the same
    time shows the user a percentage or a load bar or something that
    its not the blank screen when the swf its downloading. I want to do
    this without another swf that load this swf, or timeline scripts,
    or place all the content on second frame and then gotoAndStop to
    the third frame. All this are not solution but cheap tricks, that
    are against all this OOP principle that I just continue to read in
    books and here from guru programmers.
    The big question is:
    It is possible to create a preloader, when use a document
    class with your fla? And if yes, how?
    I know that the Document Class its not instantiated if its
    not fully loaded, if that's true when the document class will be
    fully loaded? maybe after the whole movie its loaded? And, if its
    true, it will never show a percentage bar "while" the movie its
    loaded. And if that's true WHY use a document class anyway?
    Thank you for reading this and I really wait to get some
    answer.

    I am pretty sure you cannot do self preloader with one frame
    and all the objects in the library. I guess the key here is
    one-frame design. Screen refreshes (renders) only when all the
    scripts in the frame are executed - this is a very important thing
    to understand about how Flash works. Yes, you can force screen
    refresh with updateAfterEvent() method but it is attached to a
    handful of events only (MouseEvent and TimerEvent) but, again, all
    this functionality is available only after first frame scripts are
    executed. Thus, it seems like the only way to create preloader from
    within SWF is to use multiple frames and set library objects to
    load in later (not first) frame.
    quote:
    And if that's true WHY use a document class anyway?
    Well, preloader is the last thing that would be on my mind in
    terms of using AS3 ability to link DocumentClass to the top movie.
    This feature allows for very sophisticated architectural
    approaches. It has no connection to preloader as to any other
    features developer wants to implement. Neither it depends on or
    negates timeline. As a matter of fact, although I love one-frame
    applications, I find on numerous occasions that my application
    would be more efficient if I used several (at least two) frames.
    gotoAndStop is not deprecated. It is a valid MovieClip class'
    method. After all, having only one frame doesn't mean not having
    frames at all - there is one already. Frames are fundament of
    Flash. AS3 did introduce frameless entities like Sprite, etc. but
    it doesn't mean that frames are going anywhere.
    I would agree that timeline code is inferior to
    classed/packaged (read: better organized) code but, still, how is
    it not OOP? Frame is an Object, right? Why using timeline is cheap
    and not a solution?
    On a side note, I see too many times how some authors (and
    managers) are pushing their agenda (or close mindedness) onto their
    audience with no real substantiation. Claiming that timeline in
    Flash is not valid architectural decision from OOP standpoint is
    totally wrong. As wrong as strict adherence to design patterns. I
    don't think there is sharply defined "right" or "wrong" in
    programming. One finds the best optimal solution. The goal is to
    create something that works fine. Unless, of course, the process is
    the goal - but very few of us can afford focusing on the process.

  • Document class Error #2136

    Hi, in Flash CS3 I've this DocumentClass:
    package {
        import flash.display.MovieClip;
        public class DocumentClass extends MovieClip {
            public function DocumentClass() {
                trace("document class created");
    This actually works, but I want to have the possibility to re-instance the DocumentClass (because I want to restart a game and the Main class is the DocumentClass).
    In the first frame I have:
    import flash.events.MouseEvent;
    btn.addEventListener(MouseEvent.MOUSE_DOWN, restart);
    function restart(evt:MouseEvent){
        var d = new DocumentClass();
    But this code (I simplified my situation, but the result is the same) throws an error:
    Error: Error #2136: The SWF file  file:///E|/Documents%20and%20Settings/Pepper/My%20Documents/FlashDevelopment/PepperGame.s wf  contains invalid data at DocumentClass/restart()/frame1()
    What can I do to restart my game by calling the DocumentClass point of entry? Is this possibile?
    Regards and thanks to everybody.

    When you apply a DocumentClass to an FLA, the code becomes a part of that document (just like putting the code on the first frame of the timeline).  You aren't able to say "new DocumentClass()" in your code because it's essentially telling your application to create itself.  Instead, you have two options.  Firstly, add a function in your DocumentClass called "reset".  Add in this function all the things that need to be reset (score, lives, position of objects).  When you want to start the game over, you can just call the reset() function.
    If you really want to "refresh" the whole SWF, you'll want to build a second SWF (a "shell") that acts as a container for your game.  It would basically just load in the game SWF (and maybe save any global information).  When you want to restart the game, just reload the SWF.

  • Flash breaks randomly, won't compile, ignores document class?

    I have run into a strange and annoying problem since updating to Flash Professional CS5.5 on my work computer.
    Sometimes, seemingly randomly, Flash stops compiling things correctly. I Test Movie by hitting Cmd+Return and it just displays what's on the stage, frame 1. The document class is never initialized, no errors at all, no trace statements print out; it acts as if there is no code at all. After this happens once, it will continue to do this until I restart Flash, which fixes the problem. However, restarting Flash every 10 - 15 minutes is very annoying.
    It seems to happen regardless of what project I'm working on or what state the project is in (i.e. if the code contains errors or not). All of our projects use external AS3 classes (no code on the timeline).
    Has anyone else encountered this problem?
    I'm using an iMac running OSX 10.6.8.

    I haven't run into this with CS5.5 yet, but it used to happen to me all the time in CS4.  Simply moving the .fla to a different folder (and make sure it publishes to a new folder) solved the problem every time.  In CS5.5, prior to the recent update to CS5.5.1, I would also sometimes have my exported swf not reflect changes I made.  I fixed that by first saving as xfl, then resaving as fla. 

  • How do I recerence Movie Clips on the Main Timeline from inside a class?

    Hey everyone, this might be a stupid question but I thought
    I'd ask cause it's making me nuts. I'm all of 2 days into AS3
    (coming from not using Flash at all in YEARS) so feel free to
    consider me ignorant. I do have plenty of application development
    experience in other areas though.
    I can't seem to create a class that can reference an instance
    of a movie clip on my main timeline. I'd post code of what I've
    tried but I've gone through so many desperate edits & wild
    guesses that it was just garbled junk before I deleted it all.
    Basically here's how I figured Flash could work, though maybe
    it doesn't work this way at all.
    I'm assuming that with AS 3 being so big on being a true
    object oriented environment, I wouldn't need to mix my code and
    interface together. Preferably I'd be using the Flash authoring
    tools just to design my interface. Create a button... place it
    somewhere... give it an instance name. Roughly the equivilant of
    Apple's InterfaceBuilder for those of you that might be familiar
    with Cocoa development. I can see maybe having to put a few lines
    of ActionScript onto frame 1 (though really I'm hoping Flash would
    have a better method of kicking off the application at this point
    that using code tied to frames) to load my classes & such, but
    after that I'd like all of my code to be held in external class
    files.
    So maybe I've got:
    Interface.fla - My interface
    Button_1
    Button_2
    TextField_1
    Main.as - My main controller class using to handle all of my
    applications behavior
    SomeClass.as - Some helper Class
    SomeOtherClass.as - Some helper Class
    Main.as would have instructions in its initialization method
    to go ahead & attach events to buttons & initialize
    anything else that needs to happen when the application starts.
    From there on it would all be objects communicating back &
    forth. Button_1 would get clicked with would fire
    Main.someMethod(). Main.someMethod() would then do it's thing and
    set the value of TextField_1. All very clean & code is very
    separated from interface.
    Unfortunately I can't for the life of me figure out how AS3
    classes reference each other like that. There doesn't seem to be
    any kind of a global 'root' or '_root' I can use to locate any
    movie clips on the stage. I've searched the help & the web for
    any kind of simple tutorial but to no avail. My job has tasked me
    with building a flash app for a project but I'd really rather not
    have a tone of ActionScript just shoved into frame 1. That just
    seems... ugh! (::shudder::)
    Can someone maybe point me in the right direction here? I'm
    really willing to do my homework but I can't seem to locate the
    info I need to get started. Also, is there an ActionScript IRC
    channel or something maybe?
    Thanks,
    Cliff

    I worked with the problem last night and the solution I
    started coming to involved creating my own custom document class
    based off which extends MovieClip. My thought is that way I have
    access to the initialization routine of the timeline itself and
    that all of the elements on the main timeline should be
    "properties" of my custom class.
    Is this correct? Is there a down side to doing this & if
    so what is it & why?
    Also, just for my reference, the last time I did anything
    with ActionScript I think I was using '_root' to target the main
    timeline. WHat are the global variable names in AS 3? Is it just
    'root' & 'stage' or 'Root' & 'Stage' or what?

  • Document Classes and other Questions

    Basically, i am working on an application that will eventually be deployed to the desktop as an AIR application.
    I am wanting to create an Analogue clock and Digital clock with a button that toggles the display between either one when pressed. As well as this, i will be wanting to display the Date below, i am having a number of issues however.
    I have the code sorted for three of the four components, i have not attempted to figure out the button thus far as i would be more than happy to have the digital clock, analogue clock and date all being displayed on a drag and drop desktop application first. When i say i have it sorted, i have a fully working analogue clock which i have managed to display on the desktop through air on its lonesome, however, i did not include the drag and drop function. For the digital clock and date components i am not sure how to configure them into document classes. The main issue i am having is i do not know if you can reference a dynamic text box within a movie clip to a document class.
    This is the code to show the date
    [code]{
    var currentTime:Date = new Date();
    var month:Array = new Array("January","February","March","April","May","June","July","August","September","Octo ber","November","December");
    var dayOfWeek:Array = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
    date_text.text = dayOfWeek[currentTime.getDay()] + " " + currentTime.getDate() + " " + month[currentTime.getMonth()] + " " + currentTime.getFullYear();
    [/code]
    I have put the actionscript frame inside the movie clip file, and i have given both the movie clip, and the dynamic text box within the movie clip the instance name "date_text".
    Basically, i am just struggling in how to put this code into a working document class, since the digital clock and date functions are both, some what similar, i feel the solution to one will more than likely lead to me discovering the solution for the other.
    The other problem i am having, i do not know how i will display all of the components on one air application. I am assuming, that you create one other document class file which links the other four together? i have tried to do this by just linking a new FLA file with the analogue clock, but it does not work. The code for that is below.
    [code]package
              import flash.events.Event;
              import flash.display.MovieClip;
              public class time1 extends MovieClip
                        public var now:Date;
                        public function time1()
                                  // Update screen every frame
                                  addEventListener(Event.ENTER_FRAME,enterFrameHandler);
                        // Event Handling:
                        function enterFrameHandler(event:Event):void
                                  now = new Date();
                                  // Rotate clock hands
                                  hourHand_mc.rotation = now.getHours()*30+(now.getMinutes()/2);
                                  minuteHand_mc.rotation = now.getMinutes()*6+(now.getSeconds()/10);
                                  secondHand_mc.rotation = now.getSeconds()*6;
    [/code]
    That is the original clock document class (3 Movie clips for the moving hands, and the clock face is a graphic, which i may have to reference somehow below)?
    [code]package
              import flash.display.MovieClip;
              public class main extends MovieClip
                        public var hourHand_mc:time1;
                        public var minuteHand_mc:time1;
                        public var secondHand_mc:time1;
                        public function main()
                                  hourHand_mc = new SecondHand();
                                  addChild(mySecondHand);
                                  hourHand_mc.x = 75;
                                  hourHand_mc.y = 75;
                                  minuteHand_mc = new SecondHand();
                                  addChild(mySecondHand);
                                  minuteHand_mc.x = 75;
                                  minuteHand_mc.y = 75;
                                  secondHand_mc = new SecondHand();
                                  addChild(mySecondHand);
                                  secondHand.x = 75;
                                  secondHand.y = 75;
    }[/code]
    This is my attempt at creating the main document class in a seperate FLA file to attempt to load the analogue clock, and later on the Digital Clock, Date Function and Toggle Display button in the same AIR application.
    Any help on this is much appreciated, i have been reading up a lot on it through tutorials and the like, but i can't seem to fully grasp it.

    why do you have code in a movieclip?
    if you want to follow best practice and use a document class you should remove almost all code from timelines.  the only timeline code that might be reasonably used would be a stop() on the first frame of multiframe movieclips.
    so, you should have a document class.  that could contain all your code but it would be better to just have your document class create your 2 clocks and date objects and possibly manage toggling between the two clocks.  you could have a separate class the tracks the time and date and that class is used by your two clock classes and your date class.

Maybe you are looking for

  • How to install Oracle Database Client 32-bit libraries.

    Dear All, In the document : http://download.oracle.com/docs/cd/E10415_01/doc/bi.1013/b31765.pdf it is written "For 64-bit Linux system installations, you must use the Oracle Database Client 32-bit libraries" how can i install just the libraries from

  • Sender RFC scenario not working

    Hi All, I'm trying to configure a scenario where the sender is an RFC. I have done the following configuration steps: 1. Created an RFC destination in the R/3 system.    Program ID: SAPSLDAPI_X3A    Gateway Host: hostname of the XI system    Gateway

  • Component Enhancement Deletion Problem in WEB UI

    Hi All, I created an enhancement set for component ICMPP_BT_SVT and then I had to delete it. I also deleted the records created by enhancement in tables BSPWD_COMP_EXT and BSPWD_CMP_C_REPL. But now I am facing exceptions  while I run this component.

  • Storing a record set into an array

    Hello Again, Yet another road block in my destination to completing my program. I wanted to create a MultiColumn Combobox and needed to store my Database values into an array so I get get them into the Combobox. I'm having trouble getting this code t

  • Does iphone5 supports all the lte bandclasses for lte operators apple supported?

    Recently, apple has announced a list of operators that supports lte, http://www.apple.com/iphone/LTE/. For model A1429(cdma model),Verizon is one of these operators that supports lte. Here's two question,anyone knows? 1.What 's the lte bandclass curr