Flixel Forums

development => help => Topic started by: Lo.wang on Mon, Oct 4, 2010

Title: my preloader.as throws an error.
Post by: Lo.wang on Mon, Oct 4, 2010
I put preloader.as  with


Code: [Select]
package
{
        import org.flixel.FlxPreloader
 
public class Preloader extends FlxPreloader
{
public function Preloader():void
{
className = "Main";
super();
}
}
}


Main.as  exists, and otherwise works and load the game if I dont include the preloader as first compile.    The error it throws is
Quote
[Starting debug session with FDB]
[Fault] exception, information=ReferenceError: Error #1065: Variable Main is not defined.

But  Main exists as a class ::). Any help?  I'm using Flixel 2.43
Title: Re: my preloader.as throws an error.
Post by: photonstorm on Mon, Oct 4, 2010
Have you got this in your compile parameters?

-frame start Main

In FlashDevelop it's in Project Properties, Compiler Options, Additional Compiler Options
Title: Re: my preloader.as throws an error.
Post by: Lo.wang on Mon, Oct 4, 2010
Nope.  But I remember trying flixel a year ago and never had to use that and the flixel logo and preloader worked without issue.

I put that into the compiler option, and now it does not throw an error. But there still is no flixel logo screen being shown.  Its also causing the flash player to start out of proportions or for better not fitting the dimision of the actual game (640 x 480) its like a hundred pixel larger now for some reason showing white parts.

Is the preloader bugged out in flixel 2.43 I wonder?
Title: Re: my preloader.as throws an error.
Post by: cai on Mon, Oct 4, 2010
Right click on 'Main.as' and select 'Always Compile.'

As for the window being too large, that's because there's a project setting for that, instead of it using the one defined in the SWF.  Go to Project->Properties and change the Dimensions there.  Once you save the project, it'll keep it there.
Title: Re: my preloader.as throws an error.
Post by: photonstorm on Mon, Oct 4, 2010
If he sets Main.as to Always Compile it'll skip the preloader entirely.
Title: Re: my preloader.as throws an error.
Post by: Nejuf on Thu, Oct 21, 2010
I've been having the same problem.  The base problem seems to be that the main class is not being compiled with the preloader class.  The root has to do with the way that getDefinitionByName() is performed, but it's not something we can change.

I think the simplest fix is to make some reference to the main class before trying to use the class name.

For example:
Code: [Select]
package
{
import org.flixel.FlxPreloader;
import Main;

public class Preloader extends FlxPreloader
{
Main; //or private var main:Main;

public function Preloader():void
{
this.className = "Main";
super();
}
}
}

You don't have to initialize the class, just get it into the compiler.  So just saying "Main;" or "private var main:Main;" seems to do the trick.
Title: Re: my preloader.as throws an error.
Post by: OmegaStorm on Thu, Oct 21, 2010
Set Main.as to always compile.

Main.as
Code: [Select]
package 
{
    import org.flixel.*; 
    [SWF(width="640", height="480", backgroundColor="#000000")]
    [Frame(factoryClass="Preloader")]
    public class Main extends FlxGame
    {
        public function Main():void
        {
            super(640, 480, YourState, 1)
        } 

    }
}

Preloader.as
Code: [Select]
package
{
import org.flixel.FlxPreloader;

public class Preloader extends FlxPreloader
{
public function Preloader()
{
className = "Main";
super();
}
}
}
Title: Re: my preloader.as throws an error.
Post by: butchthecat on Sat, Nov 6, 2010
This fixed my problem. Thanks!  ;D

I've been having the same problem.  The base problem seems to be that the main class is not being compiled with the preloader class.  The root has to do with the way that getDefinitionByName() is performed, but it's not something we can change.

I think the simplest fix is to make some reference to the main class before trying to use the class name.

For example:
Code: [Select]
package
{
import org.flixel.FlxPreloader;
import Main;

public class Preloader extends FlxPreloader
{
Main; //or private var main:Main;

public function Preloader():void
{
this.className = "Main";
super();
}
}
}

You don't have to initialize the class, just get it into the compiler.  So just saying "Main;" or "private var main:Main;" seems to do the trick.
Title: Re: my preloader.as throws an error.
Post by: xhunterko on Sun, Nov 7, 2010
Try this:

As main.
Code: [Select]
package 
{
    import org.flixel.*;
   
    [SWF(width="640", height="480", backgroundColor="#ffffff")];

    [Frame(factoryClass="preloader")]

    public class Main extends FlxGame
    {
        //public static var bgcolor:uint = 0xff303030;
        //public static var bgcolor:uint = 0xffc0c0c0;
        //public static var bgcolor:uint = 0x66161616;
        public static var bgcolor:uint = 0xffa51cFF;
       
        public function Main():void
        {
            super(320, 240, playstate, 2);
           
           
            FlxState.bgColor = Main.bgcolor;

        }
       
    }
}

as preloader
Code: [Select]
package
{
        import org.flixel.FlxPreloader;
     
        public class preloader extends FlxPreloader
        {
            public function preloader():void
            {
                className = "Main";
                super();
            }
        }
}

Which, is pretty much the same thing omega storm posted.