EzDevInfo.com

actionscript-3 interview questions

Top actionscript-3 frequently asked interview questions

Trying to login to RDP using AS3

I am trying to login to RDP using AS3 (air). I am doing ok, considering the lack of resources out there to understand the actual process.

I have gotten past the initial sending username, received a response from server, and I am now at initial request connection.

I am sending all my data and when sniffing traffic, I see that netmon is recognizing correctly what kind of packet I am sending (t125). I am not being disconnected by RDP and they send an ack packet - but I don't receive the response that I am expecting.

I have been cross referencing with connectoid, which is an open source RDP client. In the connection code, I am stuck where they write a mixture of little and big-endian integers.

When I look at the limited examples out there (more like packet dumps), I see that connection length for this process is 412, but my bytearray is more like 470.

I have converted connectoid methods to what I believe is correct, but with a mixture of endian type, I am still unsure.

I am sorry if this is garbled, but I am trying my best to help you to help me. I will attach some code showing what I have tried to do in conversion.

public function sendMcsData(): void {
    trace("Secure.sendMcsData");
    var num_channels: int = 2;
    //RdpPacket_Localised dataBuffer = new RdpPacket_Localised(512);
    var hostlen: int = 2 * "myhostaddress.ath.cx".length;
    if (hostlen > 30) {
        hostlen = 30;
    }
    var length: int = 158;
    length += 76 + 12 + 4;
    length += num_channels * 12 + 8;
    dataBuffer.writeShort(5); /* unknown */
    dataBuffer.writeShort(0x14);
    dataBuffer.writeByte(0x7c); //set 8 is write byte //write short is setbigendian 16 //
    dataBuffer.writeShort(1);
    dataBuffer.writeShort(length | 0x8000); // remaining length
    dataBuffer.writeShort(8); // length?
    dataBuffer.writeShort(16);
    dataBuffer.writeByte(0);
    var b1: ByteArray = new ByteArray();
    b1.endian = Endian.LITTLE_ENDIAN;
    b1.writeShort(0xc001);
    dataBuffer.writeBytes(b1);
    dataBuffer.writeByte(0);
    var b2: ByteArray = new ByteArray();
    b2.endian = Endian.LITTLE_ENDIAN;
    b2.writeInt(0x61637544);
    dataBuffer.writeBytes(b2);
    //dataBuffer.setLittleEndian32(0x61637544); // "Duca" ?!
    dataBuffer.writeShort(length - 14 | 0x8000); // remaining length
    var b3: ByteArray = new ByteArray();
    b3.endian = Endian.LITTLE_ENDIAN;
    // Client information
    b3.writeShort(SEC_TAG_CLI_INFO);
    b3.writeShort(true ? 212 : 136); // length
    b3.writeShort(true ? 4 : 1);
    b3.writeShort(8);
    b3.writeShort(600);
    b3.writeShort(1024);
    b3.writeShort(0xca01);
    b3.writeShort(0xaa03);
    b3.writeInt(0x809); //should be option.keybaortd layout just guessed 1
    b3.writeInt(true ? 2600 : 419); // or 0ece
    dataBuffer.writeBytes(b3);
    // // client
    // build? we
    // are 2600
    // compatible
    // :-)
    /* Unicode name of client, padded to 32 bytes */
    dataBuffer.writeMultiByte("myhost.ath.cx".toLocaleUpperCase(), "ISO");
    dataBuffer.position = dataBuffer.position + (30 - "myhost.ath.cx".toLocaleUpperCase()
        .length);
    var b4: ByteArray = new ByteArray();
    b4.endian = Endian.LITTLE_ENDIAN;
    b4.writeInt(4);
    b4.writeInt(0);
    b4.writeInt(12);
    dataBuffer.writeBytes(b4);
    dataBuffer.position = dataBuffer.position + 64; /* reserved? 4 + 12 doublewords */
    var b5: ByteArray = new ByteArray();
    b5.endian = Endian.LITTLE_ENDIAN;
    b5.writeShort(0xca01); // out_uint16_le(s, 0xca01);
    b5.writeShort(true ? 1 : 0);
    if (true) //Options.use_rdp5)
    {
        b5.writeInt(0); // out_uint32(s, 0);
        b5.writeByte(24); // out_uint8(s, g_server_bpp);
        b5.writeShort(0x0700); // out_uint16_le(s, 0x0700);
        b5.writeByte(0); // out_uint8(s, 0);
        b5.writeInt(1); // out_uint32_le(s, 1);
        b5.position = b5.position + 64;
        b5.writeShort(SEC_TAG_CLI_4); // out_uint16_le(s,
        // SEC_TAG_CLI_4);
        b5.writeShort(12); // out_uint16_le(s, 12);
        b5.writeInt(false ? 0xb : 0xd); // out_uint32_le(s,
        // g_console_session
        // ?
        // 0xb
        // :
        // 9);
        b5.writeInt(0); // out_uint32(s, 0);
    }
    // Client encryption settings //
    b5.writeShort(SEC_TAG_CLI_CRYPT);
    b5.writeShort(true ? 12 : 8); // length
    // if(Options.use_rdp5) dataBuffer.setLittleEndian32(Options.encryption ?
    // 0x1b : 0); // 128-bit encryption supported
    // else
    b5.writeInt(true ? (false ? 0xb : 0x3) : 0);
    if (true) b5.writeInt(0); // unknown
    if (true && (num_channels > 0)) {
        trace(("num_channels is " + num_channels));
        b5.writeShort(SEC_TAG_CLI_CHANNELS); // out_uint16_le(s,
        // SEC_TAG_CLI_CHANNELS);
        b5.writeShort(num_channels * 12 + 8); // out_uint16_le(s,
        // g_num_channels
        // * 12
        // + 8);
        // //
        // length
        b5.writeInt(num_channels); // out_uint32_le(s,
        // g_num_channels);
        // // number of
        // virtual
        // channels
        dataBuffer.writeBytes(b5);
        trace("b5 is bigendin" + (b5.endian == Endian.BIG_ENDIAN));
        for (var i: int = 0; i < num_channels; i++) {
            dataBuffer.writeMultiByte("testtes" + i, "ascii"); //, 8); // out_uint8a(s,
            // g_channels[i].name,
            // 8);
            dataBuffer.writeInt(0x40000000); // out_uint32_be(s,
            // g_channels[i].flags);
        }
    }
    //socket.
    //buffer.markEnd();
    //return buffer;
}

