Author Topic: How to integrate sponsor's loader that is .FLA?  (Read 1486 times)

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Hi,

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?

Thanks!
blog, twitter, Check out my award winning game, Rot Gut:

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: How to integrate sponsor's loader that is .FLA?
« Reply #1 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.
http://www.photonstorm.com



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

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: How to integrate sponsor's loader that is .FLA?
« Reply #2 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]
package 
{
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
{
super.create();

_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;
add(_sponsorButton);

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

_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
{
trace(e);
}

override public function update():void
{
super.update();

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

if (_sponsorLogoMc != null)
{
if (_sponsorLogoMc.currentFrame == _sponsorLogoMc.totalFrames)
{
FlxG.stage.frameRate = 30;
FlxG.stage.removeChild(_sponsorLogo);
_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;
}
else
{
_sponsorButtonClicked = false;
}
}

private function focusLost(e:Event):void
{
_sponsorLogoMc.stop();
}

private function focusGained(e:Event):void
{
_sponsorLogoMc.play();
}

}

}

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
« Last Edit: Thu, Aug 2, 2012 by wg/funstorm »

test84

  • Key Contributor
  • *****
  • Posts: 1328
  • Karma: +0/-0
  • ت
    • View Profile
    • My personal site.
Re: How to integrate sponsor's loader that is .FLA?
« Reply #3 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.
blog, twitter, Check out my award winning game, Rot Gut:

01010111

  • Member
  • **
  • Posts: 48
  • Karma: +0/-0
    • View Profile
Re: How to integrate sponsor's loader that is .FLA?
« Reply #4 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.