Az Expattech az ünnepek alatt (dec.24-jan.1.) zárva tart. Nyitás: 2024.január 2

ExpatTech Techblog - Flash

Peter Todd 2011.01.17. 12:06

Flash Cookbook - Tricks - Conditional chains

 


Peter Todd 2011.01.17. 11:52

Flash Cookbook - Tricks - Shortening code

 

This trick is about shortening actionscript code.

Peter Todd 2010.10.28. 14:25

Flash Cookbook - CSS - CSS parser, parsing CSS StyleSheet and Style

Even though Flash has a built-in css parser, still it's not the best one. After running some tests it came out, it does not really support a lot of things. For example you can't use hyphen in declarations, nor you can use spaces in selectors.

These things are needed for our work, therefore the only way left is to write our own parser. In this post we write the basics - think it through, take it further and you will get a nice and handy class for your own.

Plus, the StyleSheet.parseCSS() method does not support styles not surrounded by curly brackets. This is what you can use in the attributes of an xml-tag: style="font-size: 15px". This wouldn't be understood by the built-in parser.

Peter Todd 2010.10.08. 10:31

Flash Cookbook - Tricks - Super size bitmap, bitmapdata, infinite size

Today I ran into a problem. As we all know, Flash has a size limit on bitmapdata size.

Basically there are two rules to follow (see the specs):

Both the width and height has to be maximum 8,191 pixels

and

the amount pixels of the bitmapdata cannot exceed 16,777,215.

Well, well, well...

Peter Todd 2010.10.01. 10:49

Flash Cookbook - Tricks - Store data in bytearray and compress it

You can create a nice little drawing application using the flash graphics tools. Let's say you created an application, where you press the mousebutton, start to draw and draw lines by holding the button down. Every point your mouse reached is stored in an array at an ENTER_FRAME event.

This way I did a hand-drawn rectangle, consisting 36 points. If you want to save this drawing point by point, you save this array in the SharedObjects or send it to a server-side script to save it somewhere on the server.

Peter Todd 2010.10.01. 09:01

Flash Cookbook - Colors - Part 2. Invert Displayobject's Colors

To invert the colors of a displayobject you can use the transform.colorTransform property of the displayobject and apply a ColorTransform to it.

Peter Todd 2010.09.30. 14:15

Flash Cookbook - Appendix - Practical XML - Something to know

Today I used the flash in-built xml capability for designing an xml:

var xml:XML = <data><obj>0</obj><obj>1</obj></data>;
trace(xml["obj"][1]); //outputs 1

when I arrived to a point, where I commented an item out:

var xml:XML = <data><obj>0</obj>/*<obj>1</obj>*/</data>;
trace(xml["obj"][1]); //outputs 1

