AS2 textField hyperlink - hyperlink

I have to add something to an existing as2 project. I know as3 pretty well, but as2 doesn't make sense to me at all. Basically what I have to do is add a link to the bottom of every "page". The link changes depending on what "page" you are on. I have variables passing, so all I need to do is create the link.
//Url gets passed here
var urlString;
createTextField("urls", 1, 300, 499, 150, 30);
urls.setNewTextFormat(my_fmt);
urls.text = urlString;
Now I have to turn "urls" into a link. What would be the best way to do this?

This would be one possible solution: Create a movieclip to hold the textfield and then use it as a button...
//Url gets passed here
var urlString = "the URL";
this.createEmptyMovieClip("urlHolder", 1);
urlHolder._x = 300;
urlHolder._y = 499;
urlHolder.createTextField("urls", 1, 0, 0, 150, 30);
//urlHolder.urls.setNewTextFormat(my_fmt);
urlHolder.urls.text = urlString;
urlHolder.onRelease = function(){
getURL("www.google.com");
}

Related

PixiJS: Constantly updating PIXI.RenderTexture dumps browser memory

There are two sprites, one is dynamic and second have to be constantly updated with first one through PIXI.RenderTexture()
let sprite = new PIXI.Sprite(), tmp = new PIXI.Sprite();
//some manipulations with these sprites
app.ticker.add((delta_) => {
...
updateTexture(w, h); //width is dynamic value
...
})
Here is updateTexture() function
function updateTexture(w_, h_){
let renderTexture = PIXI.RenderTexture.create({ width: w_, height: h_});
tmp.texture = sprite.texture;
app.renderer.render(tmp, renderTexture);
app.renderer.clear();
placeholder_.texture = renderTexture;
placeholder_.texture.update();
}
And it seems that let renderTexture = PIXI.RenderTexture.create({ width: w_, height: h_}); creates a new instance in memory dumping it every time up to browser crash.
app.renderer.clear() doesn't helps.
Any ideas for PixiJS version 6.5.5?

nativescript marshalling error

I seem to be getting a strange problem when marshaling the following native iOS code to nativescript:
CGRect keyboardRect = CGRectMake(0, 0, self.view.frame.size.width, 216);
AGEmojiKeyboardView *emojiKeyboardView = [[AGEmojiKeyboardView alloc] initWithFrame:keyboardRect
dataSource:self];
emojiKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
emojiKeyboardView.delegate = self;
self.textView.inputView = emojiKeyboardView;
The equivalent I came up with is the following:
var keyboardRect = CGRectMake(0, 0, platform.screen.mainScreen.widthPixels, 216);
var emojiKeyboardView = new AGEmojiKeyboardView();
emojiKeyboardView.frame = keyboardRect;
emojiKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
emojiKeyboardView.delegate = this;
views.textInput.ios.inputView = emojiKeyboardView;
where platform is just require("platform"); and views.textInput is a view to which I need to set the inputView to AGEmojiKeyboardView.
I really don't understand where I went wrong. All that appears is a grey keyboard with no content.
EDIT:
I changed the js code to the following:
var keyboardRect = CGRectMake(0, 0, uiView.view.frame.size.width, 216);
var emojiKeyboardView = new AGEmojiKeyboardView(keyboardRect, uiView);
emojiKeyboardView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
emojiKeyboardView.delegate = uiView;
views.textInput.ios.inputView = emojiKeyboardView;
where uiView is just page.ios and something seems to happen now, but still not the intended result. An exception is thrown, namely the following: -[UIViewControllerImpl emojiKeyboardView:imageForSelectedCategory:]: unrecognized selector sent to instance 0x7e6bff60
As NativeScript has TypeScript as first-class member somethings are really easier to do with TS. For example you can also use the META-Generator
Simply run this two lines to generate metadata & typings for your CocoaPod (and all other Objective-C files) and you won't have to worry about the right syntax.(still you will need to know the basic rules)
TNS_DEBUG_METADATA_PATH="$(pwd)/metadata" tns build ios [--for-device] [--release]
TNS_TYPESCRIPT_DECLARATIONS_PATH="$(pwd)/typings" tns build ios [--for-device] [--release]
Also if you want to createa a custom view the best variant is using NativeScript placeholder with creatingView
As for the syntax it shouldb look similar to this but still you will have to create your own ViewController and as the author says - conform to AGEmojiKeyboardViewDataSource and AGEmojiKeyboardViewDelegate protocol.
var frame = require('ui/frame');
var page;
function onLoaded(args) {
page = args.object;
}
exports.onLoaded = onLoaded;
function onCreatingView(args) {
setTimeout(function() {
var uiView = page.ios.view; // replace with own UIView and conform to AGEmojiKeyboardViewDataSource and AGEmojiKeyboardViewDelegate protocol.
var frame = {origin: {x:0, y:0}, size: {width: uiView.frame.size.width, height:600}};
var emojiView = AGEmojiKeyboardView.alloc().initWithFrameDataSource(frame, uiView);
emojiView.autoresizingMask = UIView.UIViewAutoresizing.UIViewAutoresizingFlexibleHeight;
emojiView.delegate = uiView;
var textContainer = NSTextContainer.alloc().initWithSize({width: 80, height: 180});
var frame = {origin: {x:0, y:0}, size: {width: 100, height:220}};
var textView = UITextView.alloc().initWithFrameTextContainer(frame, textContainer);
textView.inputView = emojiView;
args.view = textView;
}, 500);
}
exports.onCreatingView = onCreatingView;
page.xml
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="onLoaded">
<StackLayout>
<Placeholder creatingView="onCreatingView" id="placeholder-view"/>
</StackLayout>
</Page>
I could be mistaken, but I don't think you are using marshalling properly.
The documentation states:
AGEmojiKeyboardView *emojiKeyboardView = [[AGEmojiKeyboardView alloc] initWithFrame:keyboardRect dataSource:self];
So your {N} version should be something like this:
var emojiKeyboardView = AGEmojiKeyboardView.alloc().initWithFrameDataSource(keyboardRect, uiView);
This is a great blog-post on how to create plugins based on 3rd party libraries for nativescript. It also explains step-by-step how this type of marshalling is done.
http://fluentreports.com/blog/?p=167

