Communicating with a loaded as2 swf in another as2 swf - actionscript

I have loaded an AS2 swf inside another AS2 swf using MovieClipLoader.
I have no control(cannot edit) over the child swf.
Is there a way I can communicate with the child swf from the parent swf.
The child swf is not accepting any LocalConnection Objects.
Can I call a method in the child swf some other way?
Thanks,
Sri

I made the mistake of adding code interacting with the loaded swf buttons in the onLoadComplete listener which doesn't work unless you are interacting with the loaded swf container only, dynamic text or buttons inside loaded swf can't be accessed. To control the objects inside the child (buttons, dynamic text etc) add your code in the onLoadInit listener. As an example
mclListener.onLoadInit = function(childSwf:MovieClip, status:Number):Void {
childSwf.btnInsideChild.onRelease = function()
{
childSwf._x += 10;
}
};
moved my loaded childswf by clicking the buttons inside the loaded swf

you can access any public methods/properties on the child swf after it is initialized. Listen for the onLoadInit handler, and access child members from there. LocalConnection objects aren't required if your swfs exist in the same AVM runtime instance.

You can access like child MovieClip / Custom Class Instance. When you are loading you have to define one variable and you have to use variable for accessing public methods of the Child external swf. it is treated as Child Display Object. And as per the flash UI Display list system, MovieClip can contains unlimited level nested Child Display Object.

Related

What's the way to create a collection of different custom components?

hi to all In advance Sorry for my english.
I'm explain my problem. For an OpenGL library. I have a generic Shader component (TGLCustomGLSLShader). I'd like to make a Shader Library collection. At this time i can add TGLCustomGLSLShader in my collection. But i'd like also add descendant of TGLCustomGLSLShader. for Example : I create specific shader like TGLBumpMapShader, a TGLWaterShader ect.... with differents custom properties in each and are not present in the base class. I'd like to add this new classes in my collection and view there custom properties at design-time. It is possible ?
How can make this ? Have you some links ? I tried to search with google, but i don't find any clues.
Best regards
There are two ways to implement this with full design-time and DFM support:
Have the common base class (TGLCustomGLSLShader) derive from TCollectionItem, and then create a TOwnedCollection published property in your main Library component to hold them. Users will not be able to drop shaders on the Form at design-time, but the native collection editor should be able to delete/edit the shader objects normally. You can create a custom design-time editor that allows users to create instances of your shader classes, passing the TOwnedCollection object to their constructor. You will also have to implement custom DFM streaming for the Library component so it will create instances of the appropriate shader classes when loading a DFM, otherwise it will create TGLCustomGLSLShader objects instead of derived objects.
Have the common base class derive from TComponent, thus allowing users to drop shaders on the Form and configure their properties like normal components. Then, in your Library component, create a TOwnedCollection published property, and define a custom TCollectionItem class for it that has a published TGLCustomGLSLShader property. This will allow the user to use the native collection editor to add items and then manually link them to the desired shader components as needed. While this requires more objects and more user setup, it is friendlier on the native design-time editors and DFMs, as it allows default behaviors to act normally and does not require any custom design-time editors to manage the objects.

how to access ShadowDOM of other polymer elements?