Source: (StackOverflow)

Difference between e.target and e.currentTarget

I don't understand the difference, they both seem the same but I guess they are not.

Any examples of when to use one or the other would be appreciated.


Source: (StackOverflow)

Advertisements

Calculate Bounding box coordinates from a rotated rectangle, Picture inside

Schema

I have the coordinates of the top left Point of a rectangle as well as its width, height and rotation from 0 to 180 and -0 to -180.

I am trying to get the bounding coordinates of the actual box around the rectangle. What is a simple way of calculating the coordinates of the bounding box - min y, max y, min x, max x ?

The A point is not always on the min y bound, it can be anywhere. I can use matrix the transform toolkit in as3 if needed.


Source: (StackOverflow)

What is the best way to stop people hacking the PHP-based highscore table of a Flash game

I'm talking about an action game with no upper score limit and no way to verify the score on the server by replaying moves etc.

What I really need is the strongest encryption possible in Flash/PHP, and a way to prevent people calling the PHP page other than through my Flash file. I have tried some simple methods in the past of making multiple calls for a single score and completing a checksum / fibonacci sequence etc, and also obfuscating the SWF with Amayeta SWF Encrypt, but they were all hacked eventually.

Thanks to StackOverflow responses I have now found some more info from Adobe - http://www.adobe.com/devnet/flashplayer/articles/secure_swf_apps_12.html and https://github.com/mikechambers/as3corelib - which I think I can use for the encryption. Not sure this will get me around CheatEngine though.

I need to know the best solutions for both AS2 and AS3, if they are different.

The main problems seem to be things like TamperData and LiveHTTP headers, but I understand there are more advanced hacking tools as well - like CheatEngine (thanks Mark Webster)


Source: (StackOverflow)

Call Angular JS from legacy code

I'm using angular to build HTML controls that interact with a legacy Flex application. All callbacks from the Flex app must be attached to the DOM window.

For example (in AS3)

ExternalInterface.call("save", data);

Will call

window.save = function(data){
    // want to update a service 
    // or dispatch an event here...
}

From within the JS resize function I'd like to dispatch an event that a controller can hear. It seems that creating a service is the way to go. Can you update a service from outside of Angular? Can a controller listen for events from a service? In one experiment (click for fiddle) I did it seems like I can access a service but updating the service's data doesn't get reflected in the view (in the example an <option> should be added to the <select>).

thanks!


Source: (StackOverflow)

What are the major performance hitters in AS3 aside from rendering vectors?

In ActionScript 3, using vector graphics is a guaranteed way to cause massive damage to the performance of your project.

Using a single Bitmap for all graphics by using .copyPixels() through its BitmapData object in place of all vector graphics will yield a ridiculous performance boost and is essential for people like myself developing games within Flash.