Using variables in CGRectMake, Swift, UIkit

For an App I'm making i need to use variables to change the size and position of objects (Labels). I've tried var example = CGRectMake(0, 0, 0, 100), hoping it would ignore the zeros (Not really thinking it would though). I then tried:
var example = 100
Label1.frame = CGRectMake(20, 20, 50, example)
I changed the syntax a bit, adding "" and replacing the CGRectMake with CGRect etc, but nothing worked... I don't get what I'm doing wrong here... Help!
Below is the new syntax used since Swift 3.
CGRect(x: 0, y: 0, width: 100, height: 100)
CGRectMake takes CGFloats for all of its arguments. Your sample code should work fine if you specify that example is supposed to be a CGFloat, using a type identifier:
// v~~~~ add this...
var example: CGFloat = 100
Label1.frame = CGRectMake(20, 20, 50, example)
Otherwise, swift infers the type of example to be Int, and the call to CGRectMake fails, cuz it can't take an Int as a parameter...
So, there is many ways to skin the cat. It all depends what your needs and requirements are (maybe you could elaborate a bit on what you are trying to achieve?). But one way to do it could be to set a variable when something happens, and then update the frame of the label. If you added a tap gesture recognizer to your view, and updated your label like so:
let myLabel = UILabel()
override func viewDidLoad() {
super.viewDidLoad()
let tapGestRecog = UITapGestureRecognizer(target: self, action: "handleTap:")
self.view.addGestureRecognizer(tapGestRecog)
}
func handleTap(sender:UIGestureRecognizer) {
let newXposition = sender.locationInView(self.view).x
let newYposition = sender.locationInView(self.view).y
myLabel.frame = CGRectMake(newXposition, newYposition, 200, 200)
}
This is just an example, and a very crude way of doing it. There are many other ways of doing it, but it hopefully gives you an idea of how to achieve it.
Swift allows syntax that Objective-C does not:
var example = 100
label.frame.size.height = example
In objective-C you would have to do it differently:
CGRect frame = label.frame; //Create a temporary rect to hold the frame value
frame.size.height = example;
label.frame = frame;

UISlider not updating to bound ViewModel Property

