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
richardyiu
Posts: 17
Registered: ‎01-14-2011
My Device: Not Specified
Accepted Solution

How to create icon button / browse files

Hi everyone,  I have 2 questions that I want to ask:

 

1.  How to create an icon button using action script?

 

I add this part of code at the top of my .as file right below the package keyword:

[Bindable]
[Embed(source="/images/pause.png")]
private var pauseIcon:Class;

 

then in the main function I added this code:
var pauseButton:Button = new Button();
pauseButton.setStyle("icon",pauseIcon);

 

The compiler has problem with the "private var pauseIcon:Class;" line and the new button declaration line.  Am I declaring the right type of button?

 

2.  How to browse files in the simulator? I try to use browseForOpen but it doesn't work.  It only shows a blank dialog box saying no files match my criteria.

 

My code for browsing files:

var docFilter:FileFilter = new FileFilter("Files", "*.*");

var myFile = File.applicationStorageDirectory;

myFile.browseForOpen("Open",[docFilter]);

 

thanks

Please use plain text.
Developer
Levion
Posts: 137
Registered: ‎12-22-2010
My Device: Curve 8520
My Carrier: Software Developer

Re: How to create icon button / browse files

1. try this:

 

 

[Embed(source="/images/pause.png")] private var pauseIcon:Class;

var pauseButton:IconButton = new IconButton();
pauseButton.setIcon(new pauseIcon());

 what's the exact message of the compiler?

 

2. I think filebrowsing isn't really supported in simulator, yet. You can try to leave the filter. You should see a couple of images. There is nothing more you can do now.

 

 

Please use plain text.
Developer
Harry_Dodgson
Posts: 151
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: How to create icon button / browse files

Hi,

 

    You can browse() in the 0.9.2 SDK, but there is nothing in the shared folder until you put something there.  In the 0.9.0 simulator, there were 4 images there, but what was shown was pretty random.

 

Harry

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide
Please use plain text.
New Developer
richardyiu
Posts: 17
Registered: ‎01-14-2011
My Device: Not Specified

Re: How to create icon button / browse files

 

thanks Levion,
I still got an error after changing my code.  "A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package."  Is it because I am not placing my .png file in the correct folder?
package{

import flash.display.Sprite;
...
[SWF(height="600", width="1024", frameRate="30", backgroundColor="#FFFFFF")]
[Embed(source="/images/player_pause.png")]  var pauseIcon:Class;
public class Main extends Sprite{
public function Main(){
var pauseButton:IconButton = new IconButton();
pauseButton.setIcon(new pauseIcon());

 

...

}

}

 

project.jpg

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to create icon button / browse files

[ Edited ]

The embedded definition needs to be inside the class like a normal attribute/member of that class.  You have it outside the class.

 

[SWF...

public class Main extends Sprite

{

  [Embed(source="/image/player_pause.png")] private var pauseIcon : Class;


  public function Main()

  {

    var btn : IconButton = new IconButton();

    btn.setIcon( new pauseIcon() ); 

    this.addChild( btn ); 

  } 

Please use plain text.
Developer
JRab
Posts: 2,462
Registered: ‎11-04-2010
My Device: Bold 9700

Re: How to create icon button / browse files

hey richard,

 

try getting rid of the first forward slash in your image path:

 

 

[Embed(source="images/player_pause.png")]  var pauseIcon:Class;

 

good luck!

 

J. Rab (Blog) (Twitter)
--
1. If you liked my post or found it useful please click on the thumbs up and provide a Like!
2. If my post solved your problem please click on the Accept as Solution button. Much appreciated!

Approved Apps: OnTrack | ssShots | Hangman
Please use plain text.
New Developer
richardyiu
Posts: 17
Registered: ‎01-14-2011
My Device: Not Specified

Re: How to create icon button / browse files

thanks jtegen, finally I can see my button on the screen.  It's not quite what I expected though.  I see my square icon and a rectangular button underneath.  Is there a way to hide the rectangular button and just display the icon as the button?

 

JRab, it doesn't really matter, as not as I put the .png files under src\images\

Please use plain text.
Developer
Harry_Dodgson
Posts: 151
Registered: ‎10-26-2010
My Device: Bold 9900
My Carrier: AT&T

Re: How to create icon button / browse files


richardyiu wrote:

thanks jtegen, finally I can see my button on the screen.  It's not quite what I expected though.  I see my square icon and a rectangular button underneath.  Is there a way to hide the rectangular button and just display the icon as the button?

 

JRab, it doesn't really matter, as not as I put the .png files under src\images\


 

Set the IconButton size to be the same size as your image.

--------------
Accepted PlayBook Applications: Marmi-doos, BASIC, Run and Hide
Please use plain text.
New Developer
richardyiu
Posts: 17
Registered: ‎01-14-2011
My Device: Not Specified

Re: How to create icon button / browse files

thanks, finally I created the icons that I want.

 

Is there a way to automatically position the new button right next to the old button?  I don't want to hard code the position because it may change if the user rotates the screen

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: How to create icon button / browse files

var prev_btn : Button = new Button();

prev_btn.x = 10;

prev_btn.y = 10;

var next_btn : Button = new Button();

next_btn.x = prev_btn.x + prev_btn.width + 10;

next_btn.y = prev_btn.y;

 

??

 

Or you can use containers.

Please use plain text.