Hm, I thought, what happened here (okay, for five minutes I didn't know what to do), I thought the flash miracoulusly cached my xml and loaded it from somewhere but not the IDE. Then came the hit: even though you think you've commented the part out, it didn't delete it from the xml. Of course if you want to comment this out, you need the standard notation.

var xml:XML = <data><obj>0</obj><!--<obj>1</obj>--></data>;
trace(xml["obj"][1]); //outputs undefined

But then what happens if you use the IDE's comment notations?

var xml:XML = <data><obj>0</obj>/*<obj>1</obj>*/</data>;
trace(xml);

Surprisingly outputs:

<data>
  <obj>0</obj>
  /*
  <obj>1</obj>
  */
</data>

and

var xml:XML = <data><obj>0</obj><!--<obj>1</obj>--></data>;
trace(xml);

outputs:

<data>
  <obj>0</obj>
</data>

Yes, xml takes whatever /**/ as a piece of the content. It doesn't matter, that you are working with flash in a flash IDE, it won't be a comment in your code if you use the XML type and its advantages (though we don't know the advantages of this initialization). Use the rules of XML in an XML type.

Peter Todd 2010.09.27. 14:22

Flash Cookbook - Appendix - Sort array indices

Yes. This is about array sorting. So there is the problem, that we want to sort an array, but want to know more about the indices. For this reason there is an option for Array.sort() function, which specifies the return value of sort():

Array.RETURNINDEXEDARRAY.

See the code below:

var array:Array = ["a", "c", "b"];
var sort:Array = array.sort(Array.RETURNINDEXEDARRAY);
trace(array, sort);

//a,c,b 0,2,1

It didn't sort the array, but returned an array with the sorted indices.

Peter Todd 2010.09.24. 10:10

Fun with Random - Part 2.

In the second part we create a static class for our random function, add a practical function and check whether it is really random.

Peter Todd 2010.09.23. 15:49

Fun with Random - Part 1.

Are you tired of the old randomgenerators? Here is a basic solution for creating your own.

Peter Todd 2010.09.23. 14:43

Flash Cookbook - XML - Practical XML

Practical and basic usage of the Extensible Markup Language in the Flash environment.

Peter Todd 2010.09.23. 12:59

Flash Cookbook - Tricks - Realistic Drag Simulation

Everybody has a dream about a world, where are no boundaries and everything is possible. This post is not about this dream, but asks some questions about Drag And Drop and how this event occurs. It also shows an alternative method on how things can be different.

Peter Todd 2010.09.23. 11:59

Flash Cookbook - CSS - Use CSS to design flash

Using Css for styling flash content? Is this possible? Yes it is, a good question would be "but why would I use css for this?". Even though this would be a good question, but still, it is possible, so we have to write about it. Also it is an external file, so is usable after compiling the flash movie, also a popular format, so people might be familiar with it. Sit back and enjoy the power of CSS and FLASH. This might be the beginning of a new technology. NOT!

Peter Todd 2010.08.03. 14:53

Flash Cookbook - Tricks - Global functions

Previously we wrote about global variables.

Going further, sometimes it's really useful to reach a certain function from a child of the child of the grandchild's child. Especially if we want to reach different functions from different objects. Imagine you have a url request in a certain object, and a sharedobject request in another, but somehow you need to reach both in a completely innocent small object somewhere in the depth of the jungle of the objects.

Peter Todd 2010.08.03. 14:09

Flash Cookbook - Tricks - Global variables

Sometimes it's useful to use global variables. In AS3 it's quite easy: you create a class and add static variables to it.

Peter Todd 2010.03.25. 14:06

Flash Cookbook - Appendix - Throwing errors

Why is it good for me? - asked the young padawan (YP).

See the reason of the problem, you will - answered the wise master (WM).

WM: Count 16 errors, we can. Easy to use, it is. Example, here is:

var error:Error = new Error('This was an error, my young padawan.');

and to call for this you do:

throw error;

YP: but what does this do, master?

WM: pops up a window with an errormessage, this.

YP: I see.

Peter Todd 2010.02.01. 13:22

Flash Cookbook - Optimisation - Number types used for loops

In this section we will examine the speed of loops with the three number types.

Peter Todd 2010.01.29. 15:26

Flash Cookbook - Geometry - Fine tuning Point class Part 3. Angle.

"Dear Master,

if I can create a Point using the Point.polar() method, why on earth can't I reuqest the angle of a Point? Please answer me, you are my only hope.

The Little Grasshopper"

Peter Todd 2010.01.29. 14:21

Flash Cookbook - Geometry - Fine tuning Point class Part 2. Length.

Okay. Here we are with the second question. Can we fasten the request for length? - asked the little grasshopper.

Yes, we can. The result is a 15% speedup.

Peter Todd 2010.01.29. 13:45

Flash Cookbook - Geometry - Fine tuning Point class Part 1. Distance.

Point class is not a final class therefore we can extend it. To do this is quite useful because the main functions of points are in the package so you don't have to rewrite them. But still there are some extra things what you can override to get better results concerning speed.