02-08-2011 12:30 AM
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
Solved! Go to Solution.
02-08-2011 01:05 AM
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.
02-08-2011 07:23 AM
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
02-08-2011 11:41 AM
...
}
}
02-08-2011 11:48 AM - edited 02-08-2011 11:50 AM
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 );
}
}
02-08-2011 11:50 AM
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!
02-10-2011 12:22 AM
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\
02-10-2011 07:13 AM
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.
02-14-2011 12:56 AM
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
02-14-2011 07:40 AM
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.