0
votes

I code all my project in Alloy, so no classic Titanium here. I want to load an external custom AlertDialog (located in views/popup.xml) in my index. So my need is to show an alert and destroy it (for ie.) by clicking the OK button. The Help button should do another action.

My popup.xml file :

<Alloy>
    <AlertDialog id="popup" title="Error popup"
        message="There is an error" cancel="1">
        <ButtonNames>
            <ButtonName>OK</ButtonName>
            <ButtonName>Help</ButtonName>
        </ButtonNames>
    </AlertDialog>
</Alloy>

My index.js file :

function openPopup(e) {
    var page = Alloy.createController('views/popup').getView();
    page.show();
};
openPopup();

But this gives me an error :

  • [DEBUG] [iphone, 8.1, 192.168.0.1] Native module:alloy/controllers/views/popup
  • [ERROR] [iphone, 8.1, 192.168.0.1] Couldn't find module: alloy/controllers/views/popup
  • [ERROR] [iphone, 8.1, 192.168.0.1] TypeError: 'undefined' is not a constructor (evaluating 'new (__p.require("alloy/controllers/" + name))(args)')

I have no popup.js and I didn't require any file in index.js too. So my questions are : How to load a controller dynamically? How to remove (or destroy) it with an addEventListener on "click" action? Thank you.

1
only use Alloy.createController('popup').getView();, not views/popupturtle
It works ! Thank you !Xavier C.

1 Answers

0
votes

Agree with turtle. When you create a controller it implicitly knows you are referring to a view in the the app/views directory.

And you should improve your code slightly by not creating a local variable (for garbage collection purposes). So instead of:

var page = Alloy.createController('views/popup').getView();
page.show();

You should just do:

Alloy.createController('views/popup').getView().open();

You can find more info about this in a splendid article by Fokke Zandbergen.

/John