When i press a button it will display text, but how would i add style? such as position and color.
import flash.text.TextField;
var tf:TextField= new TextField();
convob.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
tf.text="hello world";
addChild(tf);
}
Something like this:
var format:TextFormat = new TextFormat();
format.color = 0x555555;
format.size = 18;
format.align = TextFormatAlign.CENTER;
format.bold = false;
tf.setTextFormat(format);
Check class reference for TextFormat: http://help.adobe.com/en_GB/FlashPlatform/reference/actionscript/3/flash/text/TextFormat.html
Related
I am still new in Vaadin and I am trying to implement #polymenr/paper-slider component using Vaadin 14.
I have downloaded the project https://github.com/berndhopp/vaadin-paper-sliders from Github and I am trying to set "pin" property as explained here
https://vaadin.com/forum/thread/18215247/vaadin-14-slider
In PaperSlider.java
...
public void setPin(boolean pin) {
this.getElement().setProperty("pin", pin);
}
...
In DemoView.java
package org.vaadin.addon.sliders.ui;
//import org.vaadin.addon.sliders.PaperSlider;
import org.vaadin.addon.sliders.PaperSlider;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.Route;
#Route("")
public class DemoView extends VerticalLayout
{
private PaperSlider slider = null;
private Label sliderValue = null;
public DemoView()
{
Anchor sourceLink = new Anchor("https://github.com/markhm/vaadin-paper-sliders", " (source code on GitHub)");
sourceLink.setTarget("_blank");
HorizontalLayout titleBox = new HorizontalLayout();
titleBox.setAlignItems(Alignment.BASELINE);
H3 title = new H3("Vaadin paper-slider, ported to Vaadin v14");
titleBox.add(title, sourceLink);
add(titleBox);
//
// https://stackoverflow.com/questions/68531460/vaadin-14-paper-slider-pin-property
//
HorizontalLayout sliderLine = new HorizontalLayout();
sliderLine.setHeight("100px");
Label sliderValue = new Label();
PaperSlider paperSlider = new PaperSlider(0,100,20);
paperSlider.addValueChangeListener(e -> sliderValue.setText("New Slider value: " + e.getValue()));
paperSlider.setPin(true);
sliderLine.add(paperSlider, sliderValue);
add(sliderLine);
// slider.getElement().getStyle().set("padding-top", "30px") ;
//Label whiteline = new Label("");
//whiteline.setHeight("50px");
//add(whiteline);
// Testing pin property
// HorizontalLayout mySliderLine = new HorizontalLayout();
//sliderValue = new Label("mySlider value");
//PaperSlider paperSlider = new PaperSlider(0,100,20);
//paperSlider.getElement().getStyle().set("padding-top", "30px");
//mySliderLine.setHeight("100px");
//paperSlider.setPin(true);
//mySliderLine.add(paperSlider);
// slider.setPin(true) ;
// add(slider) ;
// NB: The PaperRangeSlider does not support Polymer 3.
// HorizontalLayout rangeSliderLine = new HorizontalLayout();
//
// Label rangeValues = new Label("Range values");
// rangeSlider = new PaperRangeSlider(0, 100, 40, 60);
// rangeSlider.addValueChangeListener(e -> rangeValues.setText("Range values: " + e.getValue()));
// rangeSliderLine.add(rangeSlider, rangeValues);
// add(rangeSliderLine);
}
}
I can see the paper slider but I don't see the numeric value label when the slider thumb is pressed.
Can anyone help with this please
Thanks
Alex
It seems numeric value get lost within the layout. You can try adding height to the layout, something like sliderLine.setHeight("100px") or adding some padding to the component paperSlider.getElement().getStyle().set("padding-top", "30px").
from the original post I missed the part that you have an extra Label component and that's the value that you can't see. If I do this:
HorizontalLayout sliderLine = new HorizontalLayout();
sliderLine.setHeight("100px");
Label sliderValue = new Label();
PaperSlider paperSlider = new PaperSlider(0,100,20);
paperSlider.addValueChangeListener(e -> sliderValue.setText("New Slider value: " + e.getValue()));
paperSlider.setPin(true);
sliderLine.add(paperSlider, sliderValue);
add(sliderLine);
I get to see that label with the selected value
I was trying to put a sprite over another sprite and get the name of the drop target. When I use a loder in my sprite the result is not the name of the sprite, but his instance number. I will post the code below and hope that someone could help me. Thanks alot!
package
{
import flash.display.*;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.MouseEvent;
public class dragAndDrop extends MovieClip
{
public function dragAndDrop()
{
// constructor code
var imagineDrag:Sprite = new Sprite;
imagineDrag.x = 150;
imagineDrag.y = 150;
var fundalLoader:Loader = new Loader();
var fundalLoaderURL:URLRequest = new URLRequest("butStartActiv.png");
fundalLoader.load(fundalLoaderURL);
imagineDrag.addChild(fundalLoader);
imagineDrag.name = "Tinta";
addChild(imagineDrag);
var target1:Sprite = new Sprite();
target1.graphics.beginFill(0xCCFF00);
target1.graphics.drawRect(265, 100, 125, 125);
target1.name = "casuta1";
addChild(target1);
var imagineDeTras:Sprite = new Sprite;
imagineDeTras.x = 10;
imagineDeTras.y = 10;
var fundalLoader2:Loader = new Loader();
var fundalLoaderURL2:URLRequest = new URLRequest("butStartInactiv.png");
fundalLoader2.load(fundalLoaderURL2);
imagineDeTras.addChild(fundalLoader2);
addChild(imagineDeTras);
imagineDeTras.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);
imagineDeTras.addEventListener(MouseEvent.MOUSE_UP, stopDragObject);
imagineDeTras.buttonMode = true;
imagineDeTras.useHandCursor = true;
imagineDeTras.mouseChildren = false;
function dragObject(evt:MouseEvent):void
{
evt.currentTarget.startDrag();
trace("nume : " + evt.currentTarget.name)
}///// end drag object
function stopDragObject(evt:MouseEvent):void
{
//trace("e.target.name " + e.target.name);
trace("tinta atinsa este: " + evt.target.dropTarget.name);
evt.target.stopDrag();
}//// end function stop drag
}/// end constructor
}// end class
}
When you drag and drop imagineDeTras over target1, the answer is "casuta1"
When I drag and drop imagineDeTras over imagineDrag, instead of "Tinta" the answer is instance126. Can somebody help me with this problem? Thank you very much!
The problem is a tiny mistake on your code!
On dragObject function you wrote :
trace("nume : " + evt.**currentTarget**.name)
And it's correct, But you forgot to use currentTarget instead of target on the stopDragObject!
trace("tinta atinsa este: " + evt.**target**.dropTarget.name);
You have to replace the target with currentTarget to make it trace the name of item that you add your listener to it instead of the name of it's child that mouse_up event triggered on.
Also you have to remove "dropTarge" after the curretlntTarget
You can see this if you have problem on understanding target and currentTarget: AS3: Difference between target vs currentTarget
I have this code for custom keyboard.
Its xamarin.forms for android.
I want the keyboard to be presented from bottom of the page and to raise the Entry if needed.
the result is that the keyboard is presented on top of the page and covers the entry if the entry is on the top.
~
public class CustomEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
base.OnElementChanged(e);
if (Control == null)
return;
Android.InputMethodServices.Keyboard numericKeyboard = new Android.InputMethodServices.Keyboard(Control.Context, Resource.Xml.keyboard2);
CustomKeyboardView numericKeyboardView = new CustomKeyboardView(Control.Context, null);
numericKeyboardView.Id = Control.Id;
numericKeyboardView.Keyboard = numericKeyboard;
numericKeyboardView.Visibility = ViewStates.Gone;
numericKeyboardView.PreviewEnabled = false;
/////////////////////////////////////////////////
// THIS IS THE LAYOUT CREATION
////////////////////////////////////////////////
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent); // maybe WrapContent on all
lp.Gravity = GravityFlags.Bottom;
lp.BottomMargin = 0;
/////////////////////////////////////////////////
Activity activity = this.Context as Activity;
activity.AddContentView(numericKeyboardView, lp);
Control.Touch += (sender, ex2) =>
{
if (numericKeyboardView.Visibility == ViewStates.Gone)
{
//Xamarin.Forms.Animation animation = Android.Views.Animations.AnimationUtils.LoadAnimation(
Android.Views.Animations.Animation animation = Android.Views.Animations.AnimationUtils.LoadAnimation(
this.Context,
Resource.Animation.slide_in_bottom
);
numericKeyboardView.ShowWithAnimation(animation);
numericKeyboardView.Visibility = ViewStates.Visible;
}
ex2.Handled = true;
};
}
}
~
I want the keyboard to be presented from bottom of the page and to raise the Entry if needed.
You need to wrap your numericKeyboardView with a RelativeLayout and set the Rule of AlignParentBottom.
In OnElementChanged method, add the following codes:
//Create RelativeLayout for Keyboard
Android.Widget.RelativeLayout rl = new Android.Widget.RelativeLayout(this.Context);
//Create the LayoutParams for Keyboard
Android.Widget.RelativeLayout.LayoutParams rlp = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.FillParent, LayoutParams.WrapContent);
//set the AlignParentBottom rule
rlp.AddRule(LayoutRules.AlignParentBottom);
//set the LayoutParams to Keyboard
numericKeyboardView.LayoutParameters = rlp;
//add the keyboard to RelativeLayout
rl.AddView(numericKeyboardView);
//get current activity
Activity activity = this.Context as Activity;
//Add the Layout View to activity
activity.AddContentView(rl,rlp);
I want to check if the textboxes created like this:
(function(arr) {
for (var i = 0; i < arr.length; i++) {
app.add(app.createLabel(arr[i] + " mail"));
app.add(app.createTextBox().setName(arr[i]));
}
})(["first", "second", "third"]);
have the same contents? I was looking for something like getElementByTagname or or getTextboxes, but there are no such functions.
So how to iterate thvrough them and show a label if they are all equal?
To access any widget values you need to add them as a callback element (or a parent panel) to the server handler that will process them. The values of each widget are populated on a parameter passed to the handler function and can be referenced by the widget name (that you already set).
You don't need to setId as suggested on another answer. Unless you want to do something with the widget itself (and not its value). e.g. change its text or hide it, etc.
var textBoxes = ["first", "second", "third"];
function example() {
var app = UiApp.createApplication().setTitle('Test');
var panel = app.createVerticalPanel();
textBoxes.forEach(function(name){
panel.add(app.createLabel(name + " mail"));
panel.add(app.createTextBox().setName(name));
});
panel.add(app.createLabel('Example Label').setId('label').setVisible(false));
var handler = app.createServerHandler('btnHandler').addCallbackElement(panel);
panel.add(app.createButton('Click').addClickHandler(handler));
SpreadsheetApp.getActive().show(app.add(panel));
}
function btnHandler(e) {
var app = UiApp.getActiveApplication(),
allEqual = true;
for( var i = 1; i < textBoxes.length; ++i )
if( e.parameter[textBoxes[i-1]] !== e.parameter[textBoxes[i]] ) {
allEqual = false; break;
}
app.getElementById('label').setVisible(allEqual);
return app;
}
Notice that ServerHandlers do not run instantly, so it may take a few seconds for the label to show or hide after you click the button.
When you create the textboxes, assign each one an id using setId(id).
When you want to obtain their reference later, you can then use getElementById(id).
Here is an example:
function doGet() {
var app = UiApp.createApplication();
app.add(app.createTextBox().setId("tb1").setText("the original text"));
app.add(app.createButton().setText("Change textbox").addClickHandler(app.createServerHandler("myHandler")));
return app;
}
function myHandler() {
var app = UiApp.getActiveApplication();
app.getElementById("tb1").setText("new text: in handler");
return app;
}
Here is my class, very simple:
public class SelectYesNoArea extends Manager {
BitmapField yes;
BitmapField no;
DateField date;
Calendar cal;
public SelectYesNoArea(long style){
super(style);
Bitmap bgPic = Bitmap.getBitmapResource("divBackgrounds.png");
Background bg = BackgroundFactory.createBitmapBackground(bgPic);
setBackground(bg);
cal = Calendar.getInstance();
date = new DateField("",cal.getTime().getTime(), DateFormat.DATE_SHORT);
add(date);
Bitmap bitYes = Bitmap.getBitmapResource("yes.png");
yes = new BitmapField(bitYes);
add(yes);
Bitmap bitNo = Bitmap.getBitmapResource("no.png");
no = new BitmapField(bitNo);
add(no);
}
}
I just want to handle when a user taps on the bitmapField. How can I do this?
Use an anonymous class:
yes = new BitmapField(bitYes) {
trackwheelClick(int status, int time) {
Do whatever you want here !
}
}
Try using the Field.FOCUSABLE style when creating your BitmapField.