How do I add a preloader to my game using flashDevelop? - actionscript-3

Hi I have made a tile based game using a tutorial from this site http://www.wildbunny.co.uk/blog/2011...m-game-part-1/ My game is complete but I want to add a preloader to it.
A little background for a hopefully better understanding.
FlashDevelop is where all of my as3 files and classes are and I can also test my game here and I works fine.
Flash CS6 is where I have only one scene "scene 1" with one frame on it, this frame has all of my tile based images ( movieClips ) and animations in squares, if I double click a movieClip ( for example "player" ) it will go inside and I have got lots of frames ( jumping, running etc ).
I can't test my game from here, It shows errors (scenes are NAN). I think that's normal not sure - maybe off topic anyway.
I have looked on the internet for a tutorial on preloaders suiting my situation but can't find any using flash with flashDevelop and AS3.

You create a brand new project "Actionscript 3 with preloader", FD will generate you a preloader class *.as file, and a main class file with a [frame] directive in it. Copy the preloader *.as file into your current project, copy the directive from new project's Main.as into your project's Main.as, change the package name if needed in both places (in preloader's getDefinitionByName() call and in the directive - fully qualified class names required), add whatever visuals you want to your preloader class, and you're set.
The directive in my case looked like this:
[Frame(factoryClass="Geologist.Preloader")]
The package is Geologist, and the startup() function of the preloader was like this:
private function startup():void
{
var mainClass:Class = getDefinitionByName("Geologist.Main") as Class;
var theStage:Stage = this.stage;
theStage.addChild(new mainClass() as DisplayObject);
theStage.removeChild(this);
}

Related

Action script adding a background

First of all I've just a couple hours experience with Flash and AS3 therefore, I'm sorry if it is a bit easy question.
What I want do to is a simple space war games to learn basics of AS3 and flash. Altough I dont know much things about layers, I think my game should contain two layers, one for background and the second one is for enemies spaceships and our spaceship.
I added a jpeg format file to library to use it as a background. (as you can see from the link :http://prntscr.com/2pe6zb and http://prntscr.com/2pe733 )
And I create a as3 documentFile which is called Arkaplan.as and content of it is:
package{
import flash .display.*;
public class Arkaplan extends MovieClip{
public function Arkaplan(){
var hero:backGround =new backGround();
addChild(hero);
}
}
}
However, I got an error which says that : "1180: Call to a possibly undefined method BackGround."
Is there anyone to help me to solve what is wrong ?
EDIT
When I changed the code above lilke :
package{
import flash .display.*;
public class Arkaplan extends MovieClip{
public function Arkaplan(){
var myBitmap:Bitmap = new Bitmap(new backGround(500, 500));
var myMovieclip:MovieClip=new MovieClip();
myMovieclip.addChild(myBitmap);
addChild(myMovieclip);
trace("deneme 1-2");
}
}
}
Problem is solved but I dont know why it runs correctly know ? To be able to use Bitmap Do I have to add it as a child to movieClip ?
Any time you use the word 'new' you are creating a new object. The word after new will be the name of a Class that Flash will try to locate. You must either have an external .as file that matches that name or have a library item set to 'export for ActionScript' with a Class name that matches that name.
You can access a library item's properties by right-clicking on it in the library and clicking 'properties'. With the 'advanced' option open, check the 'export for ActionScript' box and enter a Class name that matches the one you want to create.

Creating MovieClip 'components' that don't add to file size in Flash AS2/AS3

I want to create a re-usable Flash MovieClip (component maybe?) that can be dragged and dropped from the library onto the Flash IDE stage (for an example, a "stop all movieclips timer component").
I've created some attractive vector icon graphics for visual reference, so that when it's dragged onto the stage, the developer can visually see the component on the stage, similar to what Google does with it's DoubleClick components. It's not important for these icon graphics to be seen at runtime however, and I'd like their visual portions to not be compiled at runtime to save on filesize.
I'm often asked to create visually rich Flash units in extremely small file sizes. So basically I want my movieclip icon components to not add to filesize (except for the code portion), not compile and render visually but still have the code within them run.
How can I achieve this? Would creating them as components do anything for my issue? Is this even do-able?
Components are definitely the best way to achieve visually represented imported code, however it would be much easier, more compatible and more reliable to just use an imported code library...
Make a seperate .as file, put it in com/mycompany/animation in your swf folder (or use a global classpath), and add this code:
package com.mycompany.animation {
class MyTimerUtils {
public static function stopAllClipsAfterTime(ms){
setInterval(MyTimerUtils.stopAllClips, ms);
}
public static function stopAllClips(){
//etc
}
}
}
Then when you want to use it in a project, just put this code on frame 1 of your main timeline:
import code.mycompany.animation.MyTimerUtils;
MyTimerUtils.stopAllClipsAfterTime(3000); // 3 seconds
What could be easier? If another developer wants to know if a piece of code is implemented they need only look at the first few lines of code.

external document class injected into a timeline based Flash app

Here's the situation:
Making an app in Flash CS6 that has 11 frames. Some frames have actions dependent to that frame and then there are some global actions. There are no external classes, everything is incorporated into one flash file.
Now I want to incorporate AdMob and found an offer that should work for me, but it calls for setting a document class linked to external AS file. Doing this messes up my timeline based actions.
I am more front-end that back-end when it comes to designing/programming. So, my question is: How can I incorporate this external admob actionscript into my flash document file without messing up my current scripts? Is there a way to remove it's package attributes and put it on the timeline?
Hope this description wasn't confusing.
Thanks!
Some brief about document class & classes & timeline :
Consider the whole stage as a movieclip. Now the document class would be a user defined, external class for the stage movieclip. When you don't specify the document class, flash uses a predefined one, which derives a plain movieclip class. The frames added from the IDE are converted as calls to addFrameScript and the script in the frames are scheduled to run at an interval as per the frame rate (timeline). Even the shapes you draw, images you add, everything goes in as code in the frame scripts of the stage movieclip.
Now if you add a movieclip onto the stage, the above process is repeated for it as well. You may set a class or derive from an existing class for any movieclip. The class will be initialized when the movieclip instance is created, Be it frame script or place the movieclip itself in the frame.
Now to your question.Any frame script can access the external class as well. So if you have an external class named AdMob in a file AdMob.as, lying next to the fla, you may call it anywhere, in any frame as:
new AdMob()
However you must take care of the package name & path. So if the package for AdMob is abc.bbc.AdMob then the location of the as file should be abc/bbc/AdMob.as
You may import the whole package as :
import abc.bbc.*;

How to properly add "Replay" functionality to a self-preloaded Flash movie?

I made a Flash project in FlashDevelop to create an Ad.
The Preloader is setup by making use of the Additional Compiler argument:
-frame=NameOfLabel,NameOfMainClass
My main class is simply called "Main", at the top / default package level.
So frame #1, being the Preloader portion of the SWF, has:
Very few bitmaps, vector-graphics and text (to stay under 50kb);
A YouTube video player in the center (does not count in the filesize limit);
The frame #2 has everything else (the Main class basically embeds all it's dependencies). This includes:
Assets from precompiled SWF (Bitmaps, Symbols, Fonts, XML data);
All classes imported (this is recursive for every classes importing other classes);
Now my big problem is, my client requested the "replay" functionality long after I've completed 99.9% of the project.
I have the project more-or-less broken into different states (Intro, Ready, SlideMenu, etc.), but I'm not sure how I can easily reset the Flash movie back to the very beginning (where it was preloading and showing the YouTube video).
The easy solution would be to simply call an ExternalInterface JavaScript method that would refresh the Flash container, BUT I don't think I have control over what's going on the HTML / JavaScript side.
Is there an easy way to invoke a replay function from AS3?
Would not simply going back to frame 1 do the trick ?
The following seems to do the trick!
private function onReplayClick(e:MouseEvent):void {
var theStage:Stage = this.stage; //Temporarly store the stage.
//Kill any animations happening:
TweenMax.killAll(); //3rd party, may not be applicable for you :P
//Remove ALL containers / child DisplayObjects
SpriteUtils.recursiveRemove(theStage); //custom-made
// (this object is no longer attached to the stage at this point)
//Nullify any Singleton / Static variables:
Main.INST = null;
// Load the 'bytes' of the current SWF in a new Loader, then...
// add it to the stage
var swf:Loader = new Loader();
swf.loadBytes( theStage.loaderInfo.bytes );
theStage.addChild( swf );
}
By doing a deep recursive cleanup of the DisplayObjects, and any static variables (like Singleton instances), it leaves you with a blank stage.
After that, you can instantiate a new Loader that will load the SWF itself via the current LoaderInfo's bytes property.
Add the Loader to the Stage, and you're up and running again!

linkage issue(i think) in flash AS3

I writing a game in AS3 using flash. The game works, and I'm trying to add music to the game.
I added a mp3 file called Music (linkage Music.mp3)
and I added in the board (which is the whole game ) the following lines
import flash.media.SoundChannel;
public var music:Music;
public var bgmSoundChannel:SoundChannel;
I'm getting error
Type was not found or was not a compile time constant:Music
I had some problems before while trying to use more then one class its seems the my classes doesn't see other classes defined in my fla.
I will be happy to find a solution, and if you know a good explanation about as3 architecture I will be happy to get a link for that as well
The error is because Music is not found as a compile-time class. This is most likely because you have not correctly set its class in the linkage box.
You say its linkage is Music.mp3. This must be Music in order for your code to work.