FlashPlaya

September 19, 2008

as is your Friends

Filed under: AS 3 — Tags: — iBen @ 3:26 am

Remember type casting from as2?
Well, while they are not just yet things of the past, they have greatly been improved upon. as treats a current object in the noun sense of the word as in the same sense of the word you wish it to be. At some point in flash’s events that fire, calling currentTarget or target, simplify the object that passed through them. Because the flash player doesn’t know about your custom-type classes, it just recognizes your class when passed through events as regular objects. This is just one case in which as comes to the rescue. rather than typeCast parenthetically, which can go wrong depending on what you cast it into, use as followed by the Type you wish to treat the obj as.

ex: customClass:CustomClass(’loadTxt’)
customClass.addEventListener(Event.COMPLETE,onLoaded)

function onLoaded(evnt:Event){
trace(typeof(evnt.target)) //object
}

although the evnt.target points to a custom class, its no longer anything other than recognized as an object.
to prove that its an object we could say typeof(evnt.target) which will trace out object.
but lets say we need to now use evnt.target as an argument in a function that only accepts CustomClass as a type,
the compiler will throw an error, because evnt.target is not a CustomClass anylonger.
But we know this is a type CustomClass, cause we declared it above in instantiation. I could prove that it is with the use of the key word is. Kind of like instanceof which is deprecated in AS3 you can compare the object to a customclass and see if it returns the class or a null which means its not recognized as that class.

trace(customClass is CustomClass) // [CustomClass Object]
yay it is part of our custom class after all
trace(customClass is Object) //[object object] and its an object as well

What is actually doing is looking at the classes string of prototypes and checking to see if it has either inherited from the class in question or implemented it as an interface.

Still flash wont allow us to pass customClass into our function which only accepts CustomClass, types.

This is where as is a beautiful art. create a new var if you wish and set it to equal the event.target as CustomClass

var iknowCustom:CustomClass= event.target as CustomClass
Because event.target has CustomClass attached to its prototype, it allows it to be cast and now we can send iknowCustom as our argument param to the function.

Viola as is.

Also very useful when using getDefinitionbyClass()

September 17, 2008

Damn You Flash Metrics

Filed under: AS 3, SourceCode — Tags: — iBen @ 6:45 am

Its no surprise that Neither Macromedia or Adobe have corrected this one yet. Previously I created a Tag Cloud in flash and it was especially frustrating having to figure out text metrics on fonts at random sizes. See the problem is that the larger the font becomes in size, the more padding that is supplied by the text box both above and below. Text metrics will never be accurate. So I have written a class that you will use rather than just textField to create a textField that will automatically adjust to it’s exact pixel. I shit you not. Take a pic of it and measure it with photoshop. Anyhow, I am supplying you with my class and feel free to use it, but please leave my created by in the class out of respect. For more information on how to use it.. feel free to email me iben[@]flashplaya.net

Download ExactText

September 14, 2008

Hexadecimal

Filed under: AS 3 — iBen @ 5:16 am

Hexadecimal is generally the representations of color either 32 bit (ARGB) or 24 bit (RGB) but is in short the user friendly way to read Binary. Hexadecimal much like Binary, is based on its own sequence of digits and is a base of 16.
So what does base 16 mean for Hexadecimal? This means for each column 16^(exponent++)

Hexadecimal sequence makes use of the following digits 0123456789ABCDEF where A stands in for 10 and each letter therefore up to F, which stands in for 16. You can see how having to read 1 letter is easier to read than having to interpret 2 digits. Each digital unit in hex is made up of a nibble or (4 bits) This is because a in binary if all 4 digits are on (being 1) we would have 8 + 4 + 2 + 1. where 15+1 is the radix of 16. A radix is a number that can be the highest visible number per column. On our base 10 decimal system, 10 is the radix, and its representation of the radix is 9 before it becomes the next column.

So lets randomly choose a hex value. 0xff34cd ok first lets understand what this means. f as we know stands for 15. 3, and 4 are both 3 and 4. And c is 12 and d is 13. If we wanted to turn this value into a decimal we could easily knowing the information we just stated and have each value multiply(16^column it came from)
15*(16^5)+15*(16^4)+3*(16^3)+4*(16^2)+12*(6^1)+13*(16^0) or we can turn this into binary by splitting the hex into groups of 2’s.

ar:Array = new Array()
ar[0]=0xff
ar[1]=0×34
ar[2]=0xcd

