TileList custom ImageCell, buttons/sprites on each image - actionscript-3

Hi im trying to add some buttons or sprites on each of TileList items, i even made my own ImageCell class and inject some code that adds sprite on each image but it is not clickable - all clicks are reffering to "object MyImageCell" not that specific sprite, is there a solution for this or any other way for adding some content on TileList items?

I think you have the some problem as I met.In your MyImageCell class add this property:this.mouseChildren = true;
Hope this can help.

Related

Actionscript 3, how do I make a menu appear by clicking a button, on the same frame?

So I have a button called manpb. When I click manpb, I want a menu to appear. The menu is a picture, but I can convert it into an object if this helps.
The best I can do is: Make a second frame with the menu, and insert the code inside the man_pb function:
gotoAndStop(2);
My problem is that I want the menu to appear on the same frame; then the menu will have buttons of his own. Any idea what to type inside the function below?
manpb.addEventListener(MouseEvent.CLICK, man_pb);
function man_pb(event:MouseEvent):void{
}
A big thank you!
The most intuitive solution might be to have your menu inside a MovieClip on the same frame. The menu buttons can also be placed within that menu MovieClip.
Simply convert your menu picture to a MovieClip (right-click, convert to MovieClip). Make sure that you select the MovieClip, and in the Properties panel give it an Instance Name, like menuMC or anything you want.
There are then a couple ways that you could handle making the menu appear only when you click the button.
1- Set the MovieClip's opacity to 0 by default, and then include this in your button function:
menuMC.alpha = 1;
thereby changing the MovieClip to fully opaque.
2- Make the MovieClip comprised of two frames, one empty frame that has a stop(); action, and one frame that contains your menu image and buttons. Then the button code would be:
menuMC.gotoAndStop(2);
3- Load the MovieClip dynamically from your library. See this for more information. edit: This is the approach that #DodgerThud is referring too, and is the more advanced but more comprehensive approach.
Use your Menu as an Object and add it to the MovieClip you want.
var menu:Menu = new Menu();//This is your Menu Symbol in your Library, you need to create one before you can use it
var manpb;//you could do the same thing for button, so you only need one symbol that has uses different labels
manpb.addEventListener(MouseEvent.CLICK, man_pb);
function man_pb(event:MouseEvent):void{
if(contains(menu)){//checking if "menu" already exists
removeChild(menu);//remove it from the displaylist
}else{
addChild(menu);//add it to the displaylist
}
}
In the Listener function you check if your current MovieClip (this should NOT be Button) already has a child that is menu. If it does, it removes the menu, otherwise, it will add the menu.
Don't forget to export your Menu for ActionScript.

Can I create an overlay layer to disable all touches, even on menus?

I need to show a popup layer on a scene, creating a semi-transparent background layer that will also prevent touch events propagation. I am using the latest cocos2d-x v. 3.0-alpha-0.
What I want to achieve is a popup layer that fully handles touches (eg. buttons, menu items, scroll views, etc.), laying on a background layer (for design purposes), that covers the current scene. All items in the scene should not respond to touches any more.
Is this achievable using the new EventDispatcher class? I've been able to disable all touches to the main scene, but all instances of MenuItem that live in the scene are still touchable and active.
How can I achieve this? And, also, how can I create a touch listener that prevents all touches to the main scene but not to the popup?
You can disable menu items by setting setDisable property of menuitems to false.
Example
_menuItem->setEnabled(false);
For Layers use setTouchEnabled property
_backGroungLayer->setTouchEnabled(false);
Make sure that popup layer is not child of layer you want to disable.
To disable all items in menus do this
Suppose _menu contain various menuitems.
CCARRAY_FOREACH(_menu->getChildren(), item)
{
item.isEnabled=NO;
}
if you want to disable selected items just give them tags.There is no need to make any list.
I had the same problem and solved it with mm. It was dirty, but it worked:
Create a button using ccui.button.
Set the button size to your screen size.
Add this button as a background to your popup layer.
This will prevent any thing behind it being clicked.
By default, all CCMenu's have a set priority (kCCMenuHandlerPriority = -128) in cocos2d 2.1. So in a class (usually a CCNode descendant) that wants to swallow everything and preempt anything i do like in this dialog sequencer example below :
- (void)onEnter {
backdrop_.visible = self.isBackDropShown;
MPLOG(#"Adding self as a swallower touch delegate, above the rest of the planet.");
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:_dialogTouchPriority swallowsTouches:YES];
for (CCMenu *mn in _menus) {
mn.touchPriotity = _dialogTouchPriority -1 ;
}
[super onEnter];
}
where _dialogTouchPriority is kCCMenuHandlerPriority-1 by default. It will be served before everything 'below'. It is a bad hack (cocos2d internals could be changed and break this), i know , but bullet proof. Use carefully, make certain you only ever have one of these in your scene.

