• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Access function from a loaded external SWF

Community Beginner ,
Apr 14, 2014 Apr 14, 2014

Copy link to clipboard

Copied

So I have 2 swfs, one is mainly used to loading the other.

The problem I have is that I'd like to use a "onClickPause" function from the embeded swf after pressing a button.

Unfortunately I'm getting this error:

ReferenceError: Error #1069: Property onClickButtonPause not found on dk.game.main.Main and there is no default value.

Which is understandable since the function is located in: dk.game.view.AppView

Here's the code:

var loader: Loader = new Loader();

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);

loader.load(new URLRequest('myApp.swf'));

function onLoadComplete(e: Event): void {

    var loaderInfo: LoaderInfo = e.target as LoaderInfo;

    addChild(e.target.content);

    var swf: Object = loaderInfo.content;

    button_2.addEventListener(MouseEvent.CLICK, fl_Click);

    function fl_Click(event: MouseEvent): void {

        swf.onClickPause();

    }

}

Now how do I go about it from here?

TOPICS
ActionScript

Views

337

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 14, 2014 Apr 14, 2014

Copy link to clipboard

Copied

There appears to be a difference in wording between the error and the code you show.  See if that's where the problem lies.

You might also want to change from declaring swf as an Object and declare it as a MovieClip.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Apr 14, 2014 Apr 14, 2014

Copy link to clipboard

Copied

LATEST

Your best bet is to make the swf you are loading implement an Interface. The reason I recommend doing this is you can then cast your loaderInfo.content to that Interface and be sure the method is available. The reason I did not suggest just casting to the Document Class itself is if you do, the entire Document Class definition will get compiled into the loading swf, which presumably is part of what you're trying to avoid by loading it separately.

The code would then look something like this:

function onLoadComplete(e: Event): void {

    var loaderInfo: LoaderInfo = e.target as LoaderInfo;

    addChild(e.target.content);

    var swf:IYourInterface = loaderInfo.content as IYourInteface;

    if (swf) {

         button_2.addEventListener(MouseEvent.CLICK, fl_Click);

         function fl_Click(event: MouseEvent): void {

             swf.onClickPause();

         }

     } else {

          trace('loaded MC does not implement IYourInterface');

     }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines