What is the "hasOwnProperty()" equivalent for interface?
I have found this related bug at Adobe: https://bugs.adobe.com/jira/browse/FB-27683
Any workaround except try..catch statement?
Have you considered this?
if("foo" in bar){ ...
where "foo" is the name of a property and bar is the object reference as Interface?
Here it is in action in a real world scenario:
import flash.events.IEventDispatcher;
import flash.events.EventDispatcher;
var i:IEventDispatcher = new EventDispatcher();
if("dispatchEvent" in i){
trace(" I have dispatchEvent");
}
The other answer is better, but you can also use
i['hasOwnProperty']('dispatchEvent')
Related
there are few functions I want to use across the testing integrations in cypress.io is there a way to export / import the functions so I don't have to copy and paste the functions into each integration?
Thanks in advance for any advice
This might be useful for you.
https://docs.cypress.io/api/cypress-api/custom-commands.html#
You can define custom cypress commands and use them in your tests. ie cypress.login, cypress.clickHamburger, cypress.doSomethingCrazy
Yes. You can do it as you would do it in usual js code.
myFunction.js
export function funcName(param) {
return "Cypress is "+param;
}
myCypressTest.js
import { funcName } from "./myFunction.js";
funcName("great");
Yes, you can use import in your spec file.
For example, if you want to import a function add() from a Model.js, you can do something like:
import Model from '../../Model';
var model = new Model();
And call model.add() from your expect.
I thought it was going to be easy but can anyone tell me how I can test HashMap to see if it has some value in JUnit?
assertThat(myMap, ??);
I tried something like:
assertThat(myMap, hasEntry("Key", notNullValue()));
...But I couldn't make it compile since my import to hasEntry and notNullValue() is correct.
Does anyone know what the correct import pkg for them should be?
You're after hasEntry(Matcher<? super K> keyMatcher, Matcher<? super V> valueMatcher).
The underlying implementation is in IsMapContaining but,
like most matchers in Hamcrest, it can also be found through org.hamcrest.Matchers, in hamcrest-library.
Otherwise, your syntax is correct, and Matchers also defines notNullValue().
import static org.junit.Assert.AssertTrue;
assertTrue(myMap.containsKey("yourKey") && myMap.get("yourKey") != null)
To check the key is in the map:
import static org.junit.Assert.assertTrue;
...
assertTrue(myMap.containsKey("Key"));
Alternatively, to check it has a non-null value:
import static org.junit.Assert.assertNotNull;
...
assertNotNull(myMap.get("Key"));
I don't like the assertTrue approaches, because the feedback is quite limited when the assertion fails.
It can be done with assertThat like this:
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
assertThat(myMap, hasEntry(is("Key"), notNullValue()));
I was following an adobe tutorial in which we make a text field and the text i update in it is from function sayHello()
import flash.display.MovieClip
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.SimpleButton;
import flash.events.MouseEvent;
import flash.events.TextEvent;
import flash.text.TextField;
var myGreeter:Greeter = new Greeter();
mainText.text = myGreeter.sayHello("Bob");
This is written in first frame^^^^^
SayHello function is in the other actionscript file in same folder with the following code
package
{
import flash.display.MovieClip;
public class Greeter
{
public function sayHello():String
{
var greeting:String;
greeting = "Hello World!";
return greeting;
}
}
}
Maybe some would ask that did you put a TextField on the stage and give it an instance name and the answer is yes i did.
The tutorial i followed i don't know why after telling code told us correct errors if there are in it so there is a possibility that they wanted to train us maybe.
i am a little confuse with greeter class myself as why we write
sayHello("Bob")
Why not
sayHello()
i say this because the variable only has string hellow world what it has to with that man Bob
It would be kind of you if you can also explain me that,
I am asking this too becuase i also need to have complete understanding of code.
I'm not sure, but you may have conflated two steps in the tutorial. You're right that with your definition of sayHello, you should call
sayHello();
To have the function take an argument, you need to define the function to take an argument:
public function sayHello(user:String):String {
return "Hello, " + user + "!";
}
You would then call:
sayHello('Hamza');
and it would return
"Hello, Hamza!"
In short words: "The tutorial is wrong or it is incomplete". You call sayHello with one param but sayHello are declared without params. And the compiler give you right error for this call.
for example is it possible to do somehing like public var socket:flash.net.Socket = new flash.net.Socket();?
No you will still get a class undefined compiler error if you don't import flash.net.Socket
I have the following packages:
spark
spark.engine
Within spark I have a class SeCore; and within spark.engine I have SeStepper and SeKeyboard.
What I'm trying to achieve is have SeCore as being the only class that can create an instance of SeStepper or SeKeyboard. This can be achieved by moving SeCore into the spark.engine package and making the other two classes internal, but I'd like to have SeCore in the spark package if possible.
I've tried making my own namespace to handle this, like so:
package spark.engine
{
import spark.namespaces.spark_core;
use namespace spark_core;
spark_core class SeStepper extends SeObject
{
//
}
}
However I get the error:
1116: A user-defined namespace attribute can only be used at the top
level of a class definition.
Are there any other approaches I can take to achieve what I'm after?
99% of the time, marking anything as 'internal' is a bad idea. It's better to have a naming convention for 'off-limits' classes and members, and allow developers to go there at their own risk. Marking things as 'internal' or 'private' is something that should only be done rarely, and with great forethought.
However, you could enforce this behavior at run time by using a read-only property in SeCore and checking its value from SeStepper and SeKeyboard.
Following is pseudocode, haven't used AS3 in a while.
In SeCore
private var _createAuthorized = false;
public function get CreateAuthorized():boolean {return _createAuthorized;}
private function createSeStepper(){
_createAuthorized = true;
var obj = new SeStepper(this)
_createAuthorized = false;
return obj;
}
in SeStepper
public function SeStepper(core:SeCore){
if (!core.CreateAuthorized) throw new Error("Only SeCore can do this");
}
I can't agree with the answer, i mean making things public is way to invite hackers. I can execute any public functions in any flash running on my computer in any context i want, i can even override their execution in memory since they are easy to find, whereas doing something like that with private/internal functions is almost impossible.