AS3 Error 1144: Method Implemented with Incompatible Signature - actionscript-3

I'm working with the OSMF library REOPS [https://code.google.com/p/reops/]. Particularly the REOPS.zip project files. [https://code.google.com/p/reops/downloads/detail?name=REOPS.zip]
When trying to compile the RE_Skin_Compiled.fla, I receive the following error:
ClosedCaptionField.as, Line 14, Column 15 1144: Interface method get text in namespace com.realeyes.osmfplayer.controls:IClosedCaptionField is implemented with an incompatible signature in class com.realeyes.osmfplayer.controls:ClosedCaptionField.
This error is detailed by Adobe here: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/compilerErrors.html
Which states:
Method signatures must match exactly.
There are only two methods in the IClosedCaptionField interface, and they do match what is implemented in the ClosedCaptionField class.
IClosedCaptionField.as
package com.realeyes.osmfplayer.controls
{
import flash.text.TextFormat;
public interface IClosedCaptionField extends ISkinElementBase
{
function get text():String;
function set text(p_value:String):void;
}
}
ClosedCaptionField.as
package com.realeyes.osmfplayer.controls
{
import flash.text.TextField;
import flash.text.TextFormat;
/**
* Displays captions for media in the control bar. Accepts HTML
* text (limited by Flash HTML display). This component starts
* out invisible, and must be manually made visible.
*
* #author RealEyes Media
* #version 1.0
*/
public class ClosedCaptionField extends SkinElementBase implements IClosedCaptionField
{
public var cc_txt:TextField;
public function ClosedCaptionField()
{
super();
//start up hidden
//this.visible = false;
//text = "";
}
/**
* text
* The HTML text to display
*
* #return String
*/
public function get text():String
{
return cc_txt.htmlText;
}
public function set text(p_value:String):void
{
if (cc_txt)
{
cc_txt.htmlText = p_value;
}
trace("set cc text: " + p_value);
}
}
}
In the RE_Skin_compiled.fla Actionscript Settings, I have added the path to the REOPS\src\ folder, and it is able to find the classes when checking the properties on the AS Linkage.
Any ideas on what I might be missing in order to get the RE_Skin_Compiled.fla to correctly compile along with it's skin classes?

In the RE_Skin_compiled.fla, there is an included [underscore]code[underscore] compiled clip object which was causing the issues with conflicting classes.
After deleting the [underscore]code[underscore] compiled clip, the fla compiled with the linked classes correctly.

Related

Why is my class not showing up in autocomplete?

My class was not showing up in autocomplete. It was part of another file and I copied it into it's own file.
The reason it was not showing up was because it was marked internal.
package com.example.model
{
/**
* Holds data.
* */
internal class ChartItemData extends Item {
}
}
The part that was confusing was that it was the only class inside the package. I didn't know you could do that.
I changed it to public and it was immediately visible.

Display check boxes inside flash list control CS6

I would like to implement check boxes inside flash list control using Flash Pro CS6. I literally follow example provided by Adobe at Work with a CellRenderer. The only code in my .fla file is:
myList.setStyle("cellRenderer", CustomCellRenderer);
myList.addItem({label:"Burger -- $5.95"});
myList.addItem({label:"Fries -- $1.95"});
and the only code in the CustomCellRenderer.as file is (copy-paste from the Adobe example):
package
{
import fl.controls.CheckBox;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
public class CustomCellRenderer extends CheckBox implements ICellRenderer {
private var _listData:ListData;
private var _data:Object;
public function CustomCellRenderer() {
}
public function set data(d:Object):void {
_data = d;
label = d.label;
}
public function get data():Object {
return _data;
}
public function set listData(ld:ListData):void {
_listData = ld;
}
public function get listData():ListData {
return _listData;
}
}
}
When I test movie I get the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.controls::CheckBox/drawLayout()
at fl.controls::LabelButton/draw()
at fl.core::UIComponent/drawNow()
at fl.controls::List/drawList()
at fl.controls::List/draw()
at fl.core::UIComponent/callLaterDispatcher()
Any help would be greatly appreciated.
P.S. The author of similar question Display checkbox inside Flash List Control ? (Similar to item rendering in Flex) does not seem to have this problem - his problem is just in multiple selection functionality.
ANSWER (can not post answers for another 8 hour but eager to close the issue) Figured out myself: CheckBox component must be present in the library. Go to menu Window->Components-> Double click CheckBox. Check box will appear on the stage and in the library. Remove check box from the stage. Test movie.
Drag an instance of CheckBox component onto the stage then delete off the stage.

[Event(name=“”)]: How is it used and how do custom events work?

