Re: [Flashcoders] small code question

2006-01-26 Thread Morten Barklund Shockwaved

Fumio Nonaka wrote:

Using new Number is... silly. The Number-object is quite useless
and can't be used for anything, that a regular number can't. Use
normal numbers and use numbers:


The Number object can have a property, which a regular number can't.
I don't know if it is useful, though.


I know - that's why.. silly :)

It's useless. And it isn't even of primitive type number unless you 
invoke it's valueOf, which would automatically be invoked anyways in any 
calculations.


Number-, Boolean- and String-objects (not primitives) are silly and 
useless :)


--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] getting the name of an object

2006-01-23 Thread Morten Barklund Shockwaved

Sascha Balkau wrote:
Ok but it there a way to get the name of the variable that is reffering 
to the object? First I thought eval() could be used for that but it 
seems not.


There is no one variable holding the name of an object. If your idea 
is something along a trace-function:


function trace(o:Object):String {
// return name of object here
}
trace(foo_object);

Then one could argue, that both foo_object and o would be proper 
names of the variable holding the object - as there is many references.


Couldn't you rather explain, what you were trying to accomplish - then 
maybe we could understand and help?


--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Can't redefine class method

2006-01-16 Thread Morten Barklund Shockwaved

Hi,


i've had a look with flasm, it explicitly calls A.dothis() in A.doit.
writing this.dothis() isn't possible because it's a static function --
there is no object this could refer to.
there is, as far as i know, nothing you can do about it except to work
around it by either cutting'n'pasting doit from A, or using a
singleton instead.

instinctively, i would agree with you and expect B.dothis to get
called when i call B.doit, though


Nope, when you call the static method, it will not change when 
subclassed. That is exactly as I would expect.


This is due to the fact, that static methods aren't inherited - they do 
not exist on instances. They only exist on the class itself. When you 
call a static method or refence a static variable, that path to the 
variable or method will be hardcoded in front of the name of the 
member and thus not change when subclassed.


I would also expect this behaviour. Consider static methods as though 
they existed in a totally different class. If class A refenced a method 
of class C, then just because A was subclassed into B, B still refers to 
class C - what else should it do?


--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] XML GALLERY

2005-12-20 Thread Morten Barklund Shockwaved

Jose Maria Barros wrote:

Hello! Im trying to do a portfolio gallery with a grid and small
thumbnails with xml.

I ve been doing some tutorials to help me..but this thing doesnt work.

[snip]

The xml file is made correctly and the path for the images is
link=imagens/somepic.jpg


The problem is...? Not loading? Not clickable? Not right size? :)

--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Array like access to custom class?

2005-12-20 Thread Morten Barklund Shockwaved

Dan Thomas wrote:

Can I provide array like access to a custom collection object?

E.g.

Class MyClass
{
private var myArray:Array;

public function getArray():Array
{
return this.myArray;
}
}

[snip]

How can I change it so I can achieve the same thing but with access to
the items like this:

var someClass:MyClass = new MyClass;
thisItem = someClass[0];


Use __resolve:

class MyClass
{
private var myArray:Array;

public function __resolve(name:String):Object
{
if (!isNaN(name)) {
return myArray[Number(name)];
} else {
return false;
}
}
}

But it will not strict type properly at all, so you lose major 
benefits of using as2 this way. I'd do it:


class MyClass
{
private var myArray:Array;

public function elem(n:Number):Object
{
return myArray[n];
}
}

And:

var someClass:MyClass = new MyClass;
thisItem = someClass.elem(0);

Then you will get proper validation of argument, parameter and return types.

--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Array like access to custom class?

2005-12-20 Thread Morten Barklund Shockwaved

someClass.elem(0) = myObj;


Nope - of course not. elem is a function - you can't use it that way.
You can do anything you like, though. Create your own function for instance:

someClass.setElem(0, myObj);

Or a general addElem, that doesn't take a position argument but just 
pushes to the end:


