A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Combining document class with timeline code - help needed please!

  1. #1
    Senior Member
    Join Date
    Jan 2008
    Location
    UK
    Posts
    269

    Combining document class with timeline code - help needed please!

    Hi Chaps,

    I have a problem. I've written a game in Flash using timeline code like this:

    On the main timeline:
    Code:
    stop();
    include "includes/mySourceCode.as";
    init();
    Then, in mySourceCode.as I have a set of functions (including init(), of course). I know this technique of coding is frowned upon by many, but it was what I learned when I started out with Flash and it has always worked well for me. It also means I don't usually have to bother with importing classes to make most methods work as I guess they are all 'built in' to the main timeline already.

    The problem I have now is that I have got the game sponsored, and the sponsor needs me to include his preloader, which is a document classfile. So I have his preloader working, and once loaded it tells the main timeline to proceed to the next frame, where I have my usual code as above - which now doesn't work. Firstly, it can't find my include files because it is now looking in the document class folder instead of the main .fla folder it usually looks in. Secondly, once I have moved my include files to the same folder as the document class, it gives me around 70 errors about undefined properties and methods, and things not being 'compile time constants' whatever that means.

    I am guessing that for some reason, since there is now a document class, Flash is no longer importing all the classes it usually does automatically for me - so could it be that I need to go through my whole game and figure out the class import paths for all the methods I have used? Or is there an easier way to get my code working how it was before without having to change it? If I do impoort all the right classes, should it work then or will I still face problems?

    Thanks for any advice,

    Ric.

    p.s. happy new year everyone.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The provided document class may not be dynamic, which would cause the errors about undefined properties and methods if you refer to things without declaring them first. You could try to add 'dynamic' to the document class like this:
    Code:
    public dynamic class Whatever extends MovieClip{
    You really should look into object oriented programming using classes. As you've seen, you will have to deal with it from sponsors/clients eventually and at this point it's a well established paradigm that the current version of flash was designed to support.

  3. #3
    Senior Member
    Join Date
    Jan 2008
    Location
    UK
    Posts
    269
    Thanks 5T.

    I tried making it dynamic as you suggested, although it still caused the errors. However, I have now imported all of the required classes (turned out not to be as painful as I thought it would be) and it now all works just fine.

    What I don't understand though is why you don't usually have to import these classes when coding on the timeline, yet add in a document class and suddenly you need to do it.

    I'm sure there must be advantages in using a document class and writing custom classes, but I've personally never found any of them. The only time I've ever needed to use this kind of thing is exactly as you said - when I need to work with someone elses code, but thankfully that's not very often.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center