I have to work on a project someone else started, but can't contact him because he's out of the country at the moment. Anyway. There is a main mxml and a custom component called "admin".
In admin he declared an event like this:
<fx:Metadata>
[Event(name="sluitFrame")]
</fx:Metadata>
And in a certain function within the component, this event is called upon like this:
dispatchEvent(new Event("sluitFrame"));
This event sluitFrame closes a frame with some admin tools. I need to change the way this works so i'd like to find the corresponding code. On the main mxml there's this code:
<comp:Admin id="compAdmin" creationPolicy="none"
sluitFrame="verbergAdminComponent(event)"/>
So if i understand correctly sluitFrame calls to a custom even called "verbergAdminComponent(event)". So i guess i need this event to change the way the admin frame is closed etc. But this event is nowhere to be found. So I don't understand how "verbergAdminComponent(event)" works or where I can make changes to this event.
Any help is more than welcome and very much needed :)
The [Event... line simply lets the compiler and IDE know that the component/class (in this case, Admin) may dispatch an event by that name. This is important because when someone declares an instance of Admin in a MXML tag, the compiler knows that this event (in this case, sluitFrame) is a valid property. In other words, it lets the compiler know that you can set an event listener in the MXML tag. In your case, every time the Admin object dispatches a sluitFrame event, the function verbergAdminComponent is called and the sluitFrame Event is passed to it.
verbergAdminComponent would be the name of an event handler. It should be a method either in the mxml, in an included .as, or in a base class of that MXML.
Types in Events
If you use an Event in Flash, you could dispatch any named type, since it is a string. So it does not matter how you call it, as long as the listener listens to the exact same type. That's why it works. There is no magic evolved. However, I would choose to use an custom event in that case.
How custom events work
Take a look at custom events work, so you also understand where meta data comes in.
package com.website.events
{
import flash.events.Event;
/**
* #author ExampleUser
*/
public class MyCustomEvent extends Event
{
/**
*
*/
public static const CLOSE_WINDOW:String = "MyCustomEvent.closeWindow";
public function MyCustomEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false):void
{
super(type, bubbles, cancelable);
}
override public function clone():Event
{
return new MyCustomEvent(this.type, this.bubbles, this.cancelable);
}
override public function toString():String
{
return formatToString("MyCustomEvent", "type", "bubbles", "cancelable", "eventPhase");
}
}
}
I use a static constant instead of directly a string (like your example), so it is typed more strictly.
In actionscript, you'd dispatch the custom event like this. Let's say you create a class named Window.
package com.website.ui
{
/**
* #eventType com.website.events.MyCustomEvent.closeWindow
*/
[Event(name="MyCustomEvent.closeWindow", type="com.website.events.MyCustomEvent")]
import flash.display.Sprite;
import flash.events.MouseEvent;
import com.website.events.MyCustomEvent;
/**
* #author ExampleUser
*/
public class Window extends Sprite
{
public var mcCloseButton:Sprite;
public function Window():void
{
this.mcCloseButton.addEventListener(MouseEvent.CLICK, handleCloseButtonClick);
}
private function handleCloseButtonClick(event:MouseEvent):void
{
this.dispatchEvent(new MyCustomEvent(MyCustomEvent.CLOSE_WINDOW));
}
}
}
This is the class where the meta data should be located. This class is dispatching the event. Other classes that dispatches the same event, could have the meta-data too.
So, Window is dispatching an event with type CLOSE_WINDOW when user clicked on the close button. In another file you would listen to it and do something with it.
package com.website
{
import flash.display.Sprite;
import com.website.events.MyCustomEvent;
import com.website.ui.Window;
/**
* #author ExampleUser
*/
public class Main extends Sprite
{
private var _window:Window;
public function Main():void
{
this._window:Window = new Window();
// a smart code-editor would give you a hint about the possible events when you typed "addEventListener"
this._window.addEventListener(MyCustomEvent.CLOSE_WINDOW, handleWindowClosed);
this.addChild(this._window);
}
private function handleWindowClosed(event:MyCustomEvent):void
{
// do something
this._window.visible = false;
}
}
}
This should work.
Ofcourse in a real-world situation MyCustomEvent would be named WindowEvent.
Event Meta Data
The meta data could be used to give hints to the compiler and nowadays smart code editors (FDT, FlashDevelop, FlashBuilder, IntelliJ etc.) can give code completion. It's basically a description of what kind of events may be dispatched by a class, so you know what listeners could be used.
The code should work even when the meta data is deleted.
The Event meta has a name and a type. The name should be the exact value of the type. In the case of our example, it should be the value of CLOSE_WINDOW, so that's MyCustomEvent.closeWindow.
The type should be the classname with the full package, in the case of our example it would be 'com.website.events.MyCustomEvent'.
Finally, the meta data looks like this:
[Event(name="MyCustomEvent.closeWindow", type="com.website.events.MyCustomEvent")]
BTW I have some tips about your code:
I would suggest to use English function names and parameters, instead of Dutch.
verbergAdminComponent isn't a good name for a handler, it should be something like handleCloseWindow(event), which should call the verbergAdminComponent function.

