close

Filter

loading table of contents...

CoreMedia Content Cloud v11 Upgrade Guide / Version 2110

Table Of Contents
7.3.1.6.2.2 Creating Ext Config Objects in ActionScript

Ext often uses the concept of creating Config objects first, and instantiating them later. To be able to do so, a Config object must contain an property that indicates which class to instantiate (later). The three different special Ext properties available to specify the target class are:

  • xtype — the "classic" class hint. Each Ext class may specify a unique xtype, which is registered and referenced here to identify the class to instantiate. This indirection is meant to separate usage and implementation (a bit).

  • alias — When Ext extended their Config System to more than just components, they though it would make sense to introduce prefixes for the different groups of classes. Components use widget. <xtype>, plugins use plugin.<type>, GridColumns use gridcolumn.<type>. The type property used for that purpose before introducing alias has been deprecated.

  • xclass — Introduced last, this is the most straight-forward way to specify the target class: Just give its fully-qualified name! Unfortunately, this property does not work everywhere in Ext's Classic Toolkit (the one CoreMedia Studio uses), so if a class has an xtype / alias, you should better use that, or even better, all possible meta-properties the class offers.

That said, in ActionScript, you need not worry about all that. We introduced special semantics to ActionScript type casts when using them on object literals. (This is quite some cheating, too.) To create a Config object for a class MyClass , instead of calling its constructor, you type-cast an object code into that class:

var myClassConfig: MyClass = MyClass({
  id: "4711",  // inherited from Component._
  configOption1: "bar",  // MyClass Config property
  configOption2: 42  // the other MyClass Config property
});
  

Example 7.8.  Type-cast object code into class


This adds the appropriate xtype, alias , and/or xclass attributes.

However, in ActionScript, there is no way to type object literals. They are always of type Object and any properties are allowed. That's why you should use the following pattern to populate a Config object in ActionScript:

var myClassConfig = MyClass({});
myClassConfig.id = "4711";
myClassConfig.configOption1 = "bar";
myClassConfig.configOption2 = 42;

Example 7.9.  Populate Config object in ActionScript


While this adds a bit more code, you now have type checks and gain IDE support like completion, documentation lookup and navigation.

If needed, you can then use different ways to instantiate the corresponding class:

var myClassInstance: MyClass = new MyClass(myClassConfig);
// OR
var myClassInstance: MyClass = Ext.create(myClassConfig); // careful: no type check!
// OR
var myClassInstance: MyClass = MyClass(Ext.create(myClassConfig)); // at least a run-time type check

Example 7.10.  Different ways to instantiate class


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.