Move MovieClip and everything it contains

I have a MovieClip called navbar and it has buttons over it. How do I connect the buttons to the MovieClip so that when the MovieClip is moved the buttons move with it? I have been able to make the navbar draggable but the buttons aren't dragged with it.
I have tried the following:
navbar.addChild(button1);
This just made the button disappear.
Your approach is correct: adding the buttons as children to the MovieClip will allow them all to be moved as one item.
The button disappearing could be any number of reasons, for instance x and y now relative to new parent (i.e. setting button y to 600 is now 600 pixels down from the navbar, not from the stage or old parent).
Try commenting out any properties you have set on the button and see if that resolves the issue, from there you can determine which property is causing the button to disappear.
So you should basically just have something like this:
var button1:Button = new Button();
navbar.addChild(button1);
If even with that minimal code doesn't result in the button displaying on the navbar, you'll need to post more code so that we can see where the problem is occurring.
you can calculate distance from Movieclip's X,Y to buttons and you can write a code like this:
var diff1:int = navbar.x - example_button1.x;
stage.addEventListener(Event.ENTER_FRAME, function(event:Event):void{
example_button1.x=navbar.x-diff1;
});
you can duplicate example_buttons and diff variables.
or you can startDrag() sametime with same event listener,
navbar.addEventListener(someEvent.some, function(event:someEvent):void{
MovieClip(root).navbar.startDrag();
MovieClip(root).example_button1.startDrag();
});
MovieClip(root) allows you to effect main stage. With this property you can effect an object from inside of navbar for example.
As you supposed, if you want the navbar and the buttons to act like a unique element you need to put buttons inside the navbar and not just over it.
The reason the button is disappearing is due to the fact that it has been put on the stage in Designer so, when you add it to navbar, you have it into two different display stacks, and that's not allowed.
You should put buttons inside the navbar in Designer, or export them for AS and then instance them dynamically, as follow:
var btn:Button1 = new Button1()
navbar.addChild(btn)
Class name Button1 is assigned in the MovieClip properties window of the Library, under Export for ActionScript.

Java swing CheckBox is not visible in JCheckBoxMenuItem

The checkbox icon is not visible in my JCheckBoxMenuItem..I add this JCheckBoxMenuItem to JideMenu which extends JMenu.How to make this checkbox visible eventhough if it is not selected..?
Thanks in advance.
I'm not entirely certain where your problem is coming from. It sounds that just the checkbox component isn't visible, while all other MenuItem types are showing up on the Menu.
I'm not very experienced with the Swing library, but if you could put a few lines of code regarding your Menu/MenuItems, I'm certain you'll get a much better answer.
Taking a shot in the dark, you mention that the MenuItem (checkbox) is added to the menu, but have you added the menu into a MenuBar/JMenuBar object and set your JFrame to use that Bar via the setMenuBar() method? This is under the assumption that the entire menu isn't showing up (not just the checkbox component), but figured I'm try to preempt a solution here.
menuBar = new JMenuBar();
menu = new JMenu("A Menu");
menuBar.add(menu);
cbMenuItem = new JCheckBoxMenuItem("A check box menu item");
menu.add(cbMenuItem);
It´s pretty much straightforward and taken directly from here. I guess it´s all anyone can say about it until you show us your code.
setState(true) will show the checkmark… IIRC there's also a constructor that you can pass a boolean if you want it created with the checkmark visible.

How to popup a transparent Panel that is dismissed when clicked outside of it in Flex 4

I need to popup some buttons in Flex 4. Users should be able to see the background (ideally a little faded, but not important) around and in between the buttons. And clicking anywhere except the buttons should dismiss them all.
So I created a spark Panel and added a spark VGroup with some buttons. Then I call
PopupManager.addPopUp(myNewPanel, background, true);
My 2 main problems are the panel is not transparent and clicking outside the buttons doesn't dismiss them... How do I implement that?
UPDATE: Figured out how to dismiss the popup when clicking outside the panel with:
addEventListener("mouseDownOutside", close);
private function close(event:FlexMouseEvent):void {
PopUpManager.removePopUp(this);
}
Now I just need to figure out how to make the Panel transparent so you can see the background around and in between the buttons.
You should use FlexMouseEvent.MOUSE_DOWN_OUTSIDE instead of the string "mouseDownOutside". Code completion, compile-time checking and makes it easier for others to read your code.
For the background, you can use css to style it. Heres a list of all the css properties for a spark panel - http://docs.huihoo.com/flex/4/spark/components/Panel.html#styleSummary