Can anyone explain to me why this failed and how to get it to work?
NOTE: This is ActionScript 2, so ActionScript 3 responses will probably not help.
For this example create a movieclip on the stage that has the label "test_mc".
Frame 1:
import mcClicker;
var test = new mcClicker(test_mc);
mcClicker.as:
class mcClicker{
public var obj;
private function objPress(){
trace(obj); //<--- This fails
}
public function mcClicker(the_obj){
obj = the_obj;
obj.onPress = objPress;
}
}
Related
The bounty expires in 2 days. Answers to this question are eligible for a +50 reputation bounty.
user10191234 wants to draw more attention to this question:
I am a beginner in the domain and really need a working example, hints are not enough.
I need to print a 2D QR code from a blazor server side app. I've used this post but PrintDialog is not working even after adding System.windows.Forms. Any idea on how to do it. My printer is GK420T connected to USB001.
First, add the following package to your Blazor server app project:
Zebra.Sdk.Printer
Next, create a new C# class called LabelPrinter with the following code:
using Zebra.Sdk.Comm;
using Zebra.Sdk.Printer;
using Zebra.Sdk.Printer.Discovery;
public class LabelPrinter
{
private Connection printerConnection;
private ZebraPrinter printer;
public LabelPrinter(string ipAddress)
{
printerConnection = new TcpConnection(ipAddress, TcpConnection.DEFAULT_ZPL_TCP_PORT);
printer = ZebraPrinterFactory.GetInstance(printerConnection);
}
public void PrintQRCode(string data, int x, int y, int size)
{
var qrCodeCommand = "^BQ,2,10^FDMA," + data + "^FS";
var qrCodeSizeCommand = "^BY" + size.ToString();
var qrCodePositionCommand = "^FO" + x.ToString() + "," + y.ToString();
var labelCommands = new StringBuilder();
labelCommands.AppendLine("^XA");
labelCommands.AppendLine(qrCodePositionCommand);
labelCommands.AppendLine(qrCodeCommand);
labelCommands.AppendLine(qrCodeSizeCommand);
labelCommands.AppendLine("^XZ");
printerConnection.Open();
if (printerConnection.Connected)
{
printerConnection.Write(labelCommands.ToString());
}
printerConnection.Close();
}
}
PrintQRCode method takes in the data to be encoded in the QR code, as well as the X and Y coordinates and size of the QR code.
The method creates the ZPL command for printing the QR code using the ^BQ command, and sets the data and size using the ^FD and ^BY parameters. It also sets the position of the QR code using the ^FO parameter.
Finally, the method constructs the full label commands using the StringBuilder class, and sends them to the printer over the network using the Write method.
Next, in your Blazor server app, create a new razor component called PrintLabel with the following code:
#page "/printlabel"
#inject NavigationManager NavigationManager
<h1>Print Label</h1>
<label for="label-content">Label Content:</label>
<textarea id="label-content" #bind="LabelContent"></textarea>
<button class="btn btn-primary" #onclick="PrintLabel">Print</button>
#code {
private string LabelContent { get; set; }
private async Task PrintLabel()
{
var printer = new LabelPrinter("192.168.0.100"); // Replace with your printer's IP address
printer.PrintQRCode(LabelContent, 100, 100, 10);
await NavigationManager.NavigateTo("/");
}
}
I've the following test code to figure out how variable binding works. So this is what I want to import/include;
# importee.groovy
import groovy.transform.Field
#Field top = 60
number = 44 // binding variable
int ratio = 4.5
return this
which I call it from;
# importer.groovy (version1)
import groovy.lang.GroovyClassLoader
def gcl = new GroovyClassLoader()
def clazz = gcl.parseClass(new File("importee.groovy")) )
assert clazz.name == 'importee'
def script = clazz.newInstance()
//script.run()
println("binding variable:
${script.getBinding().getVariable("number")}")
So, if I don't run the script, my test code throws "MissingPropertyException" on the last print statement. This is not happenning if I call def script = evaluate(new File("importee.groovy")) instead of using GroovyClassLoader like this;
# importer.groovy (version2)
def script = evaluate(new File("importee.groovy"))
println("binding/global variable: ${script.number}")
Since both methods return a Script instance, I got a little bit confused on why I have to call the run() method in the first case. Can someone explain where I fail to understand please?
Thanks
run groovyconsole (distributed with groovy)
type a simple script:
number=44
return this
select menu Script -> Inspect Ast
and in the new window Groovy AST Browser select phase = Conversion
you will see your groovy script but converted to a Script class like this:
public class script1548245785832 extends groovy.lang.Script {
public script1548245785832() {
}
public java.lang.Object run() {
number = 44
return this
}
}
this is the actual code generated for your script.
as you can see the constructor is empty, so no information about number property after you call newInstance()
but after you call run() you actually run your script.
your script could be a class like this:
class Importee {
int number=44
public Object run(){
println number
}
}
in this case it will be enough to create instance of class without calling run() method and get the value of number variable...
def clazz = gcl.parseClass( new File("Importee.groovy")) )
def script = clazz.newInstance()
println("the variable: ${script.number}")
Version Akka.NET v1.3.8
Version Akka.TestKit.NUnit3 v1.3.2
Version NUnit v3.10.1
Platform Windows 10
I have an actor of the following kind:
public class BranchUsersActor : ReceiveActor
{
public BranchUsersActor()
{
Receive<UserBeingOnline>((online) =>
{
var userActorName = $"user_{online.UserId}";
if (Context.Child(userActorName).Equals(ActorRefs.Nobody))
{
var user = Context.ActorOf(UserActor.Props(online.UserId, online.BranchId), userActorName);
user.Tell(online);
}
});
}
public static Props Props(LoggingTags tags)
{
return Akka.Actor.Props.Create(() => new BranchUsersActor(tags));
}
}
When testing this actor, I expect that I will have a child actor.
I'm writing the next test to check this situation (using the NUnit framework):
[Test]
public void Test()
{
var branchUserActor = Sys.ActorOf(BranchUsersActor.Props());
branchUserActor.Tell(UserBeingOnline.Create(userId, branchId));
var expectedChildActor = Sys.ActorSelection($"{actorPath}/user_{userId.AkkaPrepare()}")
.ResolveOne(TimeSpan.FromSeconds(1)).Result;
Assert.IsNotNull(expectedChildActor);
}
I expect that within a second I will receive the child actor on the specified path, but I get ActorNotFoundExpection.
If I'm doing something like this:
[Test]
public void Test()
{
var branchUserActor = Sys.ActorOf(BranchUsersActor.Props());
branchUserActor.Tell(UserBeingOnline.Create(userId, branchId));
Task.Delay(100).ContinueWith(_ =>
{
var expectedChildActor = Sys.ActorSelection($"{actorPath}/user_{userId.AkkaPrepare()}")`enter code here`
.ResolveOne(TimeSpan.FromSeconds(1)).Result;
}
Assert.IsNotNull(expectedChildActor);
}
This works fine, but 1 of 10 times the test falls, because I get an ActorNotFoundException.
But I wonder why the first option does not work the way I expect?
Am I doing something wrong?
Thanks in advance for the answer.
branchUserActor.Tell(UserBeingOnline.Create(userId, branchId));
var expectedChildActor = Sys.ActorSelection($"{actorPath}/user_{userId.AkkaPrepare()}")
.ResolveOne(TimeSpan.FromSeconds(1)).Result;
The problem here is that when you're telling UserBeingOnline, you're triggering an asynchronous action - a message has been send to branchUserActor, but it may not have been processed right away. In the meantime you're calling resolve one, which tells actor system to find a child of branchUserActor - a child, which is not yet there, since the parent didn't handle the message yet.
You can use AwaitAssert(() => Assert.IsNotNull(ResolveChild())) method to work with that.
I'm trying to sort a Documents Collection using a java.util.ArrayList.
var myarraylist:java.util.ArrayList = new java.util.ArrayList()
var doc:NotesDocument = docs.getFirstDocument();
while (doc != null) {
myarraylist.add(doc)
doc = docs.getNextDocument(doc);
}
The reason I'm trying with ArrayList and not with TreeMaps or HashMaps is because the field I need for sorting is not unique; which is a limitation for those two objects (I can't create my own key).
The problem I'm facing is calling CustomComparator:
Here how I'm trying to sort my arraylist:
java.util.Collections.sort(myarraylist, new CustomComparator());
Here my class:
import java.util.Comparator;
import lotus.notes.NotesException;
public class CustomComparator implements Comparator<lotus.notes.Document>{
public int compare(lotus.notes.Document doc1, lotus.notes.Document doc2) {
try {
System.out.println("Here");
System.out.println(doc1.getItemValueString("Form"));
return doc1.getItemValueString("Ranking").compareTo(doc2.getItemValueString("Ranking"));
} catch (NotesException e) {
e.printStackTrace();
}
return 0;
}
}
Error:
Script interpreter error, line=44, col=23: Error calling method
'sort(java.util.ArrayList, com.myjavacode.CustomComparator)' on java
class 'java.util.Collections'
Any help will be appreciated.
I tried to run your SSJS code in a try-catch block, printing the error in exception in catch block and I got the following message - java.lang.ClassCastException: lotus.domino.local.Document incompatible with lotus.notes.Document
I think you have got incorrect fully qualified class names of Document and NotesException. They should be lotus.domino.Document and lotus.domino.NotesException respectively.
Here the SSJS from RepeatControl:
var docs:NotesDocumentCollection = database.search(query, null, 0);
var myarraylist:java.util.ArrayList = new java.util.ArrayList()
var doc:NotesDocument = docs.getFirstDocument();
while (doc != null) {
myarraylist.add(doc)
doc = docs.getNextDocument(doc);
}
java.util.Collections.sort(myarraylist, new com.mycode.CustomComparator());
return myarraylist;
Here my class:
package com.mycode;
import java.util.Comparator;
public class CustomComparator implements Comparator<lotus.domino.Document>{
public int compare(lotus.domino.Document doc1, lotus.domino.Document doc2) {
try {
// Numeric comparison
Double num1 = doc1.getItemValueDouble("Ranking");
Double num2 = doc2.getItemValueDouble("Ranking");
return num1.compareTo(num2);
// String comparison
// return doc1.getItemValueString("Description").compareTo(doc2.getItemValueString("Description"));
} catch (lotus.domino.NotesException e) {
e.printStackTrace();
}
return 0;
}
}
Not that this answer is necessarily the best practice for you, but the last time I tried to do the same thing, I realized I could instead grab the documents as a NotesViewEntryCollection, via SSJS:
var col:NotesViewEntryCollection = database.getView("myView").getAllEntriesByKey(mtgUnidVal)
instead of a NotesDocumentCollection. I just ran through each entry, grabbed the UNIDs for those that met my criteria, added to a java.util.ArrayList(), then sent onward to its destination. I was already sorting the documents for display elsewhere, using a categorized column by parent UNID, so this is probably what I should have done first; still on leading edge of the XPages/Notes learning curve, so every day brings something new.
Again, if your collection is not equatable to a piece of a Notes View, sorry, but for those with an available simple approach, KISS. I remind myself frequently.
I have a Document class that loads variables from Facebook with the use of stage.loaderInfo
var connect:FacebookConnectObject = new FacebookConnectObject( facebook, API_KEY, this.stage.loaderInfo );
But when I change the Document class (with another one responsible for the layout of my app), and try call the above from a movieclip that exists in my application with the use:
var facebook_class:FacebookAp = new FaceBppkApp
addChild(facebook_class) I get error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
I believe the error comes fro this line
this.stage.loaderInfo
since I changed the scope...
How I am supposed to fix that?
According to a post by Devonair: Seems 99 times out of a 100 when people have a problem with a 1009 error, it's because the stage property is inaccessible.
so I used this snippet
public function start() {
if
{(stage) init();}
else
{ addEventListener(Event.ADDED_TO_STAGE, init);
}
}
private function init(event:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
// everything else...
}
In case sb has the same problem...