Script a button to its rollover state? - actionscript-3

Anyone know if it is possible via AS3 to change a button to its rollover state when it is not, in reality, rolled over?
Client decided way late in process to ask for some other elements to affect button states. If I had known I would have used movie clips instead of buttons.
Thanks for any advice.

Have you tried manually calling gotoAndStop(2) ?
If none of the above solutions work, you'll either have to subclass SimpleButton and link it to your symbols or rebuild in MovieClips

Dispatch the rollover event manually? Apart from that, I don't see any other way. I am curious though, what sort of requirement(s) would mandate such an oddity.

You can open the properties of any library display object and change it to a button, graphic, or movieclip type. this should allow you to then change the instance type to button and retain rollover abilities while allowing "gotoAndStop" actions on the instance. I'm not totally sure this works, and this thread is old, but if anyone has this same issue it would be worth a shot. This is assuming you aren't creating SimpleButtons dynamically.

Related

Issue with transitions between scenes using effects

I've ran into a (hard to catch) issue using transitions between scenes in Cocos2d-x.
Basically I normally do a fade in-fade out like this:
Director::getInstance()->replaceScene(TransitionFade::create(0.5, scene, Color3B(0, 0, 0)));
It looks visually good and proper and all but I realized that it can be dangerous. If I have a button to go from Scene A to Scene B this way, the transition will run for 0.5 seconds as per the above implementation. When tapping ONCE and waiting, everything will be fine but if you tap very fast, it IS possible to have the event of the button called another time, even though the first transition call is already under way. This can, and I think in my case, lead to all sorts of strange and dangerous things. Especially for me who often use a protocol/delegate pattern for fetch data callbacks etc.
Want we want to do is to disable any UI (at least, possibly more?) on scene A as soon as the transition starts just to be sure that no other pushes are possible to the same or any other button, causing more transitions to be launched which could cause harmful things. Or there should be some kind of feature within cocos2d-x to always refuse transitions if one transition is already under way... To me that sounds like the most sane thing at first thought.
Is there anything I missed or are transitions in cocos2d-x really this dangerous? Anyone tackled this? Maybe a way to check if a transition is already under way would be one way for me to get around this problem without hacking around on cocos2d-x itself?
The virtual cocos2d::Node function onEnterTransitionDidFinish() could be used to unregister your callbacks for web requests etc.
Assuming you don't use the cocos2d-x event system for any app logic during a transition you might also consider disabling the EventDispatcher to block the propagation of touch events.
You could simply disable the button after it triggers.
Or you could be super lazy and create a Layer/TouchListener to intercept touch when a transition begins (onEnterTransitionDidStart()), and destroy it along with your scene :)

How to connect two UI Elements by swiping? WP8.1

Actually I'm developing a simple game. In my game, I need to connect multiple buttons by swiping. But I don't know which events should I use to do that. What I want is kind of similar to Candy Crush game.
Please help me out guys!
Take a look at Handling pointer input on MSDN, specifically the PointerPressed, PointerMoved, and PointerReleased events. You can keep track of the pointer information by making use of the PointerRoutedEventArgs argument passed in those events, including checking whether the pointer belongs to a mouse or if it is brought about by touching the screen. There are some good examples in each article.

To reset game, will I need to add objects dynamically?

Good evening/ morning.
I am creating a game in As3 where the enemies are added not added dynamically.
if(hero attacks enemy)
{ then parent.removeChild(enemy) }
When the hero attacks the enemy the enemy removes it self from the display list I presume.
but when you reset the level, i.e go back to the start menu and go back to the level you will see the enemies are not in the level, since they've been removed.
My question is, is there a way I can reset the display object in that frame, in As2 I refreshed the flash movie. But that's not good in terms of coding as it shows you are not developing or learning.
IF there is no way, will you suggest adding the objects that will be removed, dynamically?
another question is that my level is in a container.
//on the stage, there is a movieclip called container.
//In this container mc(movie clip) it contains the whole level, including platforms,
//enemies and props
IF I remove a prop from that container, in order to reset the game will I do this
container.addChild(prop)
//the question is that how do I set it's x and y position?
Thank you, I will appreciate every ones feedback and advice.
Yes, as you remove them dynamically, you need to add them dynamically again in order to reset them. You either predefine their positions and set them again, or you can just hide those enemies and make them visible once again the game resets. Depends on your code and structure.
Ideally, instead of removing them from the display list, your best bet is to hide then and put them and reset their position back to their original point.
A good practice to get into is to avoid the chance of runaway instantiation if at all possible; this means, if you're going to instantiate and remove enemies every time they're spawned and killed, the garbage collector has to work very hard to keep up. A better approach would be to have a pool of enemies that is as large enough to support as many enemies as you would ever need at one time.

