Jump to content

WidgetFlash: MovieClip event listener adding


photo

Recommended Posts

In your flash00 example in menu.fla you use code added directly on button:

 

on(release) {
Engine.worldCall("menu_quit_clicked");
}

Could you implement another event declaration style, when we use nameButton.onRelease = function() { // do something }? May be it implemented yet, but I have errors while try to use this style (

 

Code style, when we implement actions and events directly on buttons is not good, because when we have many buttons / MovieClips with many events we can't see all picture. We need jump from on graphic element to another via design view or tree of graphical elements to see actions (code), we can't implement actions (code) in external .as-files (using #include directive), we can't use another code editors and we can't use svn with code merging and collaborate work.

Another code style is using names for buttons / MovieClips and declares all listeners in one place (or external .as-files), for example, code from your flash00 could have next look:

newButton.onRelease = function() {
Engine.worldCall("menu_new_clicked");
}

loadButton.onRelease = function() {
Engine.worldCall("menu_load_clicked");
}

quitButton.onRelease = function() {
Engine.worldCall("menu_quit_clicked");
}

Thanks

Link to comment

I try to use flash widgets from newest Unigine update and encounter with two problems:

1. Could you add button's events for MovieClip too? I don't know why, but this works:

movieClipInstance.onEnterFrame = function()
{
trace("onEnterFrame");
}

and this not:

movieClipInstance.onPress = function() 
{
this.gotoAndStop(3);

trace("menu_new_clicked()");
Engine.worldCall("menu_new_clicked");
}

movieClipInstance.onRelease = function()
{
this.gotoAndStop(1);

trace("menu_quit_clicked()");
Engine.worldCall("menu_quit_clicked");
}

movieClipInstance.onReleaseOutside = function()
{
this.gotoAndStop(1);
}

movieClipInstance.onRollOut = function()
{
this.gotoAndStop(1);
}

movieClipInstance.onRollOver = function()
{
this.gotoAndStop(2);
}

This very useful to simulate button functionality with MovieClip, because flash Button have two bad limitations:

1) it haven't disable state.

2) we can't get TextField instance from it to change caption (it useful for game localizations or when we use one button skin for all buttons and change only caption).

So usually we must realize custom button logic based on MovieClip.

 

2. You have bug in MovieClip/Button instances, for example, I have three MovieClip buttons and I use next:

var resume:MovieClip = controls.resume; // get resume movie clip from controls parent-container
resume.txtCaption.text = "Resume"; // set caption to it

resume.onPress = function() 
{
this.gotoAndStop(3);

trace("menu_new_clicked()");
Engine.worldCall("menu_new_clicked");
}

resume.onRelease = function()
{
this.gotoAndStop(1);

trace("menu_quit_clicked()");
Engine.worldCall("menu_quit_clicked");
}

resume.onReleaseOutside = function()
{
this.gotoAndStop(1);
}

resume.onRollOut = function()
{
this.gotoAndStop(1);
}

resume.onRollOver = function()
{
this.gotoAndStop(2);
}

 

So I change default "Label" text to "Resume" on one button, in flash player all good:

post-151-0-87935600-1299839044_thumb.jpg

In Unigine:

post-151-0-91196100-1299839087_thumb.jpg

 

Example menu.fla file attached and can be used in widgets/flash_00 sample:

menu.zip

Link to comment

All is done.

But "this" keyword isn't working correctly inside the functions. Workaround is:

resume.onReleaseOutside = function()
{
       resume.gotoAndStop(1);
}

Link to comment
×
×
  • Create New...