someClass.addElem(myObj);

Anything you like :)

--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Out of curiosity, XPath and String Datatype Oddity

2005-12-20 Thread Morten Barklund Shockwaved

Mike Boutin wrote:
Doesnt XPath.selectNodes(myxml, pathtocontent/text()); return the text 
value as well?


The documentation says, that selectNodes *always* returns an array of 
XMLNode-objects - and it does. Always.


The text()-syntax is only used to get the XMLNode representing a text 
node - that has no nodeName and thus cannot be accessed otherwise.


--
Morten Barklund - Information Architect - Shockwaved ApS
Larsbjoernsstraede 8 - DK-1454 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] double byte character sets

2005-12-15 Thread Morten Barklund Shockwaved

nik crosina wrote:

Has anybody worked with Flash and double byte (e.g. chinese) characters
sets?
Or is that a non issue in Flash. We are having to convert a Director
application into a fully unicoded Flash version (the missing unicdoe
implementation of Director being the main reason for this).


Chinese isn't double-byte in UTF8 - it's triple-byte (as far as I know). 
Danish special characters (and most other special characters of roman 
languages, just as cyrillic, greek and other characters) are 
double-byte, and it works just fine.


Flash understands unicode (using UTF8-encoding) perfectly internally and 
when loading and sending strings.


--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] can't remove a clip attached to root???

2005-12-14 Thread Morten Barklund Shockwaved

Jason Rayles wrote:
Is there a reason that a movie clip attached to _root cannot be removed 
using removeMovieClip?


If _root.getNextHighestDepth() returns a negative value, then you cannot 
remove the movieclip unless you swap it up to some positive depth. I'm 
not sure, but that might be it.


Otherwise, no! There is no such difference - of course you can do that.

Change the depth to 1, and see if that works out for you :)

--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] alpha -= 10 = wtf

2005-12-14 Thread Morten Barklund Shockwaved

Jason Rayles wrote:

Has this been discussed?
Flash player 8

trace(this._alpha);
this._alpha -= 10;
trace(this._alpha);

Output:
100
89.84375


Yup, alpha is stored internally as values dividable by 100/256. Thus the 
value upon setting will be rounded to the nearest legal value. Use 
another variable in between:


init:
this.alpha = this._alpha;

update:
this._alpha = this.alpha -= 10;

alpha will then always be correct (with the value you want it to be), 
and _alpha will keep up as good as it can.


:)

--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Xpath and HTML tags inside XML bug?

2005-12-07 Thread Morten Barklund Shockwaved

Mike Boutin wrote:
Still wasnt able to get it working.  I had to resort to using nodeValue 
instead. pain in the ass


Why is it a workaround? Doesn't the XPath return the XMLNode? You can't 
just use the regular toString-method of the XMLNode-object - that'll 
return the wrong encoding. The nodeValue *is* the only proper way to 
fetch the correct textdata without encoding.


If the XPath-method, that you use, is supposed to return the string 
value of a text element, then using nodeValue is a hack. But if you 
only use an XPath-method which is supposed to return an XMLNode, then 
it is *not* a hack, but doing exactly, what you are supposed to do. I 
haven't used this XPath-extension, but maybe I should check i out.


--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Xpath and HTML tags inside XML bug?

2005-12-07 Thread Morten Barklund Shockwaved

Mike Boutin wrote:

even in this case the result is undefined

string = XPath.selectNodes(my_xml, /pathto[1]/xml).nodeValue;


I've just gotten the libraries, and it is exactly as I expected. 
selectNodes returns an Array of XMLNode-objects. Even the notion of 
/text() is just to get the node, which has no name, as it is a textnode 
- but it does not mean, that it will return the text. The function will 
still return an array of XMLNode-objects. So in order to actually get 
the text, you need to select the corrent index in the array, and then 
get the nodeValue from the XMLNode. given:


