Flash GUI Component
by Thomas \"Man of Ice\" Lund · 02/04/2005 (12:58 pm) · 188 comments
Behold the power of flashy flash
Version history
Version 1.5 - 2005-09-05
- commented out the gameswf::clear() to get rid of exit crash bug
- updated with CVS from 5th of September 2005
- added anti alias switch
Version 1.4 - 2005-04-23
- resizing the component now reinitializes the movie to keep it from going blank
- added gotoFrame method that moves to the numbered frame
- added gotoNamedFrame method that moves to the named frame
- added callMethod method to call functionality inside flash movies
- reorganized files, so its easier to merge gameswf and base files
- Updated GameSWF files with CVS version of GameSWF from 23rd April 2005
Version 1.3 - 2005-03-02
- Fixed bug with mouse press being handled wrongly, resulting in having to double click on buttons
- Updated GameSWF files with CVS version of GameSWF from 2nd March 2005
Version 1.2 - 2005-02-08
- Fix to the command callback. Should work now
- Added stopMovie command
- Added restartMovie command
- Added stubbed out sound support
- Added setting/getting flash variables
- Fixed bug with mouse coordinates when rescaling the gui
Version 1.1 - 2004-02-05
- Little restructuring of file to be more readable
- Implemented mErrorDisplayed variable, so errors are only shown once instead of spamming the console
- Extended the loadMovie() method to take optional looping and alpha values to save some typing
- Implemented sending keyboard input to the flash movie
Version 1.0 - 2004-02-04
- First public release
What is this?
This is a GUI component that allows you to display SWF flash movies. It is based on GameSWF.
GameSWF is a public domain implementation of the SWF format, and can (and has been) used in commercial products without royalty payments. Disclaimer: I am not a lawyer, so check up yourself.
The point of using flash for things like menus, text renderers or movies is, that it has fantastic editor support and every multimedia artist out there knows it. Its very easy to make eye candy for your games - and the text scales with resolution ;-)
It does _not_ support sound. Please use the TGE sound player for that.
It does however have callbacks for action script, so you can hook your flash up to the engine. This is untested though.
It also sends mouse movement and click events to the flash, so that you can trigger buttons and similar inside the flash
Screenshots and movies
The screenshot shows a flash movie with almost 100% transparent background.
A movie showing that buttons and some animation routines work is here
www.codejar.com/tge_flash/flash_demo.wmv
Download
The file is too large for uploading here, so grab the zip containing the code + a few demo flash movies from
www.codejar.com/tge_flash/torque_gameswf.zip
Patching the Engine using STL_fix
GameSWF uses STL. So much, that there was need for an easier solution than recoding it all.
To the rescue is a unreleased (yet) resource from Dean Calver (thanks a lot!!!) that patches the engine to allow usage of STL together with still running the TGE memory manager.
In the zip file there is a stl_fix.h. Please copy this to your engine/core folder and add to the project.
Whenever you have some code that uses STL, include this stl_fix.h (and most likely also platform/platform.h) BEFORE the STL includes, and everything works like a charm.
But there are also changes to the engine to make this work. Please follow the steps outlined below.
Open platform/platform.h
Find this in line 396
Open the file platform/platformMemory.cc
Find this in line 1080
Open platformWin32/winMemory.cc
Find this in line 41
Adding GameSWF and guiFlash to the Engine
Add GameSWF folder and guiFlash.cc (from the zip) to your project somewhere in the engine/ hierachy
Recompile - easy :-)
Please note, that the code is known _not_ to compile in VC6. It is also not tested on Mac or Linux. Please contribute to this resource by getting it to run on those platforms.
How to use
Once added to your GUI, it is very easy to use this resource. The script API is below. In addition there are callback functions in the guiFlash.cc code.
Version history
Version 1.5 - 2005-09-05
- commented out the gameswf::clear() to get rid of exit crash bug
- updated with CVS from 5th of September 2005
- added anti alias switch
Version 1.4 - 2005-04-23
- resizing the component now reinitializes the movie to keep it from going blank
- added gotoFrame method that moves to the numbered frame
- added gotoNamedFrame method that moves to the named frame
- added callMethod method to call functionality inside flash movies
- reorganized files, so its easier to merge gameswf and base files
- Updated GameSWF files with CVS version of GameSWF from 23rd April 2005
Version 1.3 - 2005-03-02
- Fixed bug with mouse press being handled wrongly, resulting in having to double click on buttons
- Updated GameSWF files with CVS version of GameSWF from 2nd March 2005
Version 1.2 - 2005-02-08
- Fix to the command callback. Should work now
- Added stopMovie command
- Added restartMovie command
- Added stubbed out sound support
- Added setting/getting flash variables
- Fixed bug with mouse coordinates when rescaling the gui
Version 1.1 - 2004-02-05
- Little restructuring of file to be more readable
- Implemented mErrorDisplayed variable, so errors are only shown once instead of spamming the console
- Extended the loadMovie() method to take optional looping and alpha values to save some typing
- Implemented sending keyboard input to the flash movie
Version 1.0 - 2004-02-04
- First public release
What is this?
This is a GUI component that allows you to display SWF flash movies. It is based on GameSWF.
GameSWF is a public domain implementation of the SWF format, and can (and has been) used in commercial products without royalty payments. Disclaimer: I am not a lawyer, so check up yourself.
The point of using flash for things like menus, text renderers or movies is, that it has fantastic editor support and every multimedia artist out there knows it. Its very easy to make eye candy for your games - and the text scales with resolution ;-)
It does _not_ support sound. Please use the TGE sound player for that.
It does however have callbacks for action script, so you can hook your flash up to the engine. This is untested though.
It also sends mouse movement and click events to the flash, so that you can trigger buttons and similar inside the flash
Screenshots and movies
The screenshot shows a flash movie with almost 100% transparent background.A movie showing that buttons and some animation routines work is here
www.codejar.com/tge_flash/flash_demo.wmv
Download
The file is too large for uploading here, so grab the zip containing the code + a few demo flash movies from
www.codejar.com/tge_flash/torque_gameswf.zip
Patching the Engine using STL_fix
GameSWF uses STL. So much, that there was need for an easier solution than recoding it all.
To the rescue is a unreleased (yet) resource from Dean Calver (thanks a lot!!!) that patches the engine to allow usage of STL together with still running the TGE memory manager.
In the zip file there is a stl_fix.h. Please copy this to your engine/core folder and add to the project.
Whenever you have some code that uses STL, include this stl_fix.h (and most likely also platform/platform.h) BEFORE the STL includes, and everything works like a charm.
But there are also changes to the engine to make this work. Please follow the steps outlined below.
Open platform/platform.h
Find this in line 396
extern void* FN_CDECL operator new(dsize_t size, const char*, const U32); extern void* FN_CDECL operator new[](dsize_t size, const char*, const U32); extern void FN_CDECL operator delete(void* ptr); extern void FN_CDECL operator delete[](void* ptr); #define new new(__FILE__, __LINE__)and change to this
extern void* FN_CDECL operator new(dsize_t size); extern void* FN_CDECL operator new[](dsize_t size); extern void FN_CDECL operator delete(void* ptr); extern void FN_CDECL operator delete[](void* ptr); extern void dPopMemManFileLine( const char*&, U32& ); extern int dPushMemManFileLine( const char*, const U32 ); #define new dPushMemManFileLine( __FILE__, __LINE__ ) ? 0 : new
Open the file platform/platformMemory.cc
Find this in line 1080
#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
// Manage our own memory, add overloaded memory operators and functions
void* FN_CDECL operator new(dsize_t size, const char* fileName, const U32 line)
{
return Memory::alloc(size, false, fileName, line);
}
void* FN_CDECL operator new[](dsize_t size, const char* fileName, const U32 line)
{
return Memory::alloc(size, true, fileName, line);
}
void* FN_CDECL operator new(dsize_t size)
{
return Memory::alloc(size, false, NULL, 0);
}
void* FN_CDECL operator new[](dsize_t size)
{
return Memory::alloc(size, true, NULL, 0);
}and change to this#if !defined(TORQUE_DISABLE_MEMORY_MANAGER)
static const int NUM_NEW_STACK_SIZE = 256;
static struct { const char* filename; U32 line; } g_NewStackMemDebug[NUM_NEW_STACK_SIZE];
static int g_CurStack = -1;
int dPushMemManFileLine( const char* filename, U32 line )
{
if(g_CurStack >= NUM_NEW_STACK_SIZE )
return 0;
g_CurStack++;
g_NewStackMemDebug[g_CurStack].filename = filename;
g_NewStackMemDebug[g_CurStack].line = line;
return 0; // needed for the new passthrough trick
}
void dPopMemManFileLine( const char*& filename, U32& line )
{
if( g_CurStack < 0 )
{
filename = 0;
line = 0;
return;
} else
{
filename = g_NewStackMemDebug[g_CurStack].filename;
line = g_NewStackMemDebug[g_CurStack].line;
g_CurStack--;
}
}
// Manage our own memory, add overloaded memory operators and functions
void* FN_CDECL operator new(dsize_t size)
{
const char* fileName = 0;
U32 line;
dPopMemManFileLine( fileName, line );
return Memory::alloc(size, false, fileName, line);
}
void* FN_CDECL operator new[](dsize_t size)
{
const char* fileName = 0;
U32 line;
dPopMemManFileLine( fileName, line );
return Memory::alloc(size, true, fileName, line);
}Open platformWin32/winMemory.cc
Find this in line 41
void* FN_CDECL operator new(dsize_t, void* ptr)
{
return (ptr);
}and change to thisvoid* FN_CDECL operator new(dsize_t, void* ptr)
{
const char* fileName = 0;
U32 line;
dPopMemManFileLine( fileName, line ); // dummy does nothing except keep the stack in order
return (ptr);
}Adding GameSWF and guiFlash to the Engine
Add GameSWF folder and guiFlash.cc (from the zip) to your project somewhere in the engine/ hierachy
Recompile - easy :-)
Please note, that the code is known _not_ to compile in VC6. It is also not tested on Mac or Linux. Please contribute to this resource by getting it to run on those platforms.
How to use
Once added to your GUI, it is very easy to use this resource. The script API is below. In addition there are callback functions in the guiFlash.cc code.
guiFlash.loadMovie("[i]path to flash movie relative to exe file[/i]", [i]optional looping true|false[/i], [i]optional alpha for background[/i]);Loads a flash movie. The path is relative to the exe file. If the flash file loads other movies, the paths they load are also relative to the exe file.guiFlash.playMovie();Plays the currently loaded movie
guiFlash.restartMovie();Restarts the loaded movie
guiFlash.stopMovie();Stops the currently playing movie
guiFlash.setBackgroundAlpha([i]alpha value between 0 and 1[/i]);Sets the background alpha to the specified value
guiFlash.setLooping([i]true|false[/i]);Set the flash movie to loop instead of stop after the last frame is displayed.
guiFlash.setFlashVariable([i]path to variable[/i], [i]new value[/i]);Sets a variable in the flash movie to the specified new value
guiFlash.getFlashVariable([i]path to variable[/i]);Returns the specified variable from the flash movie
#182
02/22/2009 (4:50 pm)
Are there any differences in implementation and/or scripting for use with TGB?
#183
Basically it builds perfectly but when i go into my project folder it doesn't give me a different exe to use so Im guessing im doing something wrong in the output part somewhere. when I start up the only available exe there is no guiflash control in the list when i hit f10.
And i know when you successfully build a new torque demo is comes in as like Torque_demo.exe and it didn't, any advice?
03/14/2009 (2:11 pm)
Okay so as far as I know I have implemented the engine code to theb est of my ability and I am still having problems. The guiflash.cc and the gameswf folder are in the ENGINE folder in the TGE_1_5_2 folder and then I built it with the gameswf.h as well. Im thinking im doing something wrong in the output files when i build torque demo. Is it in general that I and then change the output there or is it in linker general???Basically it builds perfectly but when i go into my project folder it doesn't give me a different exe to use so Im guessing im doing something wrong in the output part somewhere. when I start up the only available exe there is no guiflash control in the list when i hit f10.
And i know when you successfully build a new torque demo is comes in as like Torque_demo.exe and it didn't, any advice?
#184
03/14/2009 (2:28 pm)
okay new development....i got the torquedemo_DEBUG.exe to show up but when i double click on it i get a whole bunch of debug assertion failed.
#185
amoung a couple other different expression errors as well as a HEAP CORRUPTION DETECTED.
03/14/2009 (3:38 pm)
okay one of the possibilities that I found if that it could be a lib error between debugging and the actual program http://www.zeroc.com/faq/windowsLibraryMixup.html it is explained here. However Im not sure if this is 100% related to torque but its giving the exact debug assertion failed errors such as expresion:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)amoung a couple other different expression errors as well as a HEAP CORRUPTION DETECTED.
#186
03/14/2009 (10:44 pm)
Okay I feel like a moron..when I built I was using \ slashes instead of / for my output file...but is all this code supposed to produced a new guiflash control when you go into the guieditor, because if it is supposed to do that I did something wrong...
#187
03/15/2009 (12:00 am)
yeah...Definitely not seeing this new gui control that should be popping up in the list. guiFlash.cc is in the engine folder, the stl is in the core folder like it should be...the engine built perfectly, the exe works and but still no guiFlash control that I can put into my gui, what went wrong??? What seems strang to me is when i open up the sln and go to the gui I see all the cc's and the .h's for all the other guiControls....is in't strange that the guiFlash.cc doesnt og in any of those folders??? Like game, control or etc?? anddd where is the .h for guiflash?? is it the gameswf.h???
#188
From console.log:
and here is the gui code:
I've verified that the c++ code is correct. Anyone have any ideas?
04/21/2010 (7:51 pm)
I'm using this resource in TGB 1.7.4 and am receiving an error saying that the GuiFlash class can't be found in the script:From console.log:
Loading compiled script C:/TGB_Flash/games/TutorialBase/game/gui/flash.gui. game/gui/flash.gui (31): Unable to instantiate non-conobject class GuiFlash.
and here is the gui code:
%guiContent = new GuiControl(NewGui) {
canSaveDynamicFields = "0";
isContainer = "1";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
new GuiFlash() {
canSaveDynamicFields = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "right";
VertSizing = "bottom";
Position = "0 0";
Extent = "800 600";
MinExtent = "8 2";
canSave = "1";
Visible = "1";
hovertime = "1000";
movieName = "car_smash.swf";
backgroundAlpha = "1";
loopMovie = "0";
};
};
//--- OBJECT WRITE END ---
function GuiPlayer::onWake( %this )
{
GuiFlash.playMovie();
}I've verified that the c++ code is correct. Anyone have any ideas?
Torque Owner Thomas \"Man of Ice\" Lund
Sorry, no changes that I know off. All my daily game dev is now done using Unity, so not really using Torque anymore at the moment. Maybe someone else has made changes and want to post them.
In general you can pass variables using the set/getFlashVariables. You should also look into updating the GameSWF sources from their site. If I recall its only 5-6 lines that need changing to get the rendering correct.
Good luck