Author Topic: my preloader.as throws an error.  (Read 1956 times)

Lo.wang

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
my preloader.as throws an error.
« 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

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: my preloader.as throws an error.
« Reply #1 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
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Lo.wang

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
Re: my preloader.as throws an error.
« Reply #2 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?

cai

  • Contributor
  • ****
  • Posts: 465
  • Karma: +0/-0
  • the illest of villains
    • View Profile
    • Brandon Cash
Re: my preloader.as throws an error.
« Reply #3 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.
Follow me on Twitter | Come join us at #flixel on irc.freenode.net!

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: my preloader.as throws an error.
« Reply #4 on: Mon, Oct 4, 2010 »
If he sets Main.as to Always Compile it'll skip the preloader entirely.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

Nejuf

  • Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: my preloader.as throws an error.
« Reply #5 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.

OmegaStorm

  • Member
  • **
  • Posts: 36
  • Karma: +0/-0
    • View Profile
    • OmegaStorm Productions
Re: my preloader.as throws an error.
« Reply #6 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();
}
}
}

butchthecat

  • New Member
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: my preloader.as throws an error.
« Reply #7 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.

xhunterko

  • Contributor
  • ****
  • Posts: 449
  • Karma: +0/-0
    • View Profile
Re: my preloader.as throws an error.
« Reply #8 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.
Now on twitter: http://twitter.com/xhunterko I made a game that's in alpha you can buy here: http://xhunterko.itch.io/wave-miner-alpha