ar[0] we know is 15^(16^1)*15 or 255 is the largest value that can be created from 2 hex digits. Knowing that 1 hex digit is represented by 4 bits,
we can take a look at our binary chart 8 | 4 | 2 | 1 . You can see that if all these values are turned on they will add up to 15: 1 | 1 | 1 | 1 8+4+2+1=15 therefore F = 1111 in binary. so FF would be 1111+1111
we could have also done is in longer manner than [128 | 64 | 32 | 16 ][| 8 | 4 | 2 | 0]
What numbers can we add up to make 255 1 1 1 1 1 1 1 1
128+64+32+16+8+4+2 = 255 or again in binary 11111111

So of course 34 should be a sinch. 8 | 4 | 2 | 1 8 | 4 | 2 | 1
0 0 1 1 makes 3 0 1 1 1 makes 4

So binary of 34 is 00110111

and cd or decimal 12*(16^1) + 13*(16^0) is lets do it the long way 205. Try to figure out what 205 in binary looks like on your own.

You can see how viewing Hexadecimal is much easier to read than binary but stands for the same thing.

You might be saying to yourself right now. Well now that I know what
ar[0]=0xff =255
ar[1]=0×34 = 52
ar[2]=0xcd = 205

stand for, how do those values for each index create the full binary value? Simple because i showed you earlier that each column stands for a representation of bits in this case 16 each column increases by 16^(column++) so with bit shifting we can see how to turn 0xff + 0x 34 + 0xcd into its full binary value. Hexadecimal is a great way of converting between int and uint. Its just a matter of how you use the binary at hand.

September 8, 2008

Lesser known factoid regarding Tween

Filed under: AS 2 — Tags: — iBen @ 5:12 pm

A friend of mine, whenever having to tween a clip, no matter if a tween has already been established or not for that item, would always create a new tween to get his clip to do what was needed.

Much like in AS3, you can reset a few properties on the tween rather than having to kill it and create a new one.

For example:

var tweenVariable:Tween = new Tween(clip,’_x’,Regular.easeIn,0,100,2,true)

this is how we set up a tween right? but now, if i want to see if tweenVariable exists and if it does to change its ease or time i could do so easily with the continueTo concept.

Due to AS2 semi oop, properties that are within the class can be see externally.
So properties of the tween such as _obj, _duration, _func, _finished, _prop, _position, _begin, can all be retargeted. I use my tweens in an object and if that object exists, I call that object and .stop() change out it’s properties then .start().

Binary Data

Filed under: AS 3 — Tags: , , , — iBen @ 5:14 am

It’s no secret that majority of flash programmers are not graduates of a computer science, but rather hobbyists who saw opportunity in a world with a demand for RIA. Keith Peters has a nice post on is intro to flash here

Well I won’t bore you with my beginnings into flash but, because we are not compu-sci majors, we missed out on a few basic principals which will be needed in the future of flash and this post is the beginning of a few of those aspects.

I have spent much time researching these areas and recommend that you look into them as well because they will continue to be in each flash package continuing on.

I will continue to explore bit shifting and hexadecimal and how they relate to one another in a later post which will address the ways in which Byte Array will come in handy. But for now, Binary Data:

Binary as we all know is the language of the computer.
Everyday we sit in front of our computers, the programs we use utilize the combination of 1’s and 0’s and turn those combination into a different language in which we can understand. Such languages I’m speaking of are Unicode, hexadecimal, Decimal and ASCII. These are all languages I will explain in individual blogs how they relate to binary and the AS3 Byte Array.

Each previously stated language has its own base number in which bytes are arranged to define how to use the combination of bytes to represent some form of data.

Binary is a base 2 also stated as Binary has a radix of 2. The 1’s and 0’s i spoke of earlier. Every use of a 1 or 0 is exactly 1 binary digit information known as a bit. 4 bits make up what is known as a nibble, and 2 nibbles make up 1 byte. OK so we learned a lot of gibberish so far.

So what does base 2 really mean? Well lets begin with our own decimal system to explain how base to effects binary.

In our decimal system, we count as accurately to the tens place. as can be seen in this number 4. 4 is a value 0-9 in the 1’s place of our decimal system. If i were to say 24, 4 is still in the 1’s place and 2 is now in the 10’s place. so 4 is really the same Number as (10^0)*4. and the 2 in the 24 is no different than 2*(10^1).
And to put it all together is to say that 24 = 2*(10^1) + (10^0)*4.

OK so really base 10 just means that since we count from 1-9 per column, every time our number moves into the next column , that is the same as notating 10^(exponent++)

Keeping with that mindset, base 2 is the same thing only with 2 in place of 10. 2^0, 2^1, 2^2. And when we do this we find that we don’t get tens hundreds thousands quite so early on.. but rather 1, 2, 4, 8, 16, 32, 64, 128, 256, etc, but just as our number system increases to the left, so does binary so 1,2,4,8 should really be written as thus. 8 4 2 1.
These 4 bits is what is known as a nibble.

That is the binary number system.

Older Posts »

Powered by WordPress