0

How can I do to make a communication between flex (swf) application and angular2 application?

I know how to do with js and flex but I don't see how flex can find a angular2 method.

With JS : just need method like :

function flexUp() {
    console.log('Flex Up');
}

and in flex, call the JS method :

ExternalInterface.call("flexUp");

I'm newbie in the JS/Angular2 world.

BokC
  • 333
  • 5
  • 19

2 Answers2

2

You can fire events in flex and listen to them in Angular Angular 2 - communication of typescript functions with external js libraries

or make methods from Angular components, directives, or services globally known like explained in Angular2 - how to call component function from outside the app

Community
  • 1
  • 1
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

The good code :

In flex :

ExternalInterface.call("window.angularFlexComponent.initFlex");

In Angular2 :

  • In flex.d.ts :
interface Window {
    angularFlexComponent: any;
}
  • In flex.components.ts :
import {Component, NgZone, OnDestroy} from '@angular/core';
@Component({
    selector: 'flex',
    templateUrl: 'app/components/flex/flex.html'
})
export class FlexComponent implements OnDestroy {
    constructor(private _ngZone: NgZone) {
        window.angularFlexComponent = { initFlex: this.initFlex.bind(this), zone: _ngZone };
    }
    initFlex(): void {
        console.log('Artemis Flex Up');
    }
    ngOnDestroy() {
        window.angularFlexComponent = null;
    }
}
BokC
  • 333
  • 5
  • 19