Preloader madness


(Frazer Bennett Wilford) #22

I specify the package in all my classes, but still the same error.

How should var mainClass:Class = getDefinitionByName(“YourGameClass”)

look if my main class is in the same folder as the preloader and is called main.as??


(Mike Evmm) #23

I believe he meant you need to specify it when calling getDefinitionByName like: var mainClass:Class = getDefinitionByName("com.you.stuffToFetch.YourGameClass") even if you are calling it from within the same package as the class you want to call.


(Frazer Bennett Wilford) #24

But my package is nothing:

Like

package { … … }

is how my lowest level classes are ran


(Ultima2876) #25

If you’re using FlashDevelop, make sure you have defined a frame for main. Add -frame main Main to your compile command line in project settings (project > properties in the top menu).


(Frazer Bennett Wilford) #26

Is [Frame(factoryClass = “PreloaderMain”)]

good enough? Which compile do I use? pre-compile, or after?


(Frazer Bennett Wilford) #27

Well I figured it out, though, for a beginner like me, using Flash Punk with a preloader was not obvious. So I think I’ll make a little tutorial and post it at some point :slight_smile:


(rostok) #28

I had some issue with preloader class not being able to initialize class Main. The workaroud for this was having try/catch and repeatedly trying to do init it again in every frame. Here’s a brief code excerpt.

private function hasLoaded (): Boolean 
{
	return (loaderInfo.bytesLoaded >= loaderInfo.bytesTotal);
}

public function onEnterFrame (e:Event): void
{
	if (hasLoaded())
	{
		updateProgress1(1);
		
		try 
		{
			main = new (getDefinitionByName(mainClassName) as Class) as DisplayObject;
	
			parent.addChild(main);
			parent.setChildIndex(main, 0);
			cleanup(); 
		}
		catch (err:Error)
		{
			trace(err, "not yet");
		}
	} 
	else 
	{
		updateProgress1(loaderInfo.bytesLoaded / loaderInfo.bytesTotal);
	}
}```

Any ideas why I sometimes get "not yet" traced?