ManagedEvent with companion Event metadata - actionscript-3

I'm trying to declare a customized ManagedEvent with ActionScript as follows:
[Bindable]
[ManagedEvents(names="message")]
public class ClassName extends EventDispatcher
{
.........
}
The problem came when sonar impposed to have a companion Event with that ManagedEvents.
I added the following Event metadata :
[Bindable]
[Event(name="message",type="package.ClassEvent")]
[ManagedEvents(names="message")]
public class ClassName extends EventDispatcher
{
....
}
But the problem still unsolved with sonar.
This is a link for sonar SonarAnalyzer for flex :
http://dist.sonarsource.com/reports/coverage/rules/flex_rules_coverage.html
where there is this rule : https://sonarqube.com/coding_rules#rule_key=flex%3AS1464
Each ManagedEvents metadata tag should have a companion Event metadata tag
I really need to fix this issue, have you an idea?

The problem was solved by removing the names attribut in ManagedEvents:
[Bindable]
[Event(name="message",type="package.ClassEvent")]
[ManagedEvents("message")]
public class ClassName extends EventDispatcher
{
....
}

Related

Yii2 generic behaviour in all models

How Can I add a generic behaviour function that would work for all models. I have added this code in all models. Now I don't want to repeat the same function in all models.
You can create a CustomModel class that extends ActiveRecord. In CustomModel, add the method that you want:
class CustomModel extends \yii\db\ActiveRecord {
public function custom_function() {
//Function details
}
}
Then make your models extend CustomModel
class Book extends CustomModel {
}
That way you can use this method in all your models that extends CustomModel without having to implement this method in each of them.

Sonar blocker for managed "ame" + flex project

I'm trying to fix bocker given by sonar for a Flex+ actionScript3 web application.
I was faced to this unresolvable blocker:
The managed event "ame" is either misspelled or is missing a companion
Event metadata tag
My code is as follows:
[Bindable]
[ManagedEvents(names="message")]
public class ClassName extends EventDispatcher
{
.........
}
I tried to fix this issue as follows:
[Bindable]
[Event(name="message",type="package.ClassEvent")]
[ManagedEvents(names="message")]
public class ClassName extends EventDispatcher
{
....
}
Where in package.ClassEvent is the declared event "message"
[Command(selector="message")]
public function message(evt:NameEvent):AsyncToken
{
.....
}
PS: Sonar suggest as solution :
The "ManagedEvents" metadata tag allows you to flag an event as being
managed. By definition this "ManageEvents" metadata tag should be used
in pair with an "Event" metadata tag.
Noncompliant Code Example
[Event(name="message", type="my.package.MyEvemt")]
[ManagedEvents("mes")] //This "mes" event is not defined with
the "Event" metadata tag public class MyClass {...}
Compliant Solution
[Event(name="message", type="my.package.MyEvemt")]
[ManagedEvents("message")] public class MyClass {...}
This is a bug in Sonar.
This ticket https://jira.sonarsource.com/browse/SONARFLEX-88 should fix your problem. While it's not fixed you can mark issue as false positive.

AS3: Compiler bug with inner classes and interfaces?

For some irrelevant reasons I need a class:
that inherits (directly or not) from MovieClip.
that implements a particular interface (let's assume here that this interface is empty since it does not change anything to the issue).
and whose .as file declares internal classes.
The following code sums this up:
package {
import flash.display.MovieClip;
public class MyClass extends MovieClip implements EmptyInterface { }
}
class MyInnerClass { }
The problem with that code above is that it will not always compile. As soon as I use MyClass as Linkage for one of my library's item the compiler complains about MyClass not being a subclass of MovieClip. On the other hand, everything works great if I instantiate it manually and add it to the stage.
It looks like the interface and the inner class are somehow mutually exclusive in that very particular case. Indeed, if I remove the inner class I do not have that error anymore:
package {
import flash.display.MovieClip;
public class MyClass extends MovieClip implements EmptyInterface { }
}
Same thing when I remove the implemented interface but keep the inner class:
package {
import flash.display.MovieClip;
public class MyClass extends MovieClip { }
}
class MyInnerClass { }
Note that I've only tested this in Flash CS5.
I say it is a bug of compiler.
I have tested and found that private class must extend any class that is not Object. Instead of extending class it can also implement any interface.
This works same even if I put classes into deeper package.
I have tested this with Flash CS6.
If I'm reading you right, you want a public class to extend an internal class? - There is nothing that prevents you from doing this, so long as you declare your internal class as it's own packaged file.
According to the documentation:
[dynamic] [public | internal] [final] class className [ extends superClass ] [ implements interfaceName[, interfaceName... ] ] {
// class definition here
}
If it's the interface that is giving you grief, have you declared it in a separate file as well - that you would import? As eluded to in the comments, the namespace scoping is important so that the compiler understands what the escalating priority is.
Eg:
package my.example {
public interface EmptyInterface
{
}
}
So that:
package {
import flash.display.MovieClip;
import my.example.EmptyInterface;
public class MyClass extends MovieClip implements EmptyInterface { }
}
If this doesn't fix it I have another idea but try this first.
Click file
Click publish setting
Click on settings button
Uncheck Automatically declare stage instances
Click OK

AS3 Base class is final error when I didn't set it that way

I'm getting the "Base class is final" error on a project that uses the AIR for iOS player. Problem is I didn't set the base class to be final. Also this only happens when I use AIR as the player.
Main - document class
package {
import flash.display.*;
import parentfolder.*;
import parentfolder.childfolder.*;
public class Main extends MovieClip {
public function Main () {
addChild (new SplashScreen ());
}
}
}
Screen - inside parentfolder which is in the same folder as the document class
package parentfolder {
import flash.display.*;
public class Screen extends Sprite {
public function Screen () {
}
}
}
SplashScreen - inside parentfolder
package parentfolder.childfolder {
import flash.display.*;
import parentfolder.*;
public class SplashScreen extends Screen {
}
}
So...there's no "final" anywhere in the code and the problem is isolated in the AIR player.
There is a class in AIR called Screen, which is declared as final. You've used the .*notation on your imports, therefore flash.display.Screen is assumed as the base class for SplashScreen, instead of your custom parentfolder.Screen.
Since this class exists only in AIR, the problem does not occur in other players.
You should always use fully qualified imports (one for each class) to avoid naming conflicts like this.
Your issue is with Screen.
You are trying to extend from it in this line
public class SplashScreen extends Screen
Screen is declared as public final class Screen.
So you cannot inherit from a class that is final.
Quoting the Adobe Docs,
Specifies that a method cannot be overridden or that a class cannot be
extended. An attempt to override a method, or extend a class, marked
as final results in an error.

Adobe Air - Dispatch event with parameter

How to pass the addChild(event.target.loader) through a dispatch event from the class to the main timeline?
package scraps
{
...
public class FileScrap extends Scrap
{
...
private function loadImage(event:Event):void{
addChild(event.target.loader);
}
Thanks
You can create a custom event class that extends flash.events.Event and have the DisplayObject that gets loaded sent as a property of that event. In that case FileScrap will need to inherit from EventDispatcher or implement IEventDispatcher.
You could also just dispatch a generic event called IMAGE_LOADED or something like that, and have the main class poll a public method in scraps to get the image whenever it receives the event.