AS3 add an image to an "extended" movie clip

In AS3 - I use a generic button handler to deal with on-click events on a movie clip object. For the last 4 hours I’ve been trying to add an image to this movie clip (see * * *) object.
The code (I cut and pasted a bit but this all compiles without any errors)
btPlay = new mcButtonPlay(this,"ClickMe",GameImage); // GameImage is an BitmapData object
public class mcButtonPlay extends navigationButtonHandler {
public function mcButtonPlay(Parent:MovieClip,Text:String,GameImage:BitmapData) {
super(Text);
if (GameImage != null) {
var ImageBitMap:Bitmap = new Bitmap(GameImage);
this.addChild(ImageBitMap); // * * * This doesn’t show
Parent.addChild(ImageBitMap); // Works just to test the image
}
}
}
public class navigationButtonHandler extends MovieClip {
public function navigationButtonHandler(Text:String) {
ChangeButtonTargetText(Text);
Parent.addChild(this);
}
}
public class navigationButtonHandler extends MovieClip {
public function navigationButtonHandler(Text:String) {
ChangeButtonTargetText(Text);
Parent.addChild(this); //<--------????
}
}
where does Parent come from in the above piece of code copied from the question? It would seem the navigationButtonHandler class never gets added to the stage because it doesn't get a Parent? So the extended class also is never added to the stage which would be why your image is never shown if you addChild it to your mcButtonPlay class.
Your extended constructor DOES pass a Parent parameter but the base class doesn't. That seems weird to me and should not compile. Or are you doing some static things behind the scenes?
And get to work on your capitalization style as mentioned in the comments. It's really a lot easier to read and find errors if you follow common conventions!
this.addChild(ImageBitMap); // * * * This doesn’t show
Parent.addChild(ImageBitMap); // Works just to test the image
With this code, ImageBitMap is being removed from 'this' and placed in 'Parent', so you will never see it in 'this'.
Remove that second line and tell me if it's still working.
Edit:
Are you adding btPlay to the stage or display hierarchy?
eg.
btPlay = new mcButtonPlay(this,"ClickMe",GameImage);
this.addChild(btPlay);
Managed to fix it by swapping the super and add child logic around:
public class mcButtonPlay extends navigationButtonHandler {
public function mcButtonPlay(Parent:MovieClip,Text:String,GameImage:BitmapData) {
if (GameImage != null) {
var ImageBitMap:Bitmap = new Bitmap(GameImage);
this.addChild(ImageBitMap); // * * * This doesn’t show
Parent.addChild(ImageBitMap); // Works just to test the image
}
super(Text);
}
}
No idea why though!

keyboard input with actionscript

I'm writing in pure actionscript in notepad with flex as a compiler. Here's the code I have
package
{
import flash.display.*;
import mx.core.*;
import flash.events.*;
import mx.collections.*;
import flash.geom.*;
import mx.controls.*;
import flash.text.*;
import mx.events.*;
import mx.styles.*;
import mx.containers.*;
public class MAIN extends Sprite
{
public var APPLICATION:Application = Application(Application.application);
public var FRAME:int = 0;
public function MAIN()
{
addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
STEP();
}
public function STEP():void
{
FRAME ++;
STEP();
}
public function keyDownHandler(event:KeyboardEvent):void
{
var keyDownText:TextField = new TextField();
keyDownText.text = "Key code: " + event.keyCode;
this.addChild(keyDownText);
}
}
}
What I want is for whatever key I happen to press to be drawn on the screen (though actually I think it would only be the ascii number it corresponds to but that doesn't matter). Right now though everything's just blank. Another thing is because I'm not using any mxml I don't know if i've established the game loop correctly so let me know if that needs to be fixed.
Try
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
instead of
addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
Since your Sprite doesn't have a visible area, it will not receive keyboard or mouse input.
Also the STEP() function will cause a stackoverflow because it's infitely recursive.
If you want a main loop that gets called periodically, try using an ENTER_FRAME handler or a Timer.
Something like this:
public function MAIN()
{
addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);
addEventListener(Event.ENTER_FRAME,STEP);
}
private function STEP(e:Event):void {
FRAME++;
}
To stop it, do this:
removeEventListener(Event.ENTER_FRAME,STEP);
Not sure why you are using ALL CAPS for some methods and variables. Although it's not a language requirement, all caps are generally reserved for constants. Method names use camelCase. And types use PascalCase (like camelCase, but the first letter is capitalized). So your class would be Main, FRAME would be fram, STEP would be step, etc. You're better off sticking to these common naming schemes, I think.
And another thing. You probably shouldn't be creating a new TextField instance everytime you want to output some text. One textfield will do it in your case, I think. So create and addChild the textfield on some kind of init method that you call when you start your class and then just use the text property of this textfield to write your messages.