I'm learning Dart by making a simple webapp. the app ui I have in mind has two parts, one is a control panel, the other is a workspace. by clicking buttons in the control panel, user should be able to control the workspace.
both the control panel and the workspace are custom polymer elements. In the Control Panel's dart class, I can access itself by using shadowRoot.querySelector, but since the control panel needs to control the workspace, I need to access the workspace also. but I don't know how to do that. I tried querySelector for example, It gave me null. I understand it is a shadow DOM in the workspace tag, but how to access other tags' shadow DOM?
I can't find anything online, every example and document seems to only use shadowRoot to access self elements.
It is difficult to access the shadow DOM of another element, and this is by design. Instead of having your two custom elements so tightly coupled, a better approach would be to use events or signals. Your control panel element should take user input and fire appropriate events using the convenient fire() method it inherits from the PolymerElement class. Your application can catch and then relay those events to your workspace element. If that seems overly circuitous, you can use Polymer's <core-signals> element to pass events without dealing with intermediaries.
As an example, inside your control panel element, you might have a bold button.
<button on-click="{{boldClicked}}">Bold</button>
When that button is clicked, the control panel's boldClicked() method is executed in response. It might look something like this:
void boldClicked(Event event, var detail, Element target) {
fire('core-signal', detail: {'name': 'bold', 'data': null});
}
Then in your workspace element's HTML file, you might have:
<core-signals on-core-signal-bold="{{boldEventReceived}}"></core-signals>
And finally, in your workspace element's Dart class would be a method like so:
void boldEventReceived(Event event, var detail, Element sender) {
// manipulate workspace shadow DOM here
}
This is just one of several ways to accomplish this. You can look over the Dart team's <core-signals> example for more.
And of course, if you're using Polymer to its full potential, you will find that you need to do very little manual DOM manipulation. Using data binding and data-driven views is a winning strategy.
You can either use a selector that pierces though all shadow boundaries querySelector('my-tag /deep/ some-element') or querySelector('* /deep/ some-element') or as selector that just pierces through one level of shadow boundary querySelector('my-tag::shadow some-element') or alternatively
place both elements within the <template> of another Polymer element then you can connect attributes of both components with the same field on the common parent element (this is the preferred method in Polymer.
The solution of #user3216897 is fine of course especially if the elements don't share a common parent.
Instead of shadowRoot.querySelector you should be able to use $['abc'] if the element has an id attribute with the value 'abc'.

What is the different between ClassMapAutoLoader and onBootstrap?

What is the difference between ClassMapAutoLoader and onBootstrap?
Class Map Autoloader
A web application consists of many PHP classes, and each class typically resides in a separate file. This introduces the need of including the files.
As your application grows in size, it may be difficult to include
each needed file. Zend Framework 2 itself consists of hundreds of files,
and it can be very difficult to load the entire library and all its
dependencies this way. Moreover, when executing the resulting code, PHP interpreter will
take CPU time to process each included file, even if you don't create an
instance of its class.
To fix this problem, in PHP 5.1, the class autoloading feature has been introduced.
The PHP function spl_autoload_register() allows you to register
an autoloader function. For complex web sites, you even can create
several autoloader functions, which are chained in a stack.
During script execution, if PHP interpreter encounters a class name
which has not been defined yet, it calls all the registered autoloader functions
in turn, until either the autoloader function includes the class or "not found" error is
raised. This allows for "lazy" loading, when PHP interpreter processes the class
definition only at the moment of class invocation, when it is really needed.
To give you an idea of how an autoloader function looks like, below we provide a
simplified implementation of an autoloader function:
<?php
// Autoloader function.
function autoloadFunc($className) {
// Class map static array.
static $classMap = array(
'Zend\\Mvc\\Application' => '/path/to/zend/dir/Zend/Mvc/Application.php',
'Application\\Module' => '/path/to/app/dir/Application/Module.php',
//...
);
// Check if such a class name presents in the class map.
if(isset(static::$classMap[$className])) {
$fileName = static::$classMap[$className];
// Check if file exists and is readable.
if (is_readable($filename)) {
// Include the file.
require $filename;
}
}
}
// Register our autoloader function.
spl_autoload_register("autoloadFunc");
In the above example, we define the autoloadFunc() autoloader function,
which we will further refer to as the class map autoloader.
The class map autoloader uses the class map for mapping between class name and
absolute path to PHP file containing that class. The class map is just a usual PHP
array containing keys and values. To determine the file path by class name, the
class map autoloader just needs to fetch the value from the class map array.
It is obvious, that the class map autoloader works very fast. However, the disadvantage
of it is that you have to maintain the class map and update it each time you add a new
class to your program.
onBootstrap
On every HTTP request, the Zend\Mvc\Application
object is created. The application's "life" consists of several stages.
Zend Framework 2 uses the concept of event. One class can trigger an event,
and other classes may listen to events. Technically, triggering an event means just calling another class' "callback" method. The event management is implemented inside of
the Zend\Mvc\EventManager component.
Each application life stage is initiated by the application by triggering an event. Other
classes (either belonging to Zend Framework or specific to your application) may listen
to events and react accordingly.
Below, the four main events (life stages) are presented:
Bootstrap. When this event is triggered by the application, a module has a chance to
register itself as a listener of further application events in its onBootstrap()
callback method.
Route. When this event is triggered, the request's URL is analyzed using a router class (typically, with
Zend\Mvc\Router\Http\TreeRouteStack class. If an exact match between the URL and a route
is found, the request is passed to the site-specific controller class assigned to the route.
Dispatch. The controller class "dispatches" the request using the corresponding action method
and produces the data that can be displayed on the web page.
Render. On this event, the data produced by the controller's action method are passed for rendering to
Zend\View\Renderer\PhpRenderer class. The renderer class uses a
view template file for producing an HTML page.
For a beginner to better understand the above mentioned concepts, I would recommend the Zend Framework 2.0 by Example: Beginner’s Guide book or the Using Zend Framework 2 e-book. You may choose the book on your own.

How to access parent model from polymer component

I have my-app as main application component in index.html file and uses model.dart as its model which is my application model.
my-app has my-component as its content. When user interacts with my-component, I need to update values in model.dart.
<my-app>
<my-component></my-component>
</my-app>
one approach I thought is to access my-app in my-component dart file and use its model property to access model.dart.
Is this the right approach to access model of the application? Also how to get my-app from within my-component?
I would submit that having the child component have awareness of its parent is not a particularly good pattern.
But you are right, often what happens in the child component changes a value in the parent, or in a model bound to the parent. For cases like these, I have found that the child can dispatch an event, and the parent can choose to interact with that event as it sees fit.
Dispatching an event is as simple as doing the following (this is class MyComponent):
dispatchEvent(new CustomEvent('foo'));
And the parent can listen for that event like this:
<my-app>
<my-component on-foo="{{someMethodOnTheParent}}"></my-component>
</my-app>
In effect, the child simply broadcasts that something has happened, but has no control over how (or even if) the parent responds. If <my-component> is used by a different parent, that parent could choose to respond to the custom event in a different way:
<another-element>
<my-component on-foo="{{someOtherMethod}}"></my-component>
</another-element>
The callback that is triggered in parent could do pretty much anything, including modifying the model.
Hope that helps.
Dart Polymer >= 1.0.0-x
new PolymerDom(this).parentNode
See also https://www.polymer-project.org/1.0/docs/devguide/local-dom.html
Dart Polymer <= 0.16.x
#ShailenTuli is right about encapsulation should not be broken.
But also JS Polymer elements access the parent in their layout elements because it's still convenient in some scenarios.
This works now in PolymerDart too.
(this.parentNode as ShadowRoot).host

How to process elements added or removed from DOM by Dart Web UI template

In (latest) Dart Web UI, what's the best way to process an element when it's added or removed from the DOM by a template? Ideally I'd like to register a callback right in the template, but that's not a requirement.
Background: I need to register/unregister certain DOM elements from two JS libraries (one of which is a JQuery plugin). Since my template uses loops and conditionals (and data binding), elements can come and go at any time, and I can't just register them after the initial rendering.
It is possible to add callbacks to your component's class that trigger when it is either created, inserted into the DOM, or removed from the DOM.
Web UI Specification: Lifecycle Methods
class MyComponent extends WebComponent {
inserted() {
// Do stuff when inserted into DOM.
}
removed() {
// Do stuff when removed from DOM.
}
}

Resources