Archive

Tag Archives: flash

If you have some flash application talking to back-end via TCP, then it would be useful for you to launch special cross domain policy server on 843 port:

sudo bash -c “exec nohup setsid node policy_server.js 0<&- &”

// policy_server.js
var server = require(“net”).createServer(function(socket) {
    socket.on(‘error’, function(err) {});
    socket.end(‘<cross-domain-policy><allow-access-from domain=”*” to-ports=”*”/></cross-domain-policy>’);
});
server.on(‘error’, function(err) {});
server.listen(843);

Advertisements

Today I was needed to check several hundreds of .fla files for existance of specified labels in movies timelines. I created jsfl script. See below. It loads all .fla files one by one, finds specified movie and checks its timeline.

fl.outputPanel.clear();

var dir = ‘file:///d|/Projects/civcity/flash/branches/stable/resources/fla/buildings/’;
var n = 442;

var re = new RegExp(“civcity.buildings.”, “”);

for (var f = 1; f <= n; ++f)
{
    var fileURI = dir + ‘b_’ + f + ‘.fla’;
    if (!fl.fileExists(fileURI))
        continue;
    fl.openDocument(fileURI);
    var items = fl.getDocumentDOM().library.items;
    for (var i=0; i < items.length; i++)
    {
        item = items[i];
        name = item.name;
        if (name.match(re))
        {
            if (item.symbolType == ‘movie clip’)
            {
                var hasPreview = false;
                var hasIdle = false;

                tim = item.timeline;
                for (var l = 0; l < tim.layers.length; ++l)
                {
                    var lay = tim.layers[l];
                    var labels = [];
                    for(var fr=0; fr<lay.frames.length;++fr)
                    {
                        if(lay.frames[fr].labelType == “name”)
                        {
                            if (lay.frames[fr].name == ‘Preview’)
                                hasPreview = true;
                            if (lay.frames[fr].name == ‘Idle’)
                                hasIdle = true;
                        }
                    }
                }

                if ((!hasPreview) || (!hasIdle))
                {
                    fl.trace(f);
                    fl.trace(name);
                }
            }
        }
    }
    fl.documents[0].close();
}

fl.trace(“Done”);

The best developer is the professional who try to automate as many tasks as possible. Yesterday I was involved into such automation process. There was the sheet of play cards and I needed to split it into the single card images and import into .fla flash as resource for flash game project. So, I implement Automation even twice.

First task

Spilt sheet into several images. For this first task I used Python and PIL:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import PIL
from PIL import Image
im_source = Image.open(“classic-playing-cards.png”)
width = 71
height = 96
ys = (‘c’, ‘h’, ‘s’, ‘d’)
xs = (‘a’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘t’, ‘j’, ‘q’, ‘k’)
for x in xrange(0, 13):
    for y in xrange(0 ,4):
        file_name = “%s%s.png” % (xs[x], ys[y])
        im_c = im_source.copy()
        left = x * (width+2) + 1
        top = y * (height+2) + 1
        im_c = im_source.crop((left+1, top+1, left + width+1, top + height+1))
        im_c.save(file_name)
        print file_name

52 cards. So, this script applying is much faster and safer way than photoshop.

Second task

I imported 52 cards to Flash IDE. And now it needs to generate 52 sprites (one per each card). I used JSFL (JavaScript for Flash) for that:

var doc = fl.getDocumentDOM();
var lib = doc.library;

var items = lib.getSelectedItems();

var prefix = “com.kikudjiro.minigames.blackjack.cards.C”;
var ys = [‘a’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘t’, ‘j’, ‘q’, ‘k’];
var xs = [‘c’, ‘d’, ‘h’, ‘s’];

for (var i in items)
{
     var bitmap = items[i];
     var sX = bitmap.name.substring(15, 16);
     var sY = bitmap.name.substring(14, 15);
     var suffix = ys.indexOf(sY) * 4 + xs.indexOf(sX);
     if (suffix < 10)
          suffix = ‘0’ + suffix;
     var card_name = prefix + suffix;

           lib.addNewItem(“movieclip”, card_name);
     var index = lib.findItemIndex(card_name);
     var item = lib.items[index];
     item.linkageExportForAS = true;
     item.linkageExportInFirstFrame = true;
     item.linkageBaseClass = “flash.display.Sprite”;
     item.linkageClassName = card_name;

           lib.editItem(card_name);
     lib.addItemToDocument({x:0, y:0}, “cards/bitmaps/” + sY + sX + “.png”);

           lib.moveToFolder(“cards/deck”, card_name);
}

P.S.
The most useful automation scenario is using FAR manager macros system. Press Ctr-. to start macro recording. And after apply some set of regular actions that should be repeated press Ctr-. to stop recording and set hot key for the macro. Usually I practice it in internal FAR text editor but it’s ok to use it for any FAR actions.

Last week I finished with desing and implementation of tournaments feature of our social game about army.
Taking just raw idea of the tournament I’ve done both the server side (C#.NET+MSSQL) and the client side (Flash+ActionScript3), communication protocol, designed gameplay workflow and formalized details of UI for artist to make art. As result, there is a nice feature in the game.

One more time I have ability to prove the ability to work very productive as both the client side and the server side developer beyond the opinion of other people who claimed that it’s impossible.

Army_tournament_1Army_tournament_2

Yesterday, I interviewed AS3 coder position candidate. The most of times, I’m taking my part on job interview as candidate, but not yesterday.
This guy looks ok as coder. He’s provided nice sources and done with test task in half of day. But I want to talk about other thing.

Another opinion at line of hiring was about more strict test task, real one task. It would take much more time to do such real implementation. So, this test task would not look like test one. Keep in mind, the test task is just to check the skills of a candidate. On the other hand, the candidate may feel hurt by interviewer if asked for too complicated unpaid work. The company may looks like empire of evil in the eyes of stranger. Nobody wants to work in bad team or work in bad team for less money.

So, let’s being kind company with smiles that looks amazing in people eyes.

Great-empire-social-game-1

Already several months I’m working on “Great Empire“. It’s a game for social network. For now it’s already customized and successfully used in several networks. It’s really insteresting project with huge amount of different tasks: Flash/ActionScript 3 client side programming, server side, DB and performance optimization, game desing. I’m very happy to be useful not just as software developer but as project manager and analyst as well.