How To Create a Preloader to a Flash Game - actionscript-3

I'm just beginning to get into flash game programming. I know enough to make a functioning project, but not how to make it efficient or do specific tasks, in this case how to add a preloader. I've found several tutorials online, but none that go along with how I've seen is the best method to program. From what I've seen, it is best to program all of my code into one .as file and link this file to the main document. This makes it easy for me to make all of my variables global in scope, which lets me addChild/removeChild in various different functions. The only problem is that I can't find a tutorial on creating a preloader with this method in mind. All tutorials that I've found generally have two frames in the timeline, one with the preloader and one with the content, but I've been told this is not a good way to program. If anyone could help I'd appreciate it a lot. I can paste the source code of one of my learning projects if it would help to provide an answer to my question.

I wouldn't go with the 2 Frame approach. Instead just make your game with your Document Class, like you said you would like to do.
Then when your done, load your compiled game swf into a loader swf.
Here is a simple example on how your loaderSwf should look like:
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.events.ProgressEvent;
function startLoad()
{
var mLoader:Loader = new Loader();//Or use ProLoader
var mRequest:URLRequest = new URLRequest(“Game.swf”);
mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
mLoader.load(mRequest);
}
function onCompleteHandler(loadEvent:Event)
{
addChild(loadEvent.currentTarget.content);
}
function onProgressHandler(mProgress:ProgressEvent)
{
var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal;
trace(percent);
}
startLoad();
(needs to be wraped in a package and Class if you are using it as Document Class)

Related

AddChild to use external SWF has disabled my buttons I had on original Flash file

I have a Flash file (a website header with 5 buttons for 5 links to webpages).
On my actions layer, I added an external SWF file using the addChild object.
Note that I have very basic knowledge of ActionScript and I had to take some help from Google to setup above script.
The external SWF I have brought in using adChild code is working as an overlay on top of my original flash animation but all the buttons I have on original Flash file as website links have now become disabled. Even the mouseOver effects I applied to those 5 buttons are not responding. Below is my AS3 code:
import flash.net.navigateToURL;
import flash.net.URLRequest;
stop();
var swfRequest:URLRequest = new URLRequest("movie/txtOverlay.swf");
var swfLoader:Loader = new Loader();
swfLoader.load(swfRequest);
addChild(swfLoader);
button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.example.com/link1.asp"), "_self");
}
For the sake of brevity, I have placed just one button's code but you get the idea. Any solution to avoid this?
Thanks ... Syed

ActionScript3 DataGrid how to display content on browser

Thanks very much for being the most answered community on the web.
I have this small problem:
I want to read a database using Tomcat Servlets into a ActionScript DataGrid.
Please mind that I want it to be pure ActionScript; no mix with MXML.
I have already done a exercise with MXML and DataGrid but it is not meeting my requirement.
I want to understand how to use ActionScript libraries.
thanks for listening
Here is the code:
package {
import flash.display.*;
import spark.components.DataGrid;
import mx.collections.ArrayList;
public class EmpDBDebug extends Sprite {
public var empDG:DataGrid;
public var DGArray:Array = [
{Album:'Slanted and Enchanted'},
{Album:'Brighten the Corners'}];
public var DGArrayList:ArrayList;
public function EmpDBDebug() {
empDG = new DataGrid();
DGArrayList = new ArrayList(DGArray);
empDG.dataProvider = DGArrayList;
addChild(empDG);
}
}
}
This is a simplified version of what I want to do. I have replace Servlet with Array. All I want to do is display the DataGrid content on browser. I am not able to do that. It is refreshing but everything is blank. Hope I am doing something wrong. I tried everything. I replace Sprite with Stage but still nothing works.
Since I want to do it in pure ActionScript without using MXML, are there any other libraries which I should be using. And again I am mostly using Notepad++ and MonsterDebugger. I do not have access to fl.data.DataProvider libraries. Let us rule it for the time being. I am bit confused with Flash Licensing. Can I do it with Apache Flex?
Can you throw some light.
thanks again
RR23850

Intellij IDEA and Flex SDK runtime shared library

