dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [F8] .as file help

  1. #1
    Senior Member
    Join Date
    Dec 2005
    Posts
    426

    [F8] .as file help

    I want to create a function in a .as file and then load it into my .fla
    like this:

    .as file
    Code:
    test = function(){
    trace("test");
    }
    .fla actionscript
    Code:
    #include "file.as"
    test();

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Posts
    175
    I'm pretty sure you can only define classes in .as files, and I don't think the Flash compiler supports includes, but you can get this effect using static functions.

    TestClass.as:
    Code:
    class TestClass {
    static function Test() {
    trace("test");
    }
    }
    Your FLA (TestClass.as must be in the same directory)
    Code:
    TestClass.Test()

  3. #3
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    you can include an as file, you've got the right code for that. You are just forming your function improperly:

    test.as
    Code:
    function testFunction(){
        trace("This is a Test.")
    }
    main.fla

    Code:
    #include "test.as"
    testFunction();
    also note: included .as files are processed before any code on the frame no matter where the include is located within the script on the frame. So if a function of variable in the frame has the sanme name as a function or variable in the as file, the code in the frame effectively overwrites the code from the as file, even if the #include command is on the last line of the frame.
    Last edited by cresquin; 06-03-2007 at 04:05 AM.

  4. #4
    Senior Member
    Join Date
    Dec 2005
    Posts
    426
    i get this error:
    Code:
    Classes may only be defined in external ActionScript 2.0 class scripts.

  5. #5
    http://pat.theorigin.net cresquin's Avatar
    Join Date
    Jun 2003
    Location
    Los Angeles, CA
    Posts
    685
    you shouldn't get an error like that with my script. I am not creating a class.

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