Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
New Developer
Posts: 27
Registered: ‎01-29-2011
My Device: Not Specified

button click event problem please help

Sadly i've spent the last hour or so trying to figure out how to link a button to another page on FB Burrito and i stil haven't figured out how to do it Smiley Sad

 

I was hoping that somebody could tell me what I need to add to my button script to link it to another MXML components page.

 

The code which i have at the moment is:

 

<s:Button id="core1" x="10" y="20" width="1004" height="85" label="Core 1"/>

The page I want to link this button is titled Core 1

 

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: button click event problem please help

You need to add an event dispatcher.  For MXML that is "click".

 

<s:Button id="core1" click="ChangeScreen(event)" />

 

Then in the AS secript section, add a function like:

 

private function ChangeScreen( event : Event ) : void

{

  // add screen change logic here.

}

There are several threads about managing different pages or screens.  Check those out to see if that helps.

New Developer
Posts: 27
Registered: ‎01-29-2011
My Device: Not Specified

Re: button click event problem please help

Sorry i've tried entering these into the script and it comes up with errors when debugging. Can you please show me where to enter it in my script. My script is:

 

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" title="A-level Maths Formulaes">
 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 </fx:Declarations>
 <s:Button id="core1" x="10" y="20" width="1004" height="85" label="Core 1"/> 
 <s:Button id="core2" x="10" y="140" width="1004" height="85" label="Core 2"/>
 <s:Button id="core3" x="10" y="260" width="1004" height="85" label="Core 3"/>
 <s:Button id="core4" x="10" y="380" width="1004" height="85" label="Core 4"/>

</s:View>

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: button click event problem please help

Try this:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
  xmlns:s="library://ns.adobe.com/flex/spark" title="A-level Maths Formulaes">
 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 </fx:Declarations>
 <fx:Script><![CDATA[
    private function ChangeCore1( event : Event ) : void
    {
      // do something
    }
    private function ChangeCore2( event : Event ) : void
    {
      // do something
    }
    private function ChangeCore3( event : Event ) : void
    {
      // do something
    }
    private function ChangeCore4( event : Event ) : void
    {
      // do something
    }

 ]]></fx:Script>

 <s:Button id="core1" x="10" y="20" width="1004" height="85"  label="Core 1" click="ChangeCore1(event)"/> 
 <s:Button id="core2" x="10" y="140" width="1004" height="85" label="Core 2" click="ChangeCore2(event)"/>
 <s:Button id="core3" x="10" y="260" width="1004" height="85" label="Core 3" click="ChangeCore3(event)"/>
 <s:Button id="core4" x="10" y="380" width="1004" height="85" label="Core 4" click="ChangeCore4(event)"/>

</s:View>

 

New Developer
Posts: 27
Registered: ‎01-29-2011
My Device: Not Specified

Re: button click event problem please help

I've copied and pasted thescript and theirs no problem with debugging with simulator but when I click the button it doesn't change to the other page do you know what i need to do?

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: button click event problem please help

You need to add the logic to change the pages.  I do not know how you have that organized.  There have been several threads on managing pages/views in the app.  Basically it comes down to in the main application is to addChild and removeChild on pages based on what state you are in.  Keeping a reference to the "current" page will allow you to remove it before a new page is added.  All of the pages have been allocated in the main app/view and you are basically doing a "shell game" on the pages.  If you want to transition from one page to another, look at Tweener class in the QNX library.  There has also been many threads on this topic as well.

New Developer
Posts: 27
Registered: ‎01-29-2011
My Device: Not Specified

Re: button click event problem please help

I'm sorry i really can't do it Smiley Sad I know it's actionscript 3 n i've got a couple of books now just 4 AS3. What would add child and remove child be under do you know?

If somebody could edit my sxript so it'ld work that'ld be even better Smiley Happy

I have looked at different parts of the forum specially for navigation but i don't see how i can use that for my app Smiley Sad
Developer
Posts: 1,156
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

Re: button click event problem please help

See flash.display.DisplayObjectContainer for addChild() and removeChild() ... in general, methods for which you don't know the inheritance chain can be searched for in the search box at this link:

 

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/

 

although they might not always turn up at the very top of the search results.

 

Between that and code assist in Flash Builder you can often quickly find answers.

New Developer
Posts: 27
Registered: ‎01-29-2011
My Device: Not Specified

Re: button click event problem please help

Thanks mate i'll check it out Smiley Happy how come it's so difficult 2 change page lol.
Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: button click event problem please help

You can look at the PageViewStack class mentioned here:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/Community-Library-Released-for-cl...

 

In the library and that might help you do the page management.