Beyond this I'm not really sure what the next major things that I should be targeting and attempting to optimize are. I do use a lot of the inbuilt trigonometry functions, but they don't seem to affect it all that much. I know there are some libraries that optimize mathematics with approximation methods and similar, but so far I haven't found these necessary.

Are there any other massive known points I should be looking at? I'm more referring to the inbuilt things that I should be careful of (like avoiding vector rendering) rather than how to improve my own coding style.


Source: (StackOverflow)

Does PNG contain EXIF data like JPG?

I was wondering if PNG contains data like the following?

What I did was to convert the jpg file to png format, and I was expecting to retrieve the same info I had on the jpg as below:

Currently using this as3 library to read the data.

  • IDF0--- IDF @[134 - 248] (9 entries)
    • Orientation (SHORT) : 1
    • XResolution (RATIONAL) : 72/1
    • YResolution (RATIONAL) : 72/1
    • ResolutionUnit (SHORT) : 2
    • Software (ASCIIx16) : QuickTime 7.6.6
    • DateTime (ASCIIx20) : 2011:10:02 22:43:37
    • HostComputer (ASCIIx16) : Mac OS X 10.6.8
    • Exif IFD (LONG) : 8 34853
    • GPS IFD (LONG) : 248

 

  • EXIF IDF--- IDF @[8 - 134](10 entries)
    • ExifVersion (UNDEFINEDx4) : 0220
    • DateTimeOrigina (ASCIIx20) : 2011:04:14 17:22:01
    • UserComment (UNDEFINEDx63) : ASCII
    • FlashpixVersion (UNDEFINEDx4) : 0100
    • ColorSpace (SHORT) : 1
    • PixelXDimension (LONG) : 1022
    • PixelYDimension (LONG) : 486
    • Unknown (ASCIIx13) : Image Tag-LOL
    • SceneCaptureType (SHORT) : 0

 

  • GPS IDF--- IDF @[248 - 338](7 entries)
    • Interoperability Index (ASCIIx2) : N
    • Interoperability Version (RATIONALx3) @425: 52/1, 1144/100, 0/1
    • Unknown (ASCIIx2) : W
    • Unknown (RATIONALx3) : 1/1, 4392/100, 0/1
    • Unknown (RATIONAL) : 5/1
    • Unknown (ASCIIx2) : T
    • Unknown (RATIONAL) : 3694/117

 


Source: (StackOverflow)

Efficient looping through AS3 dictionary

for (var k in dictionary) 
{
  var key:KeyType = KeyType(k);
  var value:ValType = ValType(dictionary[k]); // <-- lookup
  // do stuff
}

This is what I use to loop through the entries in a dictionary. As you can see in every iteration I perform a lookup in the dictionary. Is there a more efficient way of iterating the dictionary (while keeping access to the key)?


Source: (StackOverflow)

How do I get from an instance of a class to a Class object in ActionScript 3?

How do you get an instance of the actionscript class Class from an instance of that class?

In Python, this would be x.__class__; in Java, x.getClass();.

I'm aware that certain terrible hacks exist to do this, but I'm looking for a built-in language facility, or at least a library routine built on something reliable.


Source: (StackOverflow)

Unloading a ByteArray in Actionscript 3

How do I forcefully unload a ByteArray from memory in ActionScript 3?

I have tried (without success):

byteArray.length = 0;
byteArray = new ByteArray();

And

for ( var i:int=0; i < byteArray.length; i++ ) {
    byteArray[i] = null;
}

Source: (StackOverflow)

How to make use of play2() function in order to perform fast stream switching of videos?

I am currently working on a Flash webplayer with resolution switching functionality. I am trying to make use of the NetStream class's play2() function in Actionscript.

The problem I am running into is that the videos don't change quickly. For those familiar with the play2() function I believe that the player is performing a "standard switch" rather than a "fast switch."

The documentation says that when the offset parameter is -1, fast switching occurs. What actually happens, though is once the "NetStream.Play.Transition" event is received, the player waits until the time denoted by ns.time + ns.bufferLength has been reached, before performing the switch.

I thought fast switching cleared the buffer, but on a check to ns.backbufferlength, I found that everything is still cached. Also it mentions: "When offset is -1, the switch occurs at the first available keyframe after netstream.time + 3," which is why I am confused.

Any help/insight on this matter would be much appreciated.

Here is a snippet of code describing what is going on (newStream() is called when a user clicks to change to a new resolution, youtube style):

public function newStream(address:String):void
{
    var opts:NetStreamPlayOptions = new NetStreamPlayOptions();
    opts.streamName = address;
    opts.transition = NetStreamPlayTransitions.SWITCH;
    opts.offset = -1;
    ns.play2(opts);
}

