I'm trying to update a small Flex AS3 "project" consisting of one main file and an imported AS3 class. Unfortunately during compile I get the error 1120:Access of undefined property DEBUG. and the compilation fails. I've used mxmlc from Flex SDK 4.6 and Flash Builder 4.5 and get the same failure.
Flex isn't my strong suit so I hope someone can point out the error. From what I understand this source code compiled fine in 2011 using mxmlc.
Relevant code from the imported file:
package {
public class krpano_as3_interface {
public static var instance:krpano_as3_interface = null;
.
.
static public const STARTDEBUGMODE : int = 0xFF;
static public const DEBUG : int = 0;
And From the main AS3 file:
package {
.
import krpano_as3_interface;
public class soundinterface extends Sprite {
static public var krpano : krpano_as3_interface = null;
.
public function soundinterface() {
if (stage == null){
}else{
txt.htmlText = "krpano " + DEBUG::version + "\n\n" +
"<b>soundinterface plugin</b>" +
"\n\n(build " + DEBUG::builddate + ")";
}
}
If I rename or move the imported file the compiler complains that it is missing. The class where the constant DEBUG is defined should be being imported so why isn't it working?
The class where the constant DEBUG is defined should be being imported so why isn't it working?
Because they have nothing to do with each other.
DEBUG::version
and
static public const DEBUG : int = 0;
Are two unrelated parts of your code.
There are two hints in the syntax:
the :: name qualifier operator stands after a namespace, so whatever DEBUG is, it is a namespace, which the public static const is not (it's an int)
A property version is accessed. The public static const does not
have such a property.
What you are looking at is conditional compilation, which (among other things) allows you to specify values and pass them to the compiler to perform the compilation process.
You can also pass Strings and Numbers to the application and use them as inline constants
In your case, you want to define a version constant in the compiler arguments. Something like this:
-define+=DEBUG::version,"5"
This is probably because the version number is maintained by some build script (make, ant, whatever) and therefore passes this information to the compiler.
I highly recommend that you get in contact with the developer who worked on this project before to understand how the build process of this project is supposed to work.
Related
I am trying to create a class (working as factory class) in my Zend Expressive APP as follows:
declare(strict_types=1);
namespace App\Install\Factory;
use App\Install\Model as Models;
use App\Install\Abstracts\AttributeInterface;
class AttributeEntityFactory{
public static function create($type1 ='Attribute') : AttributeInterface
{
$resolvedClass = "Models\\$type1";
$resolvedClass1 = 'Models\\'.$type1;
//return new $resolvedClass();
//return new $resolvedClass1();
return new Models\Attribute();
}
}
The above code works perfectly for me. However, if try to use any of the other two return statements it shows
Class 'Models\Attribute' not found
How can I achieve dynamic instantiation?
The attribute class code is as follows:
namespace App\Install\Model;
use App\Install\Abstracts\AttributeInterface;
class Attribute implements AttributeInterface
{
protected $attribute;
public function setAttribute($attribute)
{
$this->attribute = $attribute;
}
public function getAttribute()
{
return $this->attribute;
}
}
My PHP version is:
PHP 7.2.13 (cli) (built: Dec 14 2018 04:20:16) ( NTS )
you may need to pass in the full namespace?
"App\Install\Model\" . $type1;
and more...
the model Attribute you have is in the namespace App\Install\Model, and the object you are trying to create is from Models\\ . $type1
maybe you need to change Models to Model
Personally, I would avoid such factory implementation because of several reasons:
It involves magic.
Less predictable code.
Harder to read for both humans and IDE's (E.g: PHPStorm would not find the usages of Attribute class in such code when you need to find it)
Harder to analyze using static analyzers
Instead, I would rewrite this to a more explicit factory, even if I had dozens of different classes in App\Install\Model namespace:
<?php declare(strict_types=1);
namespace App\Install\Factory;
use App\Install\Model as Models;
class AttributeEntityFactory
{
public static function create($type = 'Attribute') : AttributeInterface
{
switch ($type) {
case 'Attribute':
return new Models\Attribute();
case 'SomethingElse':
return new Models\SomethingElse();
default:
throw new \InvalidArgumentException(
sprintf('An unknown type %s requested from %s', $type, __METHOD__)
);
}
}
}
As a rule of thumb:
Never compose classnames / namespaces using strings concatenated with variables / parameters / constants whatever.
Never call methods in such way, too.
You'll thank me when your application/business/codebase grows enough.
Is there a way to call internal method with native parameter from ref class in another C++/CX WinRT component? I know there is solution via pointers exposed as int, but is there any better way? Something like to include header files from other lib and not using managed reference (this way I got error message from C# Component3 "error CS0433: The type 'Class1' exists in both 'Component1' and 'Component2'" in other component that consumes these both)...
Component1/class1.h:
public ref class Class1 sealed
{
internal:
bool InternalMethodForComponent2(NativeType& param1);
public:
Class1();
virtual ~Class1();
int SomeMethodForComponent3();
private:
};
Component2/class2.cpp:
//#include "Component1/class1.h" - replaced by adding reference because of CS0433 in Component3
void Class2::SomeMethod(Class1^ obj)
{
NativeType nt;
nt.start = 1;
...
obj->InternalMethodForComponent2(nt); //does not work - error C2039: 'InternalMethodForComponent2' : is not a member of 'Component1::Class1'
}
Component3/class3.cs:
void MethodInClass3()
{
Class1 obj1 = new Class1();
Class2 obj2 = new Class2();
obj2.SomeMethod(obj1);
var res = obj1.SomeMethodForComponent3();
}
The correct way is to include the header Class1.h when defining Class2; by adding a reference to the WinMD (metadata) the compiler only knows about the public members. Adding the header allows the compiler to see the true C++ type, including the internal members.
The error you got when you included the header is hard to understand without a complete example of your code, although my best guess is that you had two namespaces and the reference to Class1 was ambiguous. For a start, you could just put Class1 and Class2 in the same .h/.cpp files to simplify things and avoid the external header reference altogether.
I am designing a simple game in Flash and have come across this error. I have no idea how to go about this in actionscript and would appreciate any help.
Basically, I have a switch statement which creates an object of different type depending on each case (as I would prefer not to duplicate the same ten lines of code for each case) and I am getting a "conflict exists with definition in namespace internal" compiler error and I think I understand why.
switch(power){
case 1:
var Pow:objectOne = new objectOne();
break;
case 2:
var Pow:objectTwo = new objectTwo();
break;
}
My question however is this - what is the proper way of going about this?
I initially thought of declaring the variable before the switch statement which results in an "implicit coercion of a value of type object(One/Two) to an unrelated type Class" error. What am I missing here?
Aside from the compiler error you are experiencing, another problem here is that you are planning on using the pow variable later in your code, yet they are of different types. My suggestion is to use the benefits of Inheritance in OOP and create a base class that your two custom classes can inherit from. That way they are both technically of the same base type, while still giving you the freedom to customize each custom class, while keeping similar functionality in the base class.
Remember, OOP is here to always help you and is there to avoid issues like the one you have come across, but here is how I would do it, and I tested the following implementation in Flash CC 2014 and it compiled successfully:
Example .FLA:
var pow:BaseClass;
var power = 1;
switch(power){
case 1:
pow = new ObjectOne();
break;
case 2:
pow = new ObjectTwo();
break;
}
pow.whichObjectAmI(); // this will simply trace what object pow is
Base Class
package {
public class BaseClass {
public function BaseClass() {
// constructor code
}
public function whichObjectAmI() {
trace("I am the base class");
}
}
}
Object One
package {
public class ObjectOne extends BaseClass {
public function ObjectOne() {
// constructor code
}
override public function whichObjectAmI() {
trace("I am Object One!");
}
}
}
Object Two
package {
public class ObjectTwo extends BaseClass {
public function ObjectTwo() {
// constructor code
}
override public function whichObjectAmI() {
trace("I am Object Two!");
}
}
}
You can always inherit from any of ActionScript's classes as well like MovieClip, Button, etc. And by doing so, you're adding custom functionality on top of their functionality so 1) you don't have to rebuild a bunch of functionality, and 2) giving you the chance to reuse their functionality while adding your own custom code!
Disclaimer: My AS3 is a little rusty ;)
Of what type would the variable Pow be after the switch statement? objectOne or objectTwo? From the compiler's perspective objectOne and objectTwo could be totally different from each other (read: methods, fields,...)
So:
A) Keep variable name for both assignments but declare it before the switch-statement AND use a common base-type (object, MovieClip,...)
B) Have 2 different variables: var PowOne: objectOne and var PowTwo: objectTwo
I think option A would be preferable...
I have a XAML + DirectX app and I want to add static field to my "interop" class:
[Windows::Foundation::Metadata::WebHostHidden]
public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler
{
public:
static int VALUE = 0;
...
};
It does not compile saying "only static const integral data members can be initialized within a class".
If I change it to const static int VALUE = 0; then it still does not compile with error "a non-value type cannot have any public data members"
What am I doing wrong?
WinRT public classes have a number of limitations to ensure they are consumable by multiple languages including C++, JavaScript, and C#. This is why you are getting error C3984. You can't have public fields and instead must use properties. You'd make it a read-only property:
property int VALUE
{
int get() { return 0; }
}
It is important to remember that properties are function calls and can't usually be optimized away, so you should consider that when designing the interfaces.
If you intend to have this class only consumable by C++, consider not using a WinRT class and instead use a simple C++ class which you managed the lifetime using std::unique_ptr or std::shared_ptr. In that case, you can of course use the public field approach as always.
The original problem you got is a general C++ language restriction not specific to WinRT. Error C2864 (you are using VS 2012 from the text you posted) is a little more general with C++11 in VS2013.
I am converting Android 4.x code to use ActionBarSherlock so that our App can be compatible with Gingerbread.
So far so good, but it fails launching a new instance of a fragment.
My MainActivity extends SherlockFragmentActivity implements ActionBar.TabListener.
The code fails here where case is 0:
#Override
public Fragment getItem(int position) {
switch (position) {
case 0:
mFragmentProjects = ProjectsFragment.newInstance(position);
return mFragmentProjects;
case 1:
mFragmentContacts = FragmentPeople.newInstance(position, 0);
return mFragmentContacts;
}
return ArrayListFragment.newInstance(position);
}
Where case is 0 it supposed to initialize the fragment but I get this exception:
ClassNotFoundException. The only other clue I have is:
"this" in PathClassLoader and in "name" it says android.app.ActionBar$TabListener
I guess this has something to do with TabListener or libraries not included / loading correctly? I have already cleaned the project.
The fragment ProjectsFragment extends SherlockListFragment.
newInstance is pretty straitforward:
static ProjectsFragment newInstance(int num) {
ProjectsFragment f = new ProjectsFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt("num", num);
f.setArguments(args);
return f;
}
It turns out that although MainActivity has no reference to ActivityY, the mere fact that ActivityY did not have the SherlockFragment code made it fail. To describe this differently:
MainActitivy uses ProjectsFragment which is a list
When you click on a list in ProjectsFragment it calls ListsActivity
ListsActivity references ItemsFragment
I had to change ItemsFragment to Sherlock code before MainActivity would work. It seems Java "looks ahead" in some way when you're working with pagers and tabs and fragments.