I got a dynamic Textfield called txt_nOpp setted to 1, I also got a slider, called Slider1, The slider can only assume values betweed 1 and 6. While the user sets slider value, the text should change.
I've implemented this code:
Slider1.addEventListener(SliderEvent.CHANGE, slHandler);
function slHandler(e:SliderEvent):void{
txt_nOpp.text = String(e.value);
}
Flash doesn't return any error, but the slider/text works only at value 1, the other values of the slider make the text disappear... What's wrong?
SliderEvent.CHANGE only updates when you release the slider, so try
Slider1.addEventListener(Event.ENTER_FRAME, function()
{
txt_nOpp.text = Slider1.value.toString();
});
instead.
I fixed it, it was an anti aliasing problem, just set it as device font and now works
Related
I am facing problem concerning switching background in Angular 10. I managed to implement switching background image but I would like it to be smooth.
At this moment it looks kind of like the slideshow - one image disappears and the other one appears.
My piece of code looks like this:
In typescript component I hold array of variables with urls to image.
backgroundImages = ['url(/assets/img/background.jpg)', 'url(/assets/img/background2.jpg)']
And in constructor I call refresh method which basically changes the value of variable holding reference to current background
refreshBackground(backgroundNumber: number) {
this.background = this.backgroundImages[backgroundNumber]
if (backgroundNumber == this.backgroundImages.length - 1)
backgroundNumber = 0
else
backgroundNumber++
setTimeout(() => this.refreshBackground(backgroundNumber), 10000)
}
In html this variable is set to style.background
<div class="container background" [style.background]="background">
I would appreciate any help and tips and if more details are needed, ask freely.
Michael
I have a MenuItemImage here:
auto myImage = MenuItemImage::create("image.png","image_selected.png",
CC_CALLBACK_1(HelloWorld::onImageClicked,this));
It allow me to input a image.png, which will be changed to image_selected.png on selected when I navigate between items in my menu with keyboard. However, I want to perform some actions when select it with myImage->selected(); (NOT activate it by clicking/touching or calling for myImage->activate(); function), not just a boring image_selected.png.
Now, I'm thinking about set up all of those action in:
keyBoardListener->onKeyPressed = [&](cocos2d::EventKeyboard::KeyCode keycode, Event* event)
{ // Setting up actions on KEY_RIGHT_ARROW or KEY_LEFT_ARROW pressed};
However this way makes things complicated. Therefore, I want to ask if there's any way that I could set up all of my actions as myImage being creating so I could call all of those action with a simple myImage->selected() or stop them with myImage->unselected() later?
Your attention and help is very much appreciated :D
Simply do this:
auto myImage = MenuItemImage::create("image.png", "image_selected.png", [&](Ref* ref){
//your code here
//by ref you can access "myImage" object
});
edit:
I'm not sure what are you trying to achieve. Do you want to have a few buttons in menu, which always one of the is selected and change them using arrows? (so menu navigation is like on console games).
edit2:
After watch a sample yt video I don't think you can achieve this relying only on MenuItemImage. Instead I'd create a ui::Button (if you need clicking/touching as well) or Sprite. Then I'd handle button states by myself. As for glowing frame you probably need some fancy shader or create it in photoshop and add to it an action with constantly fading out and in.
Sorry for my complicated questioning ;)
I've created several components on my stage (Slider, TextLabel, CheckBox, ...) with the addChild(...) method. Now, if the user needs one Slider component more (for another input), I want to give him a button "addButton" (already on stage) with an CLICK addEventListener. The function which is fired in the addEventListener should create a new Slider component on stage, e.g.
addButton.addEventListener(MouseEvent.CLICK,addSlider("slid1",20,160,250,0,250,30));
The problem is to pass the parameters to the function, i need to set the new Slider to several basic values, like position, width, minimum, maximum and so on....
Can this be achieved in this way?
thx,
edwin
There are several ways you can do this. The simplest way is to call your function inside a mouse event handler:
addButton.addEventListener(MouseEvent.CLICK, addSliderHandler);
function addSliderHandler(e:MouseEvent):void {
{
addSlider("slid1",20,160,250,0,250,30);
}
EDIT (to answer your comment question):
To position your new component according to existing components, you can keep a variable reference to the position in the script and pass this as a parameter. For instance, suppose you want the first generated slider to be at y:160, and every slider to be 40px more than this, change the script to this:
var sliderY:int = 160;
addButton.addEventListener(MouseEvent.CLICK, addSliderHandler);
function addSliderHandler(e:MouseEvent):void {
{
addSlider("slid1",20,sliderY,250,0,250,30);//Pass sliderY instead of literal number
sliderY += 40;//Add 40 to sliderY
}
Now, every time you use this function to create a button it will be positioned at y = sliderY, then it will add 40 to sliderY....so the first one generated will be at 160, the next at 200, the next at 240 etc.
Hope this helps!
So heres the code Im using:
endScreen.scorePrint.text = String(score);
endScreen.distancePrint.text = String(distance);
And it doesent show anything, while the very same code in other places in my app works, I tried to embed fonts and stuff but I still get blank space. what am I doing wrong?
EDIT:
endScreen is a MovieClip without AS linkage, its manipulated by .visible , scorePrint and distancePrint are a part of that MovieClip.
scorePrint and distancePrint are identical in all but names and are as following:
classic text -> dynamic text
Try
endScreen.scorePrint.text = "" + score;
if not, then does
trace("" + score);
show anything?
I fixed it, the problem was anti-aliasing. I changed from anti-aliasing for readability to device fonts. that fixed both fields.
Thanks for support :)
Please note the remark mentioned WORKAROUND at the end of this question.
Based on a Dictionary based specification, one of my classes creates a Form programmatically.
Adding TextInput or DatePicker to FormItemss works as expected.
Unfortunately, the following code just creates a colored rectangle, not the actual picker:
ti = new ColorPicker();
ColorPicker( ti ).selectedColor = TAColor( _spec[ key ].value ).color;
and later on
formItem.addElement( ti );
The Form is embedded in a TitleWindow component presented using
PopUpManager.addPopUp(...);
When added to TitleWindow, it shows up correctly, within Form->FormItem not:
I can't image, why the picker doesn't appear. Do you?
WORKAROUND:
If I wrap the ColorPicker inside a Group things work:
ti = new Group();
Group( ti ).addElement( new ColorPicker() );
In this case, the ColorPicker appears as editable.
Still, I'd be too happy to learn what the problem with my initial solution. Bug?
A DateField (which extends ComboBase like ColorPicker) behaves properly in a spark Form. But in the ColorPicker, the mouse down handler of the button never gets called. I think that maybe the skin part that handles the mouse clicks (it must be a button) is not properly dimensionned, and the result is it is not shown. I've come to this conclusion because within an mx Form, the ColorPicker doesn't display as it does when it is added to the regular displaylist...
Hope this helps...
In the code you've provided, you never add the colorPicker as a child to any parent container; as such it will never show up anywhere.
You probably need to do something like:
formItem.addChild(ti );
[or for a Spark formItem]:
formItem.addElement(ti );
I'm confused as to why you're seeing a rectangle.