Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: ExternalInterface  (Read 11281 times)
newtriks
Courseware Beta
Full Member
***
Posts: 23


 - newtriks
View Profile WWW Email
« on: October 14, 2007, 06:43:04 »

Hi,

Having trouble with ExternalInterface.addCallback(); in my Proxy, i.e. retrieving the data, the call back method doesn't seem to run in the proxy and hints?

cheers,

Simon
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: October 14, 2007, 07:51:27 »

Can you post a snippit?

-=Cliff>
Logged
newtriks
Courseware Beta
Full Member
***
Posts: 23


 - newtriks
View Profile WWW Email
« Reply #2 on: October 14, 2007, 08:09:59 »

:
package com.newtriks.model
 {
import org.puremvc.interfaces.IProxy;
import org.puremvc.patterns.proxy.Proxy;
import org.puremvc.interfaces.INotification;

import flash.net.*;
import flash.events.*;
             import flash.external.*;

import com.newtriks.ApplicationFacade;
import com.newtriks.model.vo.ClipVO;

public class PlaylistProxy extends Proxy implements IProxy
{
public static const NAME:String = 'PlaylistProxy';

public function PlaylistProxy()
{
super( NAME, new String );

ExternalInterface.addCallback("getData", gotData);
}

private function gotData( returnValue:String ):void
{
data = returnValue;
  }

public function get theList():String
{
return data as String ;
}

}
 }

I am applying the puremvc framework to a Flash CS3 project for a change and there are definate obstacles after lots of Flex usage. 

One other area you I am sure can help is with this issue:  interacting with movieclips on the stage.  I have a StageMediator but am having trouble referencing items already on the stage?

:
stage.addEventListener( MouseEvent.CLICK, onStageClick );

works fine!

:
stage.myButton.addEventListener( MouseEvent.CLICK, onButtonClick );
? access of undefined property ?

P.S. I have been hammering away non stop for 3 days now day and night so simple things have got stupid???
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: October 14, 2007, 10:06:52 »

Simon,

Though you can be sure to test on a browser supporting ExternalInterface, you can never be sure the user will. So a good first step in this method would be to insure that ExternalInterface.available == true, otherwise we know any further attempts to communicate with it will be futile.

Next, how is the getData/gotData supposed to work? What does the HTML in the browser look like?
 
I'm guessing something like:

:
<form>
    <input type="button" onclick="passDataToFlash()" value="Pass data to Flash" />
</form>

<script>
function passDataToFlash() {
    thisMovie("myFlashMovie").getData('test string for flash to eat');
}

function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName]
    }
    else {
        return document[movieName]
    }
}
</script>

With something so potentially easy to get wrong as ExternalInterface communications, I'd do some 'hello world' work with a simple class first, without PureMVC even in the picture. Be sure you are able to easily pass data back and forth and that your communications with the Javascript world are all sound first. Othewise you can really end up chasing your tail.

For instance, I'm working on a FlashLite game with a soon to be released AS2 port of PureMVC. It's all working great right now, but I really had to get my head around how things work in a phone first. Lots of simple tests to make sure I could  listen to the soft keys, load in new levels be without blowing memory, etc. All those things needed to be worked out on their own terms before I could think about how to marry them to a PureMVC app. But now that they are worked out it's smooth sailing. I expect the same will be true with your ExternalInterface woes.

Also, the Stage is a weird beast. That button is not a child of the Stage, but of a movie clip on the stage, probably _root. The stage object has a root property. Most likely stage.root.myButton is what you're after.

-=Cliff>
Logged
newtriks
Courseware Beta
Full Member
***
Posts: 23


 - newtriks
View Profile WWW Email
« Reply #4 on: October 14, 2007, 01:26:42 »

As always mate thanks very much.  I much prefer working in Flex now I have decided, I know it equally has its problems but its surprising how much I have warmed to it over time and also how well I found your framework assisted my application development. 

Regarding the testing, I had tested it and had used (but took out for a small snippet of the code here) ExternalInterface.available == true.  Your advise is good man thanks :)
Logged
Pages: [1]
Print