question

newuser-9b76e954-90cc-4ac5-9574-e3217296cd3b avatar image

Can't use onPageChange event on APL Pager

Hi, I tried the onPageChange on a pager object and it never fires. couldn't find any examples on the web.



{

"type": "Pager",

"width": "100vw",

"height": "100vh",

"navigation": "wrap",

"data": "${payload.project.items}",

"onPageChange": {

"type": "SendEvent",

"arguments": [

"slideChangeEv"

]

},

"item":[

{

"type": "projectSlide",

"title": "${payload.project.projectName} / ${data.title}",

"indexOf": "${index+1}/${length}",

"imgUrl": "${data.imgUrl}"

}

]

}

alexaechoapl
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Paul Dunn avatar image
Paul Dunn answered

The onPageChange is mentioned in several places within the APL documention, but it seems to be described incorrectly in several places:

https://developer.amazon.com/docs/alexa-presentation-language/apl-standard-commands.html

I was able go get a notification of the page change event by adding the following to my APL template:

{

"type": "Pager",

"id": "idPager",

"onPageChanged": [{

"type": "SendEvent",

"arguments": [

"${event.source.value}"

]

}],

"item": {

...

}

}



10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Pavel avatar image
Pavel answered

It still doesn't work for me. The onPageChanged never trigger Alexa.Presentation.APL.UserEvent

module.exports = (delay) => {
    return {
        "type": "APL",
        "version": "1.6",
        "import": [
            {
                "name": "alexa-layouts",
                "version": "1.2.0"
            }
        ],
        "mainTemplate": {
            "parameters": [
                "imagePagerDataSource"
            ],
            "items": [
                {
                    "type": "Pager",
                    "id": "imagePagerId",
                    "pageDirection": "horizontal",
                    "navigation": "none",
                    "height": "100%",
                    "width": "100%",
                    "onMount": [
                        {
                            "type": "AutoPage",
                            "componentId": "imagePagerId",
                            "duration": delay,
                            "delay": delay
                        }
                    ],
                    "onPageChanged": [
                        {
                            "type": "SendEvent",
                            "arguments": [
                                "onPageChanged",
                                "${event.page}"
                            ]
                        }
                    ],
                    "items": "${imagePagerDataSource.items}"
                }
            ]
        }
    };
};
1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @Pavel,

the onPageChanged handler runs in fast mode, but the SendEvent command does not, so it is ignored. you can work around this problem by using the sequencer property.


fast mode:

https://developer.amazon.com/en-US/docs/alexa/alexa-presentation-language/apl-commands.html#fast-mode-evaluation

sequencer property:

https://developer.amazon.com/en-US/docs/alexa/alexa-presentation-language/apl-standard-commands.html#sequencer


the following should work:

"onPageChanged": [
  {
      "type": "SendEvent",
      "sequencer": "myCustomSequencerName",
      "arguments": [
          "onPageChanged",
          "${event.page}"
      ]
  }
],

Regards,

Alex

0 Likes 0 ·