I am trying to make IntelliJ IDEA 12 configure rsl libraries for runtime loading.
Do you have any experience with that, and do you maybe have a sample XML you put into aditional compiler options?
Also, I didnt find the plugin for this, if you know any please say
update:
To clarify the practice project more:
I want to make 2 'swf's that will have one tweening library used on a simple shape, but I want to make that tweening library crossdomain rsl.
Then the goal is to in MainApp load and add to stage one swf and then the other. What I expect to happen is that the first time rsl will be loaded and the second time it will be used from cache.
I am programing in pure AS3. Examples would be wonderful :)
Right now I am trying to build one class that has RedSquare and tweening applied to that square. Ofcourse, tweening should come from rsl library.
Update 2:
I got to the point where I create [Frame(factoryClass='path.to.class')] and I create Preloader.
But here now I dont know how to make a preloader that would load rsl's and then go to the next frame, or main class. What [Frame] tag does, is it makes two frames, one for preloader, and one for main class that should be executed after.
Config I pass to the compiler:
<flex-config>
<!-- A list of runtime shared library URLs to be loaded before applications start. -->
<!-- GreenSock -->
<runtime-shared-library-path>
<path-element>/Users/matej/Documents/Projects/Work/External/greensock-as3/greensock.swc</path-element>
<rsl-url>http://localhost/~matej/rsls/greensock.swf</rsl-url>
<policy-file-url>http://localhost/~matej/rsls/crossdomain.xml</policy-file-url>
<rsl-url>http://localhost/rsls/greensock.swf</rsl-url>
<policy-file-url>http://localhost/rsls/crossdomain.xml</policy-file-url>
</runtime-shared-library-path>
<!-- static-link-runtime-shared-libraries: statically link the libraries specified by the -runtime-shared-libraries-path option.-->
<static-link-runtime-shared-libraries>false</static-link-runtime-shared-libraries>
</flex-config>
main class
package {
import com.greensock.TweenLite;
import Preloader;
import flash.display.Sprite;
import flash.events.MouseEvent;
[Frame(factoryClass="Preloader")]
public class RedSquare extends Sprite{
//---------------------------------------------------------------
// Private variables
//---------------------------------------------------------------
private var redRectangle:Sprite;
//---------------------------------------------------------------
// Constructor
//---------------------------------------------------------------
public function RedSquare() {
redRectangle = new Sprite();
redRectangle.graphics.beginFill(0xFFFF0000);
redRectangle.graphics.drawRect(100,100,50,30);
redRectangle.graphics.endFill();
addChild(redRectangle);
redRectangle.addEventListener(MouseEvent.MOUSE_OVER,onOver);
}
//---------------------------------------------------------------
// Public methods
//---------------------------------------------------------------
//---------------------------------------------------------------
// Private methods
//---------------------------------------------------------------
private function onOver(event:MouseEvent):void {
TweenLite.to(redRectangle,3,{x:400,y:200,rotation:160})
}
}
}

Flash preloader

So I've designed a circular preloader that get filled according the percentage of loaded frames.
Everything works great with a frame or two of content aside preloader. When I add the all site with a billion of frames and movie clips, the preloader won't work properly and I'm getting really bored with this because I spent like 4 days trying to understand what is wrong.
Unfortunately, I couldn't find the problem I hope that the pro's can give me an explanation of what is going wrong. Thank you all.
Code from preloader:
import flash.display.*;
import flash.events.ProgressEvent;
import flash.events.Event;
stop();
this.loaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
this.loaderInfo.addEventListener(Event.COMPLETE, loaded);
function loading(e:ProgressEvent):void{
var porcent:Number = Math.floor((e.bytesLoaded / e.bytesTotal) * 100);
porcent_txt.text = String(porcent) + "%";
loader.gotoAndPlay(porcent);
}
function loaded(e:Event):void{
this.loaderInfo.removeEventListener(ProgressEvent.PROGRESS, loading);
this.loaderInfo.removeEventListener(Event.COMPLETE, loaded);
gotoAndStop("enter");
}
You need to check if your library items are not exported to the first frame.
A normal flash file should have nothing except the preloader on the first frame. Don`t use any other classes except the one you need for the preloader in the first frame.
So first of all, thank you very much for your help it was very helpfull
The code was ok
the preloader movieclip was ok also
The problem was on a layer with some text in fact I don't know why this problem happend my guess is that it must be related with deeper problems in my project... don't know
Thank you again.

Using Squiggly in Flash CS5

This is going to seem quite a lame question - basically we have downloaded a package called Squiggly - http://labs.adobe.com/technologies/squiggly/ - and we are trying to implement it into Flash (using AS3, CS5). And none of us are very good at flash, and have no clue how to do it, the actionscript in the .as is as follows:
package
{
import flash.display.Sprite;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import flashx.textLayout.edit.EditManager;
import com.adobe.linguistics.spelling.SpellUIForTLF;
public class SquigglyTLFExample extends Sprite
{
public function SquigglyTLFExample()
{
var markup:XML = <TextFlow xmlns='http://ns.adobe.com/textLayout/2008'><p><span>I know </span><span fontStyle='italic'>Enlish</span><span>. Use the context menu to see the suggestions of the missbelled word.</span></p></TextFlow>;
var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
textFlow.flowComposer.addController(new ContainerController(this, 500, 600));
textFlow.flowComposer.updateAllControllers();
textFlow.interactionManager = new EditManager();
SpellUIForTLF.enableSpelling(textFlow, "en_US");
}
}
}
I have a blank swf, and just want to know how to implement it to a text area. Why do people still use flash? :(
Here's how I got it running in a new FLA file in Flash CS 5:
1) In Flash, go into 'Advanced Actionscript 3.0 Settings' and change to the Librarys path tab on the middle of that pane.
2) Add the AdobeSpellingUITLF.swc.
3) When the SWC has been added, select it in the list and click the little 'I'-icon(when you hover it, it should say: 'Set linkage options for a library').
Change the link type to 'Merged into code'.
4) Add the code you posted (SquigglyTLFExample) as your Document class.
5) Remember to copy the 'AdobeSpellingConfig.xml' and the 'dictionaries'-folder to the same folder as the generated SWF-file.
The configuration in Flash should look something like this:
i have built a class based on squiggle a while ago: http://apdevblog.com/actionscript-spell-checking-with-squiggly-as3-only-and-flash-9-compatible/
it's very easy to use and compatible with normal textfields >flash9.
cheers