var nodes:Array = XPath.selectNodes(my_xml, /pathto[1]/xml/text());
var textnode:XMLNode = XMLNode(nodes[0]);
var text:String = textnode.nodeValue;

That would be the proper way to do this perfectly and correctly. And 
rather OOP and nice too :)


--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Compiler bug when extending MovieClip and calling super-function in subclass constructor

2005-11-29 Thread Morten Barklund Shockwaved

Hi,

I believe, that I've found a bug in the Flash 8 compiler.

Just for the facts: I have Flash 8 Professional (English edition) for 
Windows XP - no other version number, as far as I can see.


The bug is, that the compiler will result in a missing pop-operation 
thus leaving an extra item on the stack when extending movieclip and in 
the constructor of the subclass calling a function of the movieclip 
class. The special extension-function will have a missing pop-operation 
when the super-function is called without adding this. or super. to 
the function call.


The simplest case is a FLA file only containing:

var sc:SubClass = new SubClass();
trace(sc instanceof SubClass);

And SubClass only containing:

class SubClass extends MovieClip {
public function SubClass() {
play();
}
}

The trace will be false in the above, but when adding this. or 
super. to the play-invocation, the trace will be true.


When decompiled with Flasm 1.6 the only difference between a SWF with 
this. and without is, that with this. an extra pop()-operation is 
added. And this pop-operation should be there, as it will properly 
remove the something from the stack. (both FLM-files added for 
reference in below-mentioned ZIP)


The above is just a simple example, it is not actually occuring as we 
all know, that you cannot instantiate movieclips through the 
constructor. But you can instantiate movieclips by adding them to a 
movieclip in the library and attach this movieclip. Thus we can add an 
extra class Attacher:


class Attacher {
public function Attacher() {
_root.attachMovie(SubClass, sub, 1);
}
}

And in the FLA file we create a movieclip in the library with the AS2 
class and identifier SubClass. We change the frame actionscript to:


var attacher:Attacher = new Attacher();
trace(attacher instanceof Attacher);

Now, attacher is _not_ an instance of class Attacher. It is actually 
undefined. And _that_ is a bug!


It only occurs when extending movieclip (or maybe also Button or 
TextField, haven't tried those), and only when the reference to the 
super-function is in the constructor of the subclass. Haven't tried Flash 7.


I've added all the files needed to reproduce (and I've reproduced at 
other computers with Flash 8) to a zip, and it can be downloaded at:


http://actionscript.dk/downloads/bughunt.zip

Feel free to comment.

This bug report will be submitted to Macromedia after the sending of 
this mail.


--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Is Not a Number

2005-10-31 Thread Morten Barklund Shockwaved

Martin Klasson wrote:

Run this, once in flash player6-setting, and one time in 7/8, both
compiled with as2. The Strong-typing of the parameter doesn't affect the
result.

But how come this is so indifferent results, was perhaps the output of
flsahplayer6 wrong accordingly to ecma?

trace(!isNaN(undefined))


That would be pretty old news and was one of the things changed back then.

var t;
trace(Number(t));
// gives:
//   0   in Flash 6
//   NaN in Flash 7+

Just like:

var s;
trace(String(s));
// gives:
// in Flash 6
//   undefined in Flash 7+

That is, Number- and String-conversion of undefined was changed. So was 
String-to-Boolean-conversion (non-empty string are alwas true now) and 
null-to-Number-conversion (null is NaN, not 0) - at least those are the 
4 primitive datatype conversion changes that I remember :)


It was done in order to conform with the ECMAScript standard, yes. :)

--
Morten Barklund - Information Architect - Shockwaved
Gothersgade 49, 4th floor - DK-1123 Copenhagen K, Denmark
Phone: +45 7027 2227 - Fax: +45 3369 1174
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Newbie AS3 question

2005-10-31 Thread Morten Barklund Shockwaved

Andreas Rønning wrote:

[snip]


