Is it possible to access a class outside package from other package? - actionscript-3

I have a class like this
package test{
class Test{}
}
class TestInnerClass{}
I can access the TestInnerClass from Test class but I need to access the TestInnerClass(as class, not its instance) from other class as well. And I don't really want to make TestInnerClass an independent class as all it contains are a few variables.
Is there any way to access the class from outside Test class?
[edit]
More specifically, I need the access for the following code to work.
registerClassAlias("TestInnerClass",TestInnerClass);

If you have a class that would not otherwise be accessed except internally by a public class you may define it as internal.
Internal classes are visible to references inside the current package.
In your example, TestInnerClass is only visible to Test.
Otherwise, to access the class or register class alias it must be defined public in its own .as file.
Packages help to order and classify code in hierarchy. Often, I'll keep Value Object or Data Transfer Objects within their own package, such as:
com.jasonsturges.model.vo
This helps to group smaller model classes together.

If you wanted to make a class visible outside of it's containing package your class would be defined as so:
// SampleCode.as file
package samples{
public class SampleCode {}
}
// CodeFormatter.as file
package samples{
class CodeFormatter {}
}
The SampleCode class is visible whilst the CodeFormatter class is not.
Hope I've answered your question

Related

How to check Custom Element is registered?

Some method creates new instance of my custom element (created with polymer) and attaches it on page. But I want to check is Element registered before add it and print error to console in bad case. I mean what if I forgot import component html declaration:
<!--I forgot write it in my HTML file -->
<!--<link rel="import" href="packages/visualytik/vis_starter.html">-->
So, in case when I forgot import I want to print error in console.
I know one tricky method:
import 'my_custom_component.dart';
Element component = new Element.tag('my-custom-component');
bool registered = component is MyCustomComponent;
But it's hard method because we should create component first and have to import MyCustomComponent.dart in dart file. Can I check it in other way? Something like:
document.isRegistered('my-custom-component');
Update3
You can also use the new #HtmlImport annotation. If you import the class, then you can be sure you also have imported the HTML of the element. See also https://stackoverflow.com/a/29710355/217408
Update2
See Hunting down unregistered elements
Update
Use a custom constructor in your elements class and do the registration there but only if it wasn't done already.
class MyCustomComponent extends ... {
bool _isRegistered;
bool get isRegistered => _isRegistered;
factory MyCustomComponent() {
if(!isRegistered) {
registerElement();
_isRegistered = true;
}
return new Element.tag('my-custom-element');
}
}
and then create new instances like
new MyCustomElement();
and you can always be sure the element is registered only once (but you always need to use this constructor of course).
Original
If you register your elements by calling document.RegisterElement() yourself instead of relying on Polymer for example, you need to hold a reference to the constructor reference document.RegisterElement() returns, otherwise you won't be able to create an instance of the element.
Therefore you just need to check if you already have a reference to the constructor. See also https://developer.mozilla.org/en-US/docs/Web/API/Document/registerElement

Problems with Yii2 creation Rules

I have a Yii2 with Yii2 admin, user andAdminLTE installed. My problem is I don't know how to create rules, actually I don't know how to define the Class Name. Where "Classes" should be defined? How can I see which Classes do I have or add Classes?
Thanks a lot,
The class that you'll enter should be the child class of yii\rbac\Rule. So, in order to make a rule you need to provide the namespace of this child class. Suppose, if the name of the child class is TestRule and the namespace of this class is app\test. Then you must write the class name as app\test\TestRule.
And your TestRule class must look like
namespace app\test;
class TestRule extends yii\rbac\Rule{
...
}

Change text from other class with AS3?

I have some action script in the first layer and it imports a CustomSocket class from an external .as file. When I receive a command on the socket I want to edit the GUI objects. For example, when I get the command TIME 23 from the server I want to change the dynamic text box timerBox to the value 23. I have a method called processCommand(cmd:String) in the CustomSocket class, but I don't know how to change the text. Usually you can just do timerBox.text = "23"; but this doesn't work in an external class?
If 'CustomSocket' is not your document class, then you need to specify some reference for your timeline in your class.
For general example,
While importing a class,
import CustomSocket;
csObj:CustomSocket = new CustomSocket(this);
then, inside class, in constructor
public function LibraryS(_ref:Object):void
{
timelineRef = _ref;
}
then in your class you can say,
timelineRef.timeBox.text = "23";

In AS3, how do I run code when a when the movie starts?

I'm making a level editor for my game, and would like to be able to access a list of all the classes included in my game. I have a static function in my Main class:
public static function register(c:Class, category:String):void {
if (classRegister[category] == null) {
classRegister[category] = new Array();
}
classRegister[category].push(c);
}
Then, in each class I want registered, I put a static initializer:
{
Main.register(prototype.constructor, "motion");
}
However, the static initializers only get called when the class first gets used. Is there a way for a class to force itself to be used right when the game starts? I'm aware that I could explicitly list all the registered classes in the Main file, but that's suboptimal in that the Main file would have to be edited whenever a new class is added that wants registration.
Thanks,
Varga
List all the class definition in the ApplicationDomain, and filter them based on a naming convention or a type (an interface?).
To achieve this, you can use ApplicationDomain.getQualifiedDefinitionNames() (docs), but only if you target FlashPlayer 11.3+.
As a side note, you MUST reference this class somewhere, as a class field so the compiler knows it must include this class in the SWF. You can also put the classes you want to reference inside a SWC library and use -compiler.include-libraries as compiler setting (in that case I wonder if your static initializers gets called?).

Document class silently fails

I have this weird issue while compiling my .fla file : it won't use the Document class. Here is the document class. (note that the parent class EditorPlugin extends Sprite).
package com.myproject.plugins.editor {
import flash.display.MovieClip;
import com.myproject.editor.EditorPlugin;
import com.myproject.editor.tools.EpisodeEditorTool;
import com.myproject.editor.tools.NewTabTool;
import com.myproject.editor.tools.ToolManager;
public class EpisodeEditorPlugin extends EditorPlugin{
public function EpisodeEditorPlugin(){
trace("creating", this);
AddAuth(ToolManager.EDIT_EPISODE_AUTH, ToolManager.EDIT_EPISODE_AUTH, EpisodeEditorTool, ToolManager.EDIT_EPISODE_LABEL);
}
}
}
The weird part is that in the line below, if I use NewTabTool instead of EpisodeEditorTool, the code works just fine, but with EpisodeEditorTool, the Class is not instanciated. There are no warnings or compiling errors, but i don't get the trace. I loaded the resulting .swf, it is not of type EpisodeEditorPlugin, but rather a simple MovieClip (via getQualifiedClassName() and is EpisodeEditorPlugin).
The EpisodeEditorTool and NewTabTool are quite similar even though of different use, but very huge, here are their declarations :
public class EpisodeEditorTool extends JPanel implements ITool{
and
public class NewTabTool extends JPanel implements ITool{
I should add that both class contain no error (at least according to Flash) and have been compiled in other .flas before. the only problem I can see is that EpisodeEditorTool is even more huge(r?) than other ITools.
Does anyone have any idea of how a document class could fail to be applied? And fail silently at that?
Thanks!
The only thing I can really think of is that you're not specifying the name of the Document class correctly inside the Flash IDE. Inside the Properties panel there's a box where you enter the name of your Document class, which you must presumably have used if the Document class works when you rename the class to NewTabTool. I guess you put NewTabTool into that box, then changed the actual class' name, and forgot to change the reference in the Properties panel. I've forgotten that little bit when changing the name of my Document class before, I hope your solution is as simple as that!
debu