Installation problems with Flash CS5
  • jokigenkijokigenki May 2012

    Hi,

    I've been trying to install with CS5 and I get an error (helpfully no output). I did some tracing and tracked the error down to for each loops, which don't seem to work. The first error I get is in xsfl.load around line 679 (I can't be sure because I've been adding traces everywhere) which is "for each(var uri in uris)". If I replace this with a normal for loop, it works.

    I wrote a simple test case:

    var arr = [1,2,3,4];

    for each (var n in arr)

    {

    fl.trace(n);

    }

    which outputs:

    1

    2

    3

    4

    function (keya, keyb) {

     var comparisonFunction = (function (a, b) {var ta = a[keya];var tb = b[keya];if (ta < tb) {return -1;}if (ta > tb) {return 1;}var tc = a[keyb];var td = b[keyb];if (tc < td) {return -1;}if (tc > td) {return 1;}return 0;});

     this.sort(comparisonFunction);

    }

     

    pretty sure this last entry is not right! Not sure what can be done about this other than to replace all the for eachs, will try a test on CS5.5 and see if it's any different.

     

     

  • jokigenkijokigenki May 2012

    for in is also broken. for the same test:

    0

    1

    2

    3

    sortOn

  • jokigenkijokigenki May 2012

    Hey,

    I had a go on a copy of CS5.5, (which has never had xJSFL installed) and the loops worked as expected, so either it's something xJSFL is doing, or it's a problem specific to CS5.

    Owen 

  • DaveDave May 2012

    Hey jokigenki,

    Well, I can safely say - this is not an xJSFL issue!

    Some other code you've installed has added a function to the Array or Object prototypes itself, which breaks for each and for in loops. Have you installed another extension, or panel that might have caused this? Consider disabling panels or uninstalling other extenstions and see how you get on.

    It's simple to test this issue for yourself:

    Object.prototype.test = function foo(){};
    for each(var name in {a:1, b:2, c:3})
    {
    fl.trace(name);
    }

    If you search for keya in your Flash installation folder, you should find the offending code.

    The only other thing this could be is badly-written Adobe code. The IK System in CS4 I know adds functions to Objects or Arrays, and these break for in and for each loops.

    Let me know how you get on.

    Cheers,

    Dave

  • jokigenkijokigenki May 2012

    Hey,

    I disabled all my extensions and ran the install script, and it worked!

    When I run the script that you posted, I get:

    1

    2

    3

     

    function foo() {

    }

    Is that what I'm supposed to see?

    Cheers,

    Owen

  • jokigenkijokigenki May 2012

    The offending extension was "Pixel Tools" btw. Gotta love Javascript, that it's possible to break native classes ;)

  • DaveDave May 2012

    Yeah, it was just to prove that when you add a member to a prototype, in is inherited to all subclasses.

    But it's not, as you say, that you've "broken" native classes; it's that the coder who built Pixel Tools was either lazy, or hasn't understood / wasn't aware of how JavaScript's prototypical inheritance system works.

    Both for..each and for..in loops are the right way to iterate over an Object's properties, and those properties include "manually" added properties such as sortOn. Unfortunately, the coder of Pixel Tools didn't realise that this would affect ALL objects that inhertit from Object, which includes Arrays, where for..in should NOT be used.

    Take this code:

    Object.prototype.trace = function()
    {
    fl.trace('I am: ' + this + '!');
    };

    (1).trace();
    'dave'.trace();
    (new Date()).trace();

    //I am: 1!
    //I am: dave!
    //I am: Wed May 09 2012 23:14:57 GMT+0100 (GMT Daylight Time)!

    That is valid JavaScript. It's just that if you add the function to the Object prototype, you will affect every single value (as they all inherit from Object) in JavaScript. That's bad (JavaScript) programmming :(

    Better to only add methods to object that either a) won't be inherited from, or b) if they are, it won't matter. For example, xJSFL adds useful methods to the Number and String classes, because they most-likely won't be extended. And if they are, it's highly unlikely that a for..each loop will be run on them (as they're not Arrays).

    for..each was added in JavaScript 1.6 and if we're going to be writing modern JavaScript should be happily used. It's a shame that the Pixel Tools author chose to extend the Array or Object prototype and broke it for everyone else.

    Maybe you could send him an email?

     

  • DaveDave May 2012

    Thinking about it... I may even add a check in for illegal Object extensions. That would certainly help new installers with this issue!

    var obj = {};
    var names = [];
    for(var name in obj)
    {
    names.push(obj[name]);
    }
    if(names.length)
    {
    var str = '';
    throw new Error('\nIllegal Object extensions detected! The offending members are:\n\n\t' + names.join('\n\n').replace(/\n/g, '\n\t') + '\n\nPlease check your other Flash extensions (not xJSFL) for these illegal JSFL functions, and disable them for xJSFL installation to succeed.');
    }

    Resulting in:

    The following JavaScript error(s) occurred:

    At line 16 of file "test.jsfl":

    Illegal Object extensions detected! The offending members are:

    function foo() {
    }

    function () {
    fl.trace("I am: " + this + "!");
    }

    Please check your other Flash extensions (not xJSFL) for these illegal JSFL functions, and disable them for xJSFL installation to succeed.
  • jokigenkijokigenki May 2012

    Sounds like a good idea. It's such a pain that Flash swallows the error messages, took me a while to track down where the problem was happening.

    I couldn't find the author's email, the website isn't registered anymore.

    Anyway, thanks for the help!

    Cheers,

    Owen

     

  • DaveDave May 2012

    I know. They obviously dropped the ball with CS5 error messages. I might stick in some kind of alert for that as well, warning CS5 users that they're potentially left open to debugging issues. Why is it never easy!?

    Cheers,

    Dave

  • DaveDave May 2012

    Owen, can you give me the output on both CS5 and CS5.5 for:

    fl.trace(fl.version);

    Thanks,

    Dave

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID Sign In with Google Sign In with Twitter

Sign In Apply for Membership

Tagged