where to add a global function in coldbox to call in a view - coldbox

Where in coldbox would you add a function that would be visible in your view thats global
for instance, i want to create a function that replaces spaces with hyphens for a URL
public string function makeUrl(url) {
replace bit here
return URL;
}
where would you store this?

Related

How to let the UI update automatically after a variable is updated in Dart (Not Flutter)?

Here is my code:
import 'package:dart_console/dart_console.dart';
class Init extends ConsoleViewModel {
String title;
//Console
Console console;
Init(Console aConsole) {
console = aConsole;
this.redraw();
}
redraw() {
console.clearScreen();
console.setBackgroundColor(ConsoleColor.blue);
console.setForegroundColor(ConsoleColor.white);
console.writeLine(title, TextAlignment.center);
console.resetColorAttributes();
console.writeLine();
}
}
I can change the title, and call redraw all the time, but is this possible to let it call redraw automatically instead of call it manually? Thanks.
I think you need a Function, and you call it manually when the value of the variable changed
Function onChange = Function ();
But I don’t know where to use it
You can also benefit from this:
PublishSubject

Getter for object property needs to return UnsafeMutablePointer<T>?

I'm working in Swift and one of the protocols I'm using needs to return an UnsafeMutablePointer<T> of a particular object.
I have something like this:
#objc var myProperty:UnsafeMutablePointer<someObject>
{
get
{
// I call a class function here to get a 'someObject'
// return object which I need to pass back a pointer to it.
return UnsafeMutablePointer<someObject>
}
}
The problem is that Xcode doesn't like this. It complains that '>' is not a unary operator.
I've also tried removing the UnsafeMutablePointer<> and use an & in front of someObject but it complains that the & is to be used immediately in a list of arguments for a function.
I suppose I just can't find the right syntax for this? Any help would be appreciated.
If someObject has the type SomeClass, then you need to update your declaration like this:
#objc var myProperty:UnsafeMutablePointer<SomeClass>
{
get
{
return UnsafeMutablePointer<SomeClass>(unsafeAddressOf(someObject))
}
}
The generic argument needs to be the type of the returned data, and you also need to intialize a specialized UnsafeMutablePointer with the memory address of the desired object.

Declaring function usable throughout project

I am new to swift and I am trying to figure out how to add a function that could be usable throughout the entire project. A simple function like
func globalFunction() {
println("Global function!")
}
Then be able to call this function on any swift file within my project. Where would I declare this function?
Its just like in any programming language - declaring the function outside the class, something like:
class A
{
var a:Int
// you can call your global function here
}
class B
{
var b:Int
// and here
}
func flobalFunction()
{
println("Hello, I am a global function!")
}
Use static functions if you still want to bind the method to a class:
class myClass{
static func globalFunc() -> Void {
println("This is it")
}
}
myClass.globalFunc()
You can add a .swift file in your project and declare your functions. Functions declared in this file will be available in the same module.
By default, variables, constants, and other named declarations that
are declared at the top-level of a source file are accessible to code
in every source file that is part of the same module.
Taken from The Swift programming language, see section on Top-Level Code.
If it is a helper function, you can create a new Swift file, and place the function in it else place it in any class as:
Class HelperFunctionsClass() {
func anyFunction () {
//Your implementation of the function here
}
}
To use this, create an instance of the class in the place you would like to use it as:
var instanceOfHelperFunctionClass = HelperFunctionClass()
Now simply use this instance variable to use the function as:
insttanceOfHelperFunctionClass.anyFunction()

Actionscript 2 Proper way to define function on MovieClip

I'm trying to write a function on a MovieClip, and call it from the root clip. What works fine in ActionScript 3 doesn't seem to be working properly in ActionScript 2.
Frame 1 of the _root MovieClip:
var newMovieClip:MovieClip = _root.attachMovie('Notification', id, 0);
newMovieClip.SetNotificationText("Test text");
Frame 1 of the Notification MovieClip:
function SetNotificationText(inputText : String){
notificationText.text = inputText;
}
The result is that the MovieClip is created but the text is not changed.
Am I doing this wrong?
To add functions to a MovieClip in AS2, you need to use one of these methods:
Add the method to the prototype of MovieClip:
MovieClip.prototype.SetNotificationText = function(inputText:String):Void
{
if(this["notificationText"] !== undefined)
{
// If we're going to use the prototype, at least do some checks
// to make sure the caller MovieClip has the text field we expect.
this.notificationText.text = inputText;
}
}
newMovieClip.SetNotificationText("Test text");
Make the MovieClip and argument of the function:
function SetNotificationText(mc:MovieClip, inputText:String):Void
{
mc.notificationText.text = inputText;
}
SetNotificationText(newMovieClip, "Test text");
Add the method directly to the newly created MovieClip:
var newMovieClip:MovieClip = _root.attachMovie('Notification', id, 0);
newMovieClip.SetNotificationText(inputText:String):Void
{
notificationText.text = inputText;
}
newMovieClip.SetNotificationText("Test text");
Option 2 is best overall - it's the cleanest and avoids overhead of creating a new function for every new MovieClip. It also avoids messing around with the prototype, which at best should be used to add generic methods, like a removeItem() method on Array.

Passing Parent Element to Method from MarkupBuilder

I have a custom taglib in Grails and I am using MarkupBuilder to help drive some dynamic forms. I need to pull some of this form creation code out into their own classes/methods so they can be reused and I'd like to be able to use MarkupBuilder inside these other classes/methods. So I have something like...
def formContainer = new MarkupBuilder(out)
formContainer.form(...) {
table() {
tr() {
td() {
// here I want to call a method and pass a reference to td()
generateSomeFormData(this) // but this doesn't work.
}
}
}
}
In the td(), I want to call a method but I need to pass it a reference to td. 'this' doesn't seem to reference that element.
My other method might look something like (very generic to get the point across)
generateSomeFormData(parentElement) {
parentElement.input(type:'text')
}
I believe
generateSomeFormData( delegate )
should work

Resources