Using the "as" operator vs casting?

I've recently been reading the docs regarding data types in
AS3 and am still not clear on a few things. If anyone has blogged
on this, please point me there.
One problem is that "casting" syntax is the same as top-level
function syntax. Compare String(objString) to XML(event.result).
The latter is a top-level function, but the former is a "cast". Or
is it?
An option to the String cast is objString.toString(). What is
the difference? I am not so much interested in the underlying
details of the language, as in understanding when to use which.
The same question exists for the top-level function
XML(event.result), which can be done with the "as" operator:
event.result as XML. When to use which? Are there performance
issues? The "as operator" documentation is unsatisfying.
Any discussion of this will be appreciated.
Tracy

ActionScript 3.0 has the
as operator because it circumvents a deficiency with the
cast operation () in ActionScript. Consider this:
var a:Object = new Array(1,2,3,4);
var b:Array = Array(a);
What is b? It is an Array of 1 element: [ [1,2,3,4] ];
The
as operator takes care of this:
var b:Array = a as Array;
The actual difference in the operators is that if the
variable being cast is not of the proper type, the
as operator returns null while the () operator throws an
exception:
var j:Number = Number(a); // exception!
var k:Number = a as Number; // NaN in this case, but null
normally
The feeling here at Adobe is to use the
as operator since it is not ambiguous and just check for
null. If you prefer to catch exceptions and know when X(y) is a
cast vs a conversion, then use that. More of a preference but at
times only
as will do what you need.

