Flixel Forums

development => help => Topic started by: test84 on Wed, Aug 1, 2012

Title: How to integrate sponsor's loader that is .FLA?
Post by: test84 on Wed, Aug 1, 2012

My sponsor gave me .FLA files that has his loader in it and he instructed on how to integrate it into the game but we use FlashDevelop and not Flash IDE, so how I can use their preloader and replace our  :-* flixel with it?

Title: Re: How to integrate sponsor's loader that is .FLA?
Post by: photonstorm on Thu, Aug 2, 2012
Get someone to compile the FLA into a SWF for you and inject it into your preloader. Or if the FLA just contains maybe 1 movieclip then I'd publish to an SWC and embed that into your project and just display the clip in your preloader.
Title: Re: How to integrate sponsor's loader that is .FLA?
Post by: wg/funstorm on Thu, Aug 2, 2012
I've done this before.

First I tried to do a SWC as photonstorm suggested cause that's what I use for other movieclips, but I couldn't get it to work for their specific file, can't remember why though.

Then I tried my own FlxMovieClip class but that didn't work because the swf has audio.

So then I settled on the SWF loader method. First I compiled it to swf in flash. Then I integrated it in flashdevelop, here's my state. This will not work for you out of the box... there's a bunch of crap in there I had to do to deal with this specific swf and you will probably have to do different things to get yours to work.

Code: [Select]
import flash.display.Loader;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
import flash.display.DisplayObjectContainer;
import org.flixel.*;

* ...
* @author
public class State_Menu_Logo_Sponsor extends FlxState
[Embed(source='../lib/art/ui/sponsorlogo/Intro_TS.swf', mimeType='application/octet-stream')] private var sponsorLogoSwf:Class;
private var _sponsorLogo:Loader;

private var _sponsorLogoMc:MovieClip;

private var _sponsorButton:FlxButton;
private var _sponsorButtonClicked:Boolean;

override public function create():void

_sponsorLogo = new Loader();
_sponsorLogo.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
_sponsorLogo.contentLoaderInfo.addEventListener(Event.COMPLETE, sponsorLogoLoaded);
_sponsorLogo.loadBytes(new sponsorLogoSwf());

_sponsorButton = new FlxButton();
_sponsorButton.makeGraphic(700, 500, 0x0);
_sponsorButton.onUp = btnSponsorClick;

FlxG.stage.frameRate = 70;
_sponsorLogo.addEventListener(Event.DEACTIVATE, focusLost);
_sponsorLogo.addEventListener(Event.ACTIVATE, focusGained);
FlxG.bgColor = 0x0;

_sponsorButtonClicked = false;

private function sponsorLogoLoaded(e:Event):void
_sponsorLogo.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onError);
_sponsorLogo.contentLoaderInfo.removeEventListener(Event.COMPLETE, sponsorLogoLoaded);
_sponsorLogoMc = ((_sponsorLogo.content as MovieClip).getChildAt(1) as MovieClip);
FlxG.stage.addChildAt(_sponsorLogo, 0);

private function onError(e:Event):void

override public function update():void

if (FlxG.stage.frameRate != 70)
FlxG.stage.frameRate = 70;

if (_sponsorLogoMc != null)
if (_sponsorLogoMc.currentFrame == _sponsorLogoMc.totalFrames)
FlxG.stage.frameRate = 30;
_sponsorLogo.removeEventListener(Event.DEACTIVATE, focusLost);
_sponsorLogo.removeEventListener(Event.ACTIVATE, focusGained);
_sponsorLogo = null;
_sponsorLogoMc = null;
FlxG.switchState(new State_Menu_Logo_Developer());

private function btnSponsorClick():void {
if (!_sponsorButtonClicked)
var request:URLRequest = new URLRequest("http://www.yoursponsorurl.com/");
navigateToURL(request, "_blank");
_sponsorButtonClicked = true;
_sponsorButtonClicked = false;

private function focusLost(e:Event):void

private function focusGained(e:Event):void



A bunch of notes:
- I have no idea if this is the best way to do it. It's just what I hacked together after some googling. It works. Good enough for me :P
- FLA was in as2 and I had problems (can't remember what exactly) with using it in my as3 project so I converted it to as3 in Flash.
- FLA was 70fps and my game is 30 so I change the fps when entering, and leaving, and also in update just to be safe cause I had some issues with it.
- Flixel's focus lost screen caused some issues. First it drops the FPS to 10, and then restores it to the one you set in flixel. I remember getting pretty frustrated with this and in the end I simply removed the fps = 10 code from flixel.
- Your movieclip will also not be paused by flixel's focus lost so I added event listeners to deal with that.
- The logo I got had a bunch of nested movieclips, I remember it caused some problems and I just ended up editing the FLA and copying the frames from the nested movieclips to the main timelines after getting frustrated with it. I think the getChildAt(1) is also related to that. If it's not nested I think it would just be this instead '_logoSponsorMc = (_logoSponsor.content as MovieClip);'
- The sponsor button included in the SWF wasn't working so I added an invisible FlxButton over the whole thing.
- Since the button covers everything, when players click it or lose focus and then click back on the game to regain focus it would just open the website again and lost focus again every time you tried. So that's what the buttonClicked boolean is about.
- At first the cursor wasn't showing up because the SWF was on top of the flixel game. So I put the SWF behind the flixel game using addChildAt 0. And also made the flixel background transparent.

Whew... I think that's all the issues I ran into I can remember. It took me almost a full day and was super annoying. Good luck!  :P
Title: Re: How to integrate sponsor's loader that is .FLA?
Post by: test84 on Fri, Aug 3, 2012
Thanks for the replies but my main problem is how to integrate his loader, I managed to use flixel's own loader but he prefers us to use his and I have no idea how to do that, it's in FLA as well.

BTW I'm talking about MaxGames, in case anyone has any experience with their stuff.
Title: Re: How to integrate sponsor's loader that is .FLA?
Post by: 01010111 on Sat, Aug 4, 2012
I may be incorrect, and I've never tried this, but I seem to recall talking about it with someone who had to do this, and they suggested embedding your swf into their project, which would require Flash.