Custom cell in list in Flash AS3

I am no expert in Flash, and I need some quick help here, without needing to learn everything from scratch.
Short story, I have to make a list where each cell contains an image, two labels, and a button.
List/Cell example:
img - label - label - button
img - label - label - button
As a Java-programmer, I have tried to quicly learn the syntax and visualness of Flash and AS3, but with no luck so far.
I have fairly understood the basics of movie clips etc.
I saw a tutorial on how to add a list, and add some text to it. So I dragged in a list, and in the code went list.addItem({label:"hello"}); , and that worked ofc. So i thought if I double-clicked the MC of the list, i would get to tweak some things. In there I have been wandering around different halls of cell-renderers etc.
I have now come to the point that I entered the CellRenderer_skinUp or something, and customized it to my liking. When this was done, I expected i could use list.addItem(); and get an empty "version" of my cell, with the img, labels and the button. But AS3 expects an input in addItem. From my object-oriented view, I am thinking that i have to create an object of the cell i have made, but i have no luck reaching it.. I tried to go
var test:CellRenderer = list.listItem;
list.addItem(test);
..But with no luck.
This is just for funsies, but I really want to make this work, however not so much that I am willing to read up on ALOT of Flash and AS3. I felt that I was closing in on the prize, but the compiler expected a semicolon after the variable (list.addItem({test:something});).
Note: If possible, I do NOT want this:
list.addItem({image:"src",label:"text",label"text",button:"text"});
Well.. It actually is what I want, but I would really like to custom-draw everything.
Does anyone get what I am trying to do, and has any answers for me? Am I approaching this the wrong way? I have searched the interwebs for custom list-cells, but with no luck.
Please, any guiding here is appreciated!
Sti
You could use a Datagrid as well, with each column pointing to the appropriate part of the data source (possibly even the same field, depending on what you're doing). You can then just use the ImageCell as the renderer for the second and third colums.
I think you're just not understanding that Adobe, in the own woolly-headed little way, is separating the Model from the View on your behalf. You hand the Model to the View and then get out of the way. The extent of what you can/should change is just telling it what renderer to pop your data into.
In fact, the fl.controls don't give you much control at all about how they work--I wouldn't go down the road of trying to create a custom itemRenderer with any signifcant functionality for them if you don't fully understand how the Display List works and if you're not comfortable digging around in the debugger and ferreting out all kinds of undocumented information.
For more details (to the extent anyone knows anything about how these work), see
http://www.adobe.com/devnet/flash/quickstart/datagrid_pt1.html
http://www.adobe.com/devnet/flash/quickstart/datagrid_pt2.htmlhttp://www.adobe.com/devnet/flash/quickstart/datagrid_pt3.html
http://www.adobe.com/devnet/flash/quickstart/tilelist_component_as3.html
Do you have the option to use the Flex Framework instead of pure Flash? It makes this kind of extension much more satisfying. It's aimed more at application developers, whereas Adobe sees Flash users more as designers.

Alternate of masking technique to ignore mouse event on parts on asset

In my isometric flash game I have some models with long shadows. I want to ignore the mouse events (move, click, down and up) when the user performs any action on the shadow part of the image. (see sample image)
I know there is a way we can do it by creating a mask in flash. But what if I want to handle it on the .png images (bitmap)? Do I need to create a mask image for all such images? I think it will be very big deal unless there are easy ways (using tools in Photoshop).
Update:
Looking for a "codable" solution to handle the shadows (like the one Richie_W said
Get the pixel colour value where the mouse was clicked - If it is the
shadow colour you can then ignore the click
NOT a solution which involves art work, like creating mask asset or creating shadow asset etc
My friend told me cityville is not using masks but they are handling from code.
Does any one know how it can be done? OR
It can't be programed and only way is to create masks?
There are a number of options you could try (IMO in order of solution quality):
Update your system to seperate out the shadow asset from the thing casting the shadow. From there it is easy to only attach a click listener to the correct asset. This system allows for future improvements such as changing the shadow asset at runtime (Different times of the day etc) without having to deal with updating the click listener node.
Get the pixel colour value where the mouse was clicked - If it is the shadow colour you can then ignore the click. This is a pretty flaky solution but quick to implement.