*Yawn* here we go again, another new guy trying to understand this 
OBVIOUS concept that we've been through so many times already. I

can't believe he's bothering us with this again!

[snip]


Sorry, I was in a bad mood due to other circumstances, had just 
explained the very same thing in some other fora, and it's another 
monday morning... :)


(though I truely fail to see, how that is a scandinavian trademark?)

I just saw your posting:


2. What the hell is going on with this here

class ParseXML{
private var xmlDoc:XML;
private function handleXML(){
trace(this);
}
function ParseXML(url:String){
xmlDoc = new XML();
xmlDoc.ignoreWhite = true;
xmlDoc.onLoad = handleXML;
xmlDoc.load(url);
}
}

trace this in this case traces out the xml doc. Is this because onLoad 
= handleXML declares the scope of handleXML as being the xmlDoc?
Sometimes the onLoad = functionReference; syntax weirds me out. I tend 
to go for the onLoad = function(){ more specific functionality here } method


And wanted to reply with an explanation - and the archives doesn't 
really give the mails their true position in the hierarchy with this 
many replies to replies and thus I really cannot see, if you've been 
given a proper answer.


Maybe I've misinterpreted your question from the above posting as 
stating a common question and not really asking it - are you? If so, 
disregard the below. Otherwise, consider the below my view of how things 
are actually interpreted. :)


this-references are dynamically evaluated. It is what i personally 
refer to as the activating scope and can as such be anything, that is 
pushed in to the function as the activating scope. The defining scope on 
the other hand cannot be changed.


Thus I can create a function that trace's this - no matter what this is:

var my_function:Function = function () { trace(this is +this); }

I can then apply it to - say - a movieclip:

my_movieclip.some_function = my_function;
my_movieclip.some_function();

I can also invoke it runtime with the movieclip pushed in as the 
activating scope:


my_function.call(my_movieclip); // or .apply() - which ever suits you

The XML-class will internally call the onLoad-function as (pseudo-code):

private function __dataArrived():Void {
// parse stuff, set status, do other stuff
this.onLoad(this.status == 0);
}

Thus it will call the onLoad-function with the XML-object itself as the 
activating scope.


Some suggest it been worked around using a local property of the 
surrounding object as:


class Test {
private var owner:Test;
private var xml:XML;
public function Test() {
owner = this;
xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = handleXML;
xml[owner] = local property of xml;
}
private function handleXML(success:Boolean):Void {
trace(I am Test: +(this instanceof Test));
trace(I am XML: +(this instanceof XML));
trace(owner is Test: +(owner instanceof Test));
trace(owner is XML: +(owner instanceof XML));
trace(What is owner then: +owner);
}
public function load(some_url:String):Void {
xml.load(some_url);
}
private function toString():String {
return some Test-instance;
}
}

But that will not work (as owner will be repaced with this.owner and 
will then point to the XML-instance-property and thus be a string).


Maybe someone suggests it being worked around using a static property 
(changing private var owner:Test to private static var owner:Test). 
Then it _will_ work (as owner is replaced with Test.owner when 
compiled), but then you can only have one instance simultanously - which 
may or may not be useful. At least not very pretty.


The defining scope can never be changed as explained. That is why the 
otherwise very used approach of:


class Test {
private var xml:XML;
public function Test() {
xml = new XML();
xml.ignoreWhite = true;
var owner:Test = this;
var callback:Function = handleXML;
xml[owner] = local property of xml;
xml[callback] = something not a function;
xml.onLoad = function() {
callback.apply(owner, arguments);
};
}
private function handleXML(success:Boolean):Void {
trace(I am Test: +(this instanceof Test));
trace(I am XML: +(this instanceof XML));
}
public function load(some_url:String):Void {
xml.load(some_url);
}
}

Now it works - and now callback and owner is read from the defining 
scope - and will always be the same. That is, we can copy this 
function to any object, invoke it using