Similar Messages

  • Cross-post: Using the "as" operator vs casting

    I'm cross posting this because it is technically an
    Actionscript question, but it has real Flex consequences.
    I've recently been reading the docs regarding data types in
    AS3 and am still not clear on a few things. If anyone has blogged
    on this, please point me there.
    One problem is that "casting" syntax is the same as top-level
    function syntax. Compare String(objString) to XML(event.result).
    The latter is a top-level function, but the former is a "cast". Or
    is it?
    An option to the String cast is objString.toString(). What is
    the difference? I am not so much interested in the underlying
    details of the language, as in understanding when to use which.
    The same question exists for the top-level function
    XML(event.result), which can be done with the "as" operator:
    event.result as XML. When to use which? Are there performance
    issues? The "as operator" documentation is unsatisfying.
    Any discussion of this will be appreciated.
    Tracy

    Maltus now I'm totally confused.
    The Flex manual in the TOP LEVEL section (Guess TOP LEVEL
    means that they don't belong to any package) clearly states this
    functions:
    Function Description
    Array Creates a new array.
    Boolean Converts the expression parameter to a Boolean value
    and returns the value.
    decodeURI Decodes an encoded URI into a string.
    decodeURIComponent Decodes an encoded URI component into a
    string.
    encodeURI Encodes a string into a valid URI (Uniform
    Resource Identifier).
    encodeURIComponent Encodes a string into a valid URI
    component.
    escape Converts the parameter to a string and encodes it in
    a URL-encoded format, where most nonalphanumeric characters are
    replaced with % hexadecimal sequences.
    int Converts a given numeric value to an integer value.
    isFinite Returns true if the value is a finite number, or
    false if the value is Infinity or -Infinity.
    isNaN Returns true if the value is NaN(not a number).
    isXMLName Determines whether the specified string is a valid
    name for an XML element or attribute.
    Number Converts a given value to a Number value.
    Object Every value in ActionScript 3.0 is an object, which
    means that calling Object() on a value returns that value.
    parseFloat Converts a string to a floating-point number.
    parseInt Converts a string to an integer.
    String Returns a string representation of the specified
    parameter.
    trace Displays expressions, or writes to log files, while
    debugging.
    uint Converts a given numeric value to an unsigned integer
    value.
    unescape Evaluates the parameter str as a string, decodes
    the string from URL-encoded format (converting all hexadecimal
    sequences to ASCII characters), and returns the string.
    XML Converts an object to an XML object.
    XMLList Converts an object to an XMLList object.
    So how do I do a XML type casting without using the XML
    function for example? or is it the same?

  • How can I use the update operation in a VC Model

    Hello experts,
    i try to to use the update operation in my VC model.  I have developed an AS wich return a table. Now i want to update a table row. So I add the update operation to my model. But it doesn´t work. I mapped all attribute between the table and the update service. The event name is submit.
    Another strange thing is: If i try to update in the service browser it cames the error message that the vandatory attribute ... is missing.
    Any ideas??
    Thanks
    Marco

    Hi Marco,
    In this case it is possible that your update service requires a mandatory parameter which you are not providing.
    When you drag your service onto the VC screen, right click on the service and test it.It will give you a clear picture of which parameters are required by the service and besides you can also use some test data to check if the service is working properly.
    Do let me know if this helps.
    Thanks,
    Gaurav.

  • SSRS Expression for Conditional Filtering using the "IN" operator

    Hello,
    I need to filter my dataset based on a parameter:
    If Period= 1 then Week must be in (W1, W2, W3),  Else Week must be in (W10, W20, W30)
    I tried using the "IN" operator but don't know how to create the expression for the "Value" field. I tried the following:
    iif(Parameters!Period.Value = 1,
    "W1, W2, W3",
    "W10, W20, W30")
    But it doesn't work.
    Expression: Week
    Operator: IN
    Value: ???
    Any help would be highly appreciated!

    Hi,
    Use split function.
    See this expression: IIF(Parameters!Period.Value = 1, SPLIT("W1,W2,W3",","), SPLIT("W10,W20,W30",","))
    http://social.msdn.microsoft.com/Forums/sqlserver/en-US/8da78c9b-7f0c-42f1-a9c4-82f065f317c9/using-the-in-operator-in-ssrs-expressions
    Thanks Shiven:) If Answer is Helpful, Please Vote

  • Select Performance problems using the 'like' operator

    I have a PL/SQL procedure that uses a cursor which contains a 'like' operator in the where clause. I have two database instances that are theoretically the same, however this code processes about 100,000 rows in 5 minutes on one database and 100,000 rows in several weeks on the other database. I know it is the 'like' operator that is causing the problem, but I don't know where to look in the database setup parameters as to what could be different between the two. Can someone point me in the right direction?

    I tried to think of another way to write the query, but I really need to use the wildcard option on the data I'm searching for. The system I'm working with attaches a suffix to the end of every ID (ie. '214-222-1234-0') The suffix ('-0') increments but the rest of the ID stays the same ('-1','-2',etc...), but I want to find all of the rows where the first 12 characters are the same, so I strip off the suffix and use a wildcard '%' in its place. I tried adding the SUBSTR() function to the left hand column of the where clause, but it was even slower than using the 'like' operator. I know its a sound query, I just can't figure out why it works fine on one database and not the other.

  • Using the "this" operator to pass variable references among classes and met

    Hi guys still trying to understand how to use the "this" operator
    can some one tell what I am doing wrong or just make this work for me to see how it works.
    public class ReferencePassing
    public static void main(String[]args)
    ReferencePassing rp = new ReferencePassing();
    System.out.println(rp);
    public ReferencePassing()
    HelperObject ho = new HelperObject(this);
    System.out.println(this);
    class HelperObject
    private ReferencePassing MyReferencePassingBuddy;
    public HelperObject (ReferencePassing theRp);
    MyReferencePassingBuddy = theRp;
    print();
    public void print()
    System.out.println(MyReferencePassingBuddy);
    }

    Hi guys still trying to understand how to use the "this" operatorYou're still trying to understand how to write methods and constructors.
    public HelperObject (ReferencePassing theRp);Syntax error at ';'.
    MyReferencePassingBuddy = theRp;
    print();
    public void print()Syntax error: '}' expected.

  • How do I use the ? operator in JSF tag attributes?

    I want to do something like this:
    <h:inputText styleClass="${myBean.valid ? 'styleA' : styleB'}" ...>
    What do I have to do to use this Expression language?
    With the #{...} expression the ? operator doesnt seem to be available.
    When I use the ${...} expression I am getting this error:
    javax.servlet.ServletException: ServletException in '/WEB-INF/body/Test.jsp': /WEB-INF/body/Test.jsp(12,5) According to TLD or attribute directive in tag file, attribute styleClass does not accept any expressions
         javax.faces.webapp.FacesServlet.service(FacesServlet.java:121)
    Can anybody please help?
    Thanks!

    Personally, i'd do:
    <h:inputText styleClass="styleA" rendered="#{myBean.valid}"/>
    <h:inputText styleClass="styleB" rendered="#{!myBean.valid}"/>

  • Error in Automated activity of BPM using the PI operation mapping.

    Dear Experts,
    We have a BPM process, where we have imported Operation Mapping, to use it in an automated activity. We have created the service reference with localhost and checked the local provider system check box and with type WS.
    While running the scenario the process stops at the automated activity (having the Operation mapping), with error:
    A technical error during invocation: Could not invoke service reference name
    I have tried to recreate the step couple of times but it is always the same error.
    Could you please share your expertise in how to over come the error.
    Thank you,
    Best Regards,
    Ajay

    Hi Ganesh,
    Thanks for your response.
    SOAP and Mail scenario are also using the same inbound proxy structure , and the proxy is working fine in both cases.
    For FTP scenario we are reusing the same inbound proxy but we are facing error .
    SAP is getting
    "XML to ABAP Conversion error with error id as "CX_ST_MATCH_ELEMENT " System expected the element 'Namespace of the inbound service interface' .
    Please guide.
    Thanks,
    Ruchi

  • Using the Unpivot Operator when in Oracle8i PL/SQL Generation Mode

    Hi,
    when you are validating a mapping with contains an unpivot operator and the PL/SQL Generation Mode is set to Oracle8i (because you're using an Oracle8i 8.1.7. target database) the following error is raised:
    VLD-3127: Cannot generate code for UNPIVOT because the unpivot operator is only supported starting with the Oracle9i version of the database.","The unpivot operator is only supported starting with the Oracle9i version of the database. To resolve this, set the PL/SQL Generation Mode to Oracle9i in the configuration of the Oracle module that contains this mapping.
    When you set the PL/SQL Generation Mode to Oracle9i and after successfully validating the mapping generate the code you can see that within the generated code case-statements are used for the unpivot translation.
    like:
    MIN(CASE WHEN "AGG_YEAR_MONTH" = 200301 THEN "NO_CALLS" ELSE NULL END) "JAN2003_CALLS"
    And as Oracle8i doesn't support the case-statement, the raised validation error is understandable. But the generated code can be easily modified using decode-classes instead of the case-statements.
    results in:
    MIN(DECODE("AGG_YEAR_MONTH",''200301'',"NO_CALLS",NULL)) "JAN2003_CALLS"
    And the generated code works fine in the Oracle8i 8.1.7 target database.
    But now my question:
    Does someone know if it is possible to create a custom unpivot operator in OWB9.2.0 which will generate the code using the decode-class instead of using the case-statements. And if so, how I can create such custom operator.
    Many Thx in advantage!
    Remco

    Hi,
    The reason why OWB does not generate decode statements is that the generated code needs to support both set-based and row-based operation modes. Decodes are valid in SQL (set based), but not in PL/SQL (row based)
    Oracle 8i (8.1.7) does in fact support CASE, but only in SQL statements, not PL/SQL
    Have you considered creating a view to perform the unpivot operation using decode? It should also be possible solve your problem using a function
    Regards,
    Roald

  • Why I get an error when running a sequence using the LabVIEW operator interface ?

    I have a simple TestStand sequence calling LabVIEW vis that is giving me an error when I run it with the .exe version of the LabVIEW operator interface and I set TestStand to run the vis using the 8.2.1 runtime engine instead of the development adapter. I made a change in the operator interface to open a vi programatically and get the value of a control, this vi is also used in the TestStand sequence I am trying to run. Could this be causing my problem ?
    Thanks

    Hello Verdulken,
    I have a few additional questions:
    Does your application function correctly when running the LabVIEW operator interface you have created as a VI in the LabVIEW development environment (i.e. does this problem only occur when the LabVIEW operator interface is run as an executable)?
    What is the error that you are receiving?
    Regarding the VI that you open programmatically, do you open it in a visible manner (i.e. use the Show front panel when called option from VI Properties)?If so, do you also close this VI after it finishes (i.e. use the Close if originally closed option from VI Properties)?
    Does the error occur on the step that calls this very same VI again later in the sequence?
    Does your application function correctly if you use the development adapter for all of your calls?
    Thank you in advance for this information,
    Matt G.
    National Instruments
    Applications Engineering

  • Error when using the expression operator

    Hi All
    When i'm using the following expression in the expression editor i'm getting an error message "expression is not properly formed, error expression cannot be validated". But when i use the same expression in TOAD i'm getting the result. Can any one please help me where i'm going wrong?
    SUBSTR (INGRP1.site_id_nbr, 1, 11)
    || DECODE (SUBSTR (INGRP1.site_id_nbr, -1, 1),
    1, '1',
    2, '1',
    3, '3',
    4, '3'
    Thanks

    This may be a bug in the expression validation, decode is valid in an expression operator always when Set Based code generation only is used (you may get errors if row based is used), if you configure the mapping to set based only code generation mode and default operating mode then try deploying the mapping you should be OK. Otherwise you build an expression that is valid SQL (set based) and PLSQL (row based), the CASE statement will give you this
    Cheers
    David

  • Using the minus operator

    I am very new to oracle and am working with the minus operator to run a query. I could use some help!
    Here is the query I am working on:
    select suppliername, partname
    from quote
    where partname = 'hammer'
    minus
    select suppliername, partname
    from quote
    where partname = 'hammer';
    HOW DO I GET THE QUERY TO DISPLAY ONLY THE ROWS OF SUPPLIERNAMES THAT SUPPLY ONLY HAMMERS?
    I WOULD GREATLY APPRECIATE SOME CLARIFICATION.

    HOW DO I GET THE QUERY TO DISPLAY ONLY THE ROWS OF SUPPLIERNAMES THAT SUPPLY ONLY HAMMERS?It may, for some data related reason, give you the result you were expecting, but this query does not answer that question because you have included partname in the MINUS.
    E.g.
    WITH quote AS
    (SELECT 'BOB'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'BOB'  suppliername, 'SPANNER' partname FROM DUAL UNION ALL
    SELECT 'TIM'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
    SELECT suppliername, partname
    FROM   quote
    MINUS
    SELECT suppliername, partname
    FROM   quote
    WHERE  partname != 'HAMMER';
    SUPPLIERNAME PARTNAME
    BOB          HAMMER  
    JACK         HAMMER  
    TIM          HAMMER   Clearly this is wrong because Bob supplies spanners (aka wrench).
    However:
    WITH quote AS
    (SELECT 'BOB'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'BOB'  suppliername, 'SPANNER' partname FROM DUAL UNION ALL
    SELECT 'TIM'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
    SELECT suppliername
    FROM   quote
    MINUS
    SELECT suppliername
    FROM   quote
    WHERE  partname != 'HAMMER';
    SUPPLIERNAME
    JACK        
    TIM          Amongst the many alternatives - NOT EXISTS:
    WITH quote AS
    (SELECT 'BOB'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'BOB'  suppliername, 'SPANNER' partname FROM DUAL UNION ALL
    SELECT 'TIM'  suppliername, 'HAMMER' partname FROM DUAL UNION ALL
    SELECT 'JACK' suppliername, 'HAMMER' partname FROM DUAL)
    SELECT *
    FROM   quote q1
    WHERE  NOT EXISTS (SELECT 1
                       FROM   quote q2
                       WHERE  q2.suppliername = q1.suppliername
                       AND    partname != 'HAMMER');
    SUPPLIERNAME PARTNAME
    JACK         HAMMER  
    TIM          HAMMER  

  • How to create a inputstream without using the file operation

    Hi friends
    In my application, I have to create a Streamsource object using the below constructor:
    public StreamSource(InputStream inputStream)
        Construct a StreamSource from a byte stream. Normally, a stream should be used rather than a reader, so the XML parser can resolve character encoding specified by the XML declaration.
        If this constructor is used to process a stylesheet, normally setSystemId should also be called, so that relative URI references can be resolved.
    Parameters:
        inputStream - A valid InputStream reference to an XML stream.*[http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/stream/StreamSource.html#StreamSource(java.io.InputStream) |http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/transform/stream/StreamSource.html#StreamSource(java.io.InputStream) ]*
    But for creating the inputstream, i am creating a tempory file, ie I am using fileinputstream.
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.StringReader;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    import javax.xml.transform.stream.StreamSource;
    public class SourceConvertor
        private static Source convertStaxToStream(Source request)
    // here the argument to this method is StaxSource and the return type is StreamSource
            TransformerFactory factory = TransformerFactory.newInstance();
            Transformer transformer = null;
            File fp = null;
            FileInputStream fInp = null;
            try
                transformer = factory.newTransformer();
                fp = new File("tempFile.txt");
                transformer.transform(request, new StreamResult(fp));
                fInp = new FileInputStream(fp);
            } catch (Exception e)
                e.printStackTrace();
            return new StreamSource(fInp);
        public static void main(String args[])
            try
                String message ="<author><name>Rai</name><book>GodOfSmallThings</book></author>";
                Source original = new StreamSource(new StringReader(message));
                Source converted = convertStaxToStream(original);
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer();
                transformer.transform(converted, new StreamResult(System.out));
            catch (Exception e)
                // TODO Auto-generated catch block
                e.printStackTrace();
    This is not at all a good aproach because evey time it is creating a new file.
    So can anyone suggest a better aproach or idea or a simple code snippet so that i can create the inputstream without creating a temporary file.
    Thanks in advance:
    *[http://www.javamilestone.blogspot.com/  |http://www.javamilestone.blogspot.com/  ] *

    Err, a StreamSource is a Source. Check the Javadoc. You can pass it directly to the transform.

  • With using the Union oper. query

    Hi Team
    I have table like A and B
    A table Structure
    C1-------C2-------C3
    R1-------R2--------R3
    R4-------R5---------R6
    B table Structure
    C1-----C2
    R11----R8
    my output is like below
    C1-------C2-------C3
    R1-------R2--------R3
    R4-------R5---------R6
    R11----R8----------null
    i can use the Union all condition i don't want to use the
    union all condition who? plz help
    select c1,c2,c3
    union
    select c1,c2;

    870003 wrote:
    Hi Team
    I have table like A and B
    A table Structure
    C1-------C2-------C3
    R1-------R2--------R3
    R4-------R5---------R6
    B table Structure
    C1-----C2
    R11----R8
    my output is like below
    C1-------C2-------C3
    R1-------R2--------R3
    R4-------R5---------R6
    R11----R8----------null
    i can use the Union all condition i don't want to use the
    union all condition who? plz helpWhy don't you want to use union all, because that is exactly what you are trying to achieve?

  • Using the LIKE operator with wildcards to match names

    I am using SQL in ColdFusion 9 to match names in an MS Access 2003 database table.
    The Visitors field of MyTable contains the name "Smith" in six records.
    1. Smith Jones Wilson
    2. Smith, Jones, Wilson
    3. Smith(Jr.), Jones, Wilson
    4. Jones Wilson Smith
    5. Wilson Smith Jones
    6. Smith
    7. Smithson, Jones, Wilson
    8. Jones, Wilson, Arrowsmith
    To find out which records contain the name Smith (but not Smithson or Arrowsmith) I now need to write four "OR" lines:
    WHERE MyField LIKE 'Smith[!a-zA-Z]%'  (finds only the Smiths in records 1, 2 and 3)
             OR MyField LIKE '%[!a-zA-Z]Smith'  (finds only the Smith in record 4)
           OR MyField LIKE '%[!a-zA-Z]Smith[!a-zA-Z]%' (finds only the Smith in record 5)
           OR MyField = 'Smith'   (finds only the Smith in record 6)
    I would like to know how to combine these four lines into one which would find all six records containing Smith.
    Thank you for your help.

    As this is a SQL-specific question, you might be better off asking it on a SQL forum?  Does Access even support regexes?
    For a CF the regex you'd be after "\bsmith\b".  You should read the Access regex reference to see if it supports this.  A CF regular expression is no use to you here as the comparison needs to be done on the DB,  not in CF.
    Adam
    Misread the question.  Revising.

Maybe you are looking for

  • Windows Server 2012 Essentials (not R2) - all client computers offline

    The server is Windows Server 2012 Essentials (not R2). I have had this problem ever since I first installed the Windows Server 2012 Essentials server in the summer of 2013 (before R2 was released). The Windows Server 2012 Essentials server shows offl

  • Word 2013 - new Insert Controls

    The new feature in Word 2013 allows you easily to insert a new row in a table by left-clicking in the white space to the left of the table. However, the original behaviour in 2010 and earlier (select the row, so it can be copied or deleted or overwri

  • How to replicate Middletier server by cloning?

    Hi, We are trying to replicate a production environment by cloning at OS level. We have done with cloning and I can login with the new users. I also tried replacing the old server name to the present one in various conf files, such as, context.xml fo

  • XFA dynamic forms and Annotations: When?

    We´re using mainly dynamic forms in our web solution for a lot of reasons, but in the near future we also want to give our customers the possibilty to make annotations inside their forms. Currently we have a prototype for that, with some xfa buttons

  • Why do i get an "IllegalBlockSizeException"?

    I have a piece of code which encrypts a string and stores it into a txt file. But when i come to decrypt the file i get the following error Exception in thread "main" javax.crypto.IllegalBlockSizeException: Input length (with padding) not multiple of