I've got a UISeekbar and a UILabel located inside an MvxView
_currentPositionText = new UILabel { TextColor = UIColor.White };
_seekBar = new UISlider
{
MinValue = 0,
Continuous = true,
AutoresizingMask = UIViewAutoresizing.FlexibleWidth
};
_seekBar.TouchDown += OnTouchDown;
_seekBar.TouchUpInside += OnTouchUpInside;
_seekBar.TouchDragInside += OnDragInside;
I'm setting the binds as follows
set.Bind(_seekBar).For(sb => sb.Value).To(vm => _viewModel.CurrentPositionMsec);
set.Bind(_seekBar).For(sb => sb.MaxValue).To(vm => _viewModel.DurationMsec);
set.Bind(_currentPositionText).To(vm => vm.CurrentPositionText);
If I add some trace code inside the get of the CurrentPositionMsec, I can see the property updating once per second (as expected).
note: That same method also updates the CurrentPositionText by simply formatting the milliseconds into a TimeSpan.
The binding for the _currentPositionText is updating as expected, but the _seekBar doesn't update the slider position.
The expected result is for the slider to update once per second based on the CurrentPositionMsec.
I have this working in Android with the following binding, and both Android and iOS are sharing the same viewModel.
<SeekBar
android:Foo=""
android:Bar=""
local:MvxBind="Max DurationMsec; Progress CurrentPositionMsec" />
Am I not setting something up right? This "should" work AFAIK.
Reordering the bindings does not appear to yield any better results
// binding MaxValue first doesn't fix (lambda)
set.Bind(_seekBar).For(sb => sb.MaxValue).To(vm => _viewModel.DurationMsec);
set.Bind(_seekBar).For(sb => sb.Value).To(vm => _viewModel.CurrentPositionMsec);
Changing the binding to use a string rather than a lambda DID prove to solve the issue.
// using a string did enable the bindings to work as expected.
set.Bind(_seekBar).For("MaxValue").To(vm => _viewModel.DurationMsec);
set.Bind(_seekBar).For("Value").To(vm => _viewModel.CurrentPositionMsec);
We have now chosen to use strings as a standard in our code base. It does leave room for mistakes since we don't get compile time errors, but at least it ensures the bindings work.
I added a second SeekBar to the SeekView sample in https://github.com/MvvmCross/MvvmCross-Tutorials/tree/master/ApiExamples
This code seemed to work well:
public override void ViewDidLoad()
{
base.ViewDidLoad();
var label = new UILabel(new RectangleF(10, 100, 100, 30));
label.Text = "Slide me:";
Add(label);
var seek = new UISlider(new RectangleF(110, 100, 200, 30));
seek.MinValue = 0;
seek.MaxValue = 100;
Add(seek);
var seek2 = new UISlider(new RectangleF(110, 160, 200, 30));
seek2.MinValue = 0;
seek2.MaxValue = 100;
Add(seek2);
var mirrorLabel = new UILabel(new RectangleF(110, 130, 200, 30));
mirrorLabel.TextColor = UIColor.Blue;
Add(mirrorLabel);
var set = this.CreateBindingSet<SeekView, SeekViewModel>();
set.Bind(seek).To(vm => vm.SeekProperty);
set.Bind(seek2).To(vm => vm.SeekProperty);
set.Bind(mirrorLabel).To(vm => vm.SeekProperty);
set.Apply();
}
Obviously this only exercises the current value and not the maximum - but hopefully getting this working will help.
My only suggestion might be to try reordering your bindings - so that MaxValue is set before Value is. Or perhaps try using a fixed MaxValue and then using a value converter (or other mechanism) to scale the current value.

Make dynamically loaded images ease in and out using actionscript

I have 4 buttons and 4 images when I click a button a different image appears. I want the images to ease in and out after each button click. I have tried the code below but can't seem to figure it out.
home_btn.addEventListener(MouseEvent.CLICK, homeClick);
function homeClick(e:MouseEvent):void{
backgroundimg.source = "images/bluebg.jpg";
var bluebgTween:Tween = new Tween(backgroundimg, "alpha", Strong.easeIn, 1, 0, 3, true);
}
If fading in then fading out, set the initial alpha of backgroundimg to 0.
backgroundimg.alpha = 0;
You can then fade in on the CLICK event. Note that I've swapped the begin and finish values for the Tween.
Once the tween has finished, the yoyo() method can then be used to fade out again.
home_btn.addEventListener(MouseEvent.CLICK, homeClick);
function homeClick(e:MouseEvent):void{
backgroundimg.source = "images/bluebg.jpg";
var bluebgTween:Tween = new Tween(backgroundimg, "alpha", Strong.easeIn, 0, 1, 3, true);
bluebgTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
function onFinish(te:TweenEvent):void {
bluebgTween.yoyo();
bluebgTween.removeEventListener(TweenEvent.MOTION_FINISH, onFinish);
}
}
I used these sites as a reference for this:
http://www.republicofcode.com/tutorials/flash/as3tweenclass/
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/transitions/Tween.html

Resources