private function nsCallback(event:NetStatusEvent)
{
    switch(event.info.code)
    {
        case "NetStream.Play.Transition":
        {
            trace("Current time (on Transition): " + 
                  ns.time, "Buffer: " + ns.bufferLength);
            var estTime:Number = ns.time + ns.bufferLength;
            trace("Estimated Completion Time: " + estTime);
            break;
        }
    }
}

Source: (StackOverflow)

konami code in flex

What would be the best way to implement the konami code into a flex application?

I want to create a component to add it on all my proyects, just for fun.

thanks

UPDATE: I made a simple component, thanks to ZaBlanc

<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
    <mx:Metadata>
    	[Event(name="success", type="flash.events.Event")]
    </mx:Metadata>
    <mx:Script>
    	<![CDATA[

    		// up-up-down-down-left-right-left-right-B-A
    		public static const KONAMI_CODE:String = "UUDDLRLRBA";

    		// signature
    		private var signatureKeySequence:String = "";

    		private function init():void{
    			systemManager.stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
    		}

    		private function onKeyDown(event:KeyboardEvent):void{
    			var keyCode:int = event.keyCode;

    		    switch (keyCode) {
    		        case Keyboard.UP:
    		            signatureKeySequence += "U";
    		            break;

    		        case Keyboard.DOWN:
    		            signatureKeySequence += "D";
    		            break;

    		        case Keyboard.LEFT:
    		            signatureKeySequence += "L";
    		            break;

    		        case Keyboard.RIGHT:
    		            signatureKeySequence += "R";
    		            break;

    		        case 66: //Keyboard.B only for AIR :/
    		            signatureKeySequence += "B";
    		            break;

    		        case 65: //Keyboard.A only for AIR too :(
    		            signatureKeySequence += "A";
    		            break;

    		        default:
    		            signatureKeySequence = "";
    		            break;
    		    }

    		    // crop sequence
    		    signatureKeySequence = signatureKeySequence.substr(0, KONAMI_CODE.length);

    		    // check for konami code
    		    if (signatureKeySequence == KONAMI_CODE) {
    		        dispatchEvent(new Event("success"));
    		        signatureKeySequence = "";
    		    }

    		}
    	]]>
    </mx:Script>

</mx:UIComponent>

to test it

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:konamicode="konamicode.*">
    <mx:Script>
    	<![CDATA[
    		import mx.controls.Alert;
    	]]>
    </mx:Script>
    <konamicode:KonamiCodeCatch success="Alert.show('+30 lives!!!')" />
</mx:Application>

Source: (StackOverflow)

How do I test if a property exists on a object before reading its value?

I'm attempting to read a property on a series of Sprites. This property may or may not be present on these objects, and may not even be declared, worse than being null.

My code is:

if (child["readable"] == true){
    // this Sprite is activated for reading
}

And so Flash shows me:

Error #1069: Property selectable not found on flash.display.Sprite and there is no default value.

Is there a way to test if a property exists before reading its value?

Something like:

if (child.isProperty("readable") && child["readable"] == true){
    // this Sprite is activated for reading
}

Source: (StackOverflow)

Flash/Flex conditional compilation "else"

In AS3 you can pass a constant to the compiler

-define+=CONFIG::DEBUG,true

And use it for conditional compilation like so:

CONFIG::DEBUG {
   trace("This only gets compiled when debug is true.");
}

I'm looking for something like #ifndef so I can negate the value of debug and use it to conditionally add release code. The only solution I've found so far was in the conditional compilation documentation at adobe and since my debug and release configurations are mutually exclusive I don't like the idea of having both DEBUG and RELEASE constants.

Also, this format works, but I'm assuming that it's running the check at runtime which is not what I want:

if (CONFIG::DEBUG) {
   //debug stuff
}
else {
   //release stuff
}

I also considered doing something like this but it's still not the elegant solution I was hoping for:

-define+=CONFIG::DEBUG,true -define+=CONFIG::RELEASE,!CONFIG::DEBUG

Thanks in advance :)


Source: (StackOverflow)

Best Tools for Debugging Flash ActionScript 3 (AS3) [closed]

Does anyone want to share the best debugging tools they have found for Actionscript 3 (AS3) and Flash CS5?

I've just done a search and found a few, but would love to hear from people who've actually used any of them. (In order of 'most promising')


Screenshots...

Adobe Scout:

De MonsterDebugger:

Thunderbird AS3 Console:

Luminic Box:

Senocular:

Xray:


Source: (StackOverflow)