The Stack Overflow podcast is back! Listen to an interview with our new CEO.
5 added 2378 characters in body
source | link

Also, I tried ObjectProxy and that only abstracts out the first method. It fails because the proxy only passes in the name of the method but nothing after it. With ExternalInterface I have to pass the full block of code rather and then return a value.

The object proxy call method:

function callProperty(name:String, ...args):* {
    if (isDesktop) {
        return myObject[name].apply(this, args);
    }
    else {
        return ExternalInterface.call("function (name, args) { return myObject[name].apply(this, args); }", name, args);
    }
}

so this works:

myProxy.doMethod(value1, value2);

But fails with this:

myProxy.getElement(id).getTextRange(start, end);

That's because I can't return a reference from another vm besides other limitations.


Update:
I found a real world example for the DragManager class that I'm going to model it after. In the browser the class uses mx.managers.DragManagerImpl and on the desktop it uses NativeDragManagerImpl that interacts with the operating system:

Also, I tried ObjectProxy and that only abstracts out the first method. It fails because the proxy only passes in the name of the method but nothing after it. With ExternalInterface I have to pass the full block of code rather and then return a value.

The object proxy call method:

function callProperty(name:String, ...args):* {
    if (isDesktop) {
        return myObject[name].apply(this, args);
    }
    else {
        return ExternalInterface.call("function (name, args) { return myObject[name].apply(this, args); }", name, args);
    }
}

so this works:

myProxy.doMethod(value1, value2);

But fails with this:

myProxy.getElement(id).getTextRange(start, end);

That's because I can't return a reference from another vm besides other limitations.


Update:
I found a real world example for the DragManager class that I'm going to model it after. In the browser the class uses mx.managers.DragManagerImpl and on the desktop it uses NativeDragManagerImpl that interacts with the operating system:

4 added 258 characters in body
source | link

He preached that plugins were a problem on mobile devices (and then it spread that plugins were a problem on desktop environments) while secretly allowing his own plugins like Quicktime in Safari and installing app launcher in other browsers. If you are on Mac look at the plugins in your browser. There's one from Apple right there. And whatAs further proof, the few the things he did get correctsaid about his statement on plugins that were true, he didn't allow those plugins the opportunity to fix them. Plugin authors added power management, increased security and other features and fixed the issues he mentioned. It was never about the issues it was about control. If you need a break.

He preached that plugins were a problem on mobile devices (and then it spread that plugins were a problem on desktop environments) while secretly allowing his own plugins like Quicktime in Safari and installing app launcher in other browsers. If you are on Mac look at the plugins in your browser. There's one from Apple right there. And what he did get correct about his statement on plugins he didn't allow those plugins the opportunity to fix them.

He preached that plugins were a problem on mobile devices (and then it spread that plugins were a problem on desktop environments) while secretly allowing his own plugins like Quicktime in Safari and installing app launcher in other browsers. If you are on Mac look at the plugins in your browser. There's one from Apple right there. As further proof, the few the things he said about plugins that were true, he didn't allow those plugins the opportunity to fix them. Plugin authors added power management, increased security and other features and fixed the issues he mentioned. It was never about the issues it was about control. If you need a break.

3 added some example code
source | link
 

Sorry not sorry, rant over.


After sleeping on @bikemans868's suggestion it reminded me of a design pattern I saw used before (don't remember the name).

It goes like this, I'm a framework author and I want to create a button but this button has to work in two different environments. Each environment has a different syntax to get it to work. I don't want the developer using my button to worry about creating different buttons for each environment.

So I create MyButton class and it has all the methods and API that I want. I then create two additional classes for environment A and environment B. Then at runtime or compile time I determine what environment I'm in and then set the implementation in the Button class.

In the following code I set the implementation in the constructor. So the class looks like this:

public class Button implements IButton {

   public function Button() {

       // the registration could take place somewhere else
       if (desktop) {
           ImplementationClass = getClass("com.example.DesktopButton");
       }
       else if (browser) {
           ImplementationClass = getClass("com.example.BrowserButton");
       }

       implementation = new ImplementationClass();
   }

   public var ImplementationClass:Object;

   public var implementation:IButton;

   public function setLabel(value:String):void {
       implementation.setLabel(value);
   }
}

public class DesktopButton implements IButton {

   public function setLabel(value:String):void {
       button.label = value;
   }
}

public class BrowserButton implements IButton {

   public function setLabel(value:String):void {
       ExternalInterface.call("function(value) { document...button.label = value; }", value);
   }
}

Sorry not sorry, rant over.

 

Sorry not sorry, rant over.


After sleeping on @bikemans868's suggestion it reminded me of a design pattern I saw used before (don't remember the name).

It goes like this, I'm a framework author and I want to create a button but this button has to work in two different environments. Each environment has a different syntax to get it to work. I don't want the developer using my button to worry about creating different buttons for each environment.

So I create MyButton class and it has all the methods and API that I want. I then create two additional classes for environment A and environment B. Then at runtime or compile time I determine what environment I'm in and then set the implementation in the Button class.

In the following code I set the implementation in the constructor. So the class looks like this:

public class Button implements IButton {

   public function Button() {

       // the registration could take place somewhere else
       if (desktop) {
           ImplementationClass = getClass("com.example.DesktopButton");
       }
       else if (browser) {
           ImplementationClass = getClass("com.example.BrowserButton");
       }

       implementation = new ImplementationClass();
   }

   public var ImplementationClass:Object;

   public var implementation:IButton;

   public function setLabel(value:String):void {
       implementation.setLabel(value);
   }
}

public class DesktopButton implements IButton {

   public function setLabel(value:String):void {
       button.label = value;
   }
}

public class BrowserButton implements IButton {

   public function setLabel(value:String):void {
       ExternalInterface.call("function(value) { document...button.label = value; }", value);
   }
}
2 added 548 characters in body
source | link
1
source | link