Category 'Flash'


Actionscript 3.0: public, protected, private, and internal

With AS3 have introduced new "instructions" to define properties and methods (public or private). si comportava in AS2 come ora si comporta protected , in AS3 private è davvero “privata” !) proprio a causa dell'introduzione di una sintassi più OO rispetto alle precedenti versioni. Some, such as private - already present in AS2 - changed behavior ( private behaved in AS2 behaves like now protected in AS3 private is really "private"!) just because of the introduction of an OO syntax than previous versions . Better outline, then, from the "public" at most "private":

  • public
    everyone can access it
  • protected
    you can access the parent class and subclasses
  • Private
    only the class that defines
  • Internal
    only within the same package

Continued ...

Very short snippet: cutString ()

Convenient and quick! With the values Number of Actionscript, for example, is an essential aid to the "print" on the screen.

1
2
3
4
5
6
7
/ *
** @ Name: cutString ()
** @ Description: Cut a string for n chars
* /
cutString ( s : String , v : uint = 4 ) : String { cutString protected function (s: String , v: uint = 4): String {
s . length > v ) ? s . substr ( 0 , v ) : s ) ; return ((s. length> v)? s. substr (0, v): s);
}

Often I use it also in sub() and _s()

Continued ...

Flash CS3: Create a reflex effect on any MovieClip

Taking advantage of a remarkable feature of Actionscript 3.0 (see ActionScript 3.0, all with the new operator ) I created a class ReflexMe able to generate an effect "reflection" on any MovieClip present in the library.

Loading Flash ...

The source is part of the package undolibrary - GoogleCode of this - but if you want you can download the single file ReflexMe.as .

Continued ...

Effects on the bitmap with perlinNoise ()

The class BitmapData allows you to easily apply effects useful for various purposes. We have already seen how to create a "fog TV" with a few lines of code ( Flash CS3 to create fog effect TV in 1 second ). Now we will deal with another effect "spectacular" which, as we shall see later, allows the creation of interesting visual effects, as in the example shown below: the parameters varied to observe the different effects, clicking the mouse on the image generated This can be moved.

Loading Flash ...

On this occasion I also added a new simple component (Check) in Undolibrary ! So update your SVN repository. The source is available here: MapEffect.zip

Continued ...

The arithmetic module

The "module" is one of the aritmentiche available on almost all programming languages (I used it the first time with the Basic Commodore 64) . May appear as a simple operator, as in the case of Actionscript or Javascript, which both use the character "percent" (% b), or as a method or instruction. For developers may be useful in contexts apparently different. Gskinner spoke recently, showing some classic but interesting examples.

Put simply, the operation returns two numbers form the rest of their division. For completeness, we say that the operation of the module is a very broad topic, which I discussed in the RSA encryption ! This time, however, not talk of codes or ciphers, but useful things much simpler.

Divisible by alternating ...

The first use we can make the operation of the module is to determine whether a number is divisible by a number b! If the risultatto of a% b (% I will use here the notation to indicate the operation of the module) is zero, a is divisible by b. I remember when I had to do with a problem like I did not know the operation of the module. On the Commodore 64 I needed to know if a number was divisible by 2. At the time I used this syntax (I found the code origionale - year 1983):

1
2
3
10 INPUT A
12 B = A / 2: IF B = INT (B) THEN PRINT "OK THE NUMBER" A "AND 'EQUAL": GOTO 10
14 PRINT "THE NUMBER" A "AND 'ODD": GOTO 10

The BASIC of the Commodore 64, however, did not have the operation module - at least that I remember!

Basically exactly what I was doing that by its nature makes the operation of module: 2 verified that the division had no rest, in this case, check that the result did not contain decimal ( IF B = INT(B) )! If the division operation is equal to its full, then the number is equal!

If a have our value to be tested, the same thing can be resolved by:

1
2
3
a % 2 ) == 0 ) { if ((a% 2) == 0) {
/ / Even
}

Or, for 3, by:

1
2
3
a % 3 ) == 0 ) { if ((a% 3) == 0) {
/ / Divisible by 3
}

Small note: thanks to the track if you have to do with the powers of 2 annche there a faster way to check whether a number is odd or even. In binary notation, in fact, the numbers are all equal to zero the first bit! Thus, using the logical operators, you can know whether a number is odd or even simply "Protestant" the first bit:

1
2
3
! ( a & 1 ) ) { if ((a & 1)) {
/ / Even
}

In the Assembly, for example, this is bread and butter! It is even more immediate and simple (the Motorola 68020, for example, had an instruction BTST that "tested" just a single bit ;) ). – moltiplicazione bit a bit) tra il nostro valore a e 1 (chiamato maschera ). The logical operations (AND, OR, NOT, XOR, etc ...), in fact, are known to be faster in terms of run, and then "time machine"! (a & 1) performs the logical operation of AND ( & - Multiplication bitwise) between our value a , and 1 (called mask). If a = 7 (00000111), for example:

1
2
3
00000111 AND
= 00000001
00000001; odd

If a = 8:

1
2
3
00001000 AND
= 00000001
00000000, equal

Not only can we check the numbers, that is, with the first bit to 0, and therefore divisible by 2, but can also occur if a number is divisible by 4, 8, 16, 32, 64, etc ... using the appropriate forms:

1
2
3
! ( a & 3 ) ) { if ((a & 3)) {
/ / Divisible by 4 (mask = 00000011 = 3), since 4 is 00000100)
}

If the last two bits are set to zero the number is divisible by 4! If the last 3 bits (mask 00,000,111) are to zero the number is divisible by 8! And so on :)

Gskinner shows the use of the module in cases of alternate generation of values. A classic example is to change the background of a list of items: a white and a gray. Gskinner offers:

1
2
3
4
5
rowIndex % 2 == 0 ) { if (rowIndex% 2 == 0) {
rowColor = 0xFFFFFF;
{ Else {}
rowColor = 0xCCCCCC;
}

First of all, the code above can be solved with a single line of code:

1
2 == 0 ) ? 0xFFFFFF : 0xCCCCCC ; rowColor = (rowIndex% 2 == 0)? 0xFFFFFF: 0xCCCCCC;

Moreover, in this specific case, I would avoid actually perform a "heavy" form of operation. This particular situation is often engaged in a loop, so it would be "good" not to waste clock cycles the machine. In these cases I like the cleanest (and logical) solution:

1
fooIndex == false ) ) ? 0xFFFFFF : 0xCCCCCC ; rowColor = (fooIndex = (fooIndex == false))? 0xFFFFFF: 0xCCCCCC;

o false , a seconda di come vogliamo impostare inizialmente il nostro colore sfondo. Where fooIndex precedentemete is a value set to true or false , depending on how we initially set our background color. This approach is more subtle, less immediate, at first, but faster because it performs logical true / false. la condizione (fooIndex == false) sarà falsa e di conseguenza fooIndex verrà impostato da true a false. If fooIndex is true, when the statement is executed (fooIndex = (fooIndex == false) ) the condition (fooIndex == false) is false and consequently fooIndex will be set from true to false. verrà impostato da false a true! The second time, however, the condition (fooIndex == false) is true and then fooIndex is set from false to true! And so on ...

Repetitions: to watch the behavior

The finite arithmetic, which is the basis of the functioning of the operation of the module, it is often referred to as clock arithmetic. A classic timepiece has a dial with hands divided into 12 hours (12 plus 12 day night!), Sufficient to indicate any one of 24 hours a day. At 08:00 AM If I asked you what time your watch will score between 18 hours, your answer would be 8 +18 = 26! But the 02:00 at night! Involuntarily and without knowing it, perhaps, perform operations conitnuamente form whenever we are dealing with times.

In Italy we are used to the system 24 hours (or mixed). When we point to 16:00 intend that hour than in other countries is indicated as 04:00 pm. Who uses the postfix am / pm to distinguish from those ofa night hours, even more often performs the operation of the module, module 12 in this case! We Italians, and others, however, being accustomed to consider the 24 hours, perform operations with Form 24!

When I'm 11 in the morning (11:00 for all) and think "in 5 hours", the Italians respond 5 +11 = 16 (four in the afternoon), a stranger could also answer 5 +11 = 4 pm. Since 5 + 11 classical arithmetic, is obviously 16, as did the stranger to meet 4 pm? He simply run the module 12 on the result: 5 + 11 = 16 mod 12 = 4. It is not necessary that you take a calculator to verify the accuracy of the calculation, but these steps are a bit 'all, displayed a face of a clock and place the hands on the 11 mentally, then add - always visually - 5 hours, such as if by magic you'll actually about 4! That's why they are called the four in the afternoon 16 :)

In Italy, instead, we use a Form 24, in fact: 11 +5 = 16 mod 24 = 16. When I am to 23:00 pm, 5 hours after the 28:00 will not be, because 28 modulo 12 = 4! 122514884225 Form 24 = 17! What happens is that the key result of the Form 24 will never exceed 24. But the most interesting thing is that the numbers are repeated indefinitely:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1% 24 = 1
2% 24 = 2
3% 24 = 3
...
22% 24 = 22
23% 24 = 23
24% 24 = 0
25% 24 = 1
26% 24 = 2
27% 24 = 3
...
48% 24 = 0
49% 24 = 1
50% 24 = 2
51% 24 = 3
...

This repetition is a disarming ease. Imagine, for example, they should have an object, a MovieClip, similar to a chessboard, in four columns. Create a MovieClip quandrato, 55 × 55 pixels and the properties panel esportiamolo as Simbolo . The following code will have four columns of our MovieClip and will "head" with the operation of module:

1
2
3
4
5
6
7
Number = 4 ; var col: Number = 4;
var i= 0 ; i < 12 ; i ++ ) { for (var i = 0; i <12; i + +) {
Sprite = new Simbolo ( ) ; var s: Sprite = new Symbol ();
s ) ; addChild (s);
= ( i % col ) * 60 ; s. = x (with i%) * 60;
= Math . floor ( i / col ) * 60 ; s. y = Math . floor (i / col) * 60;
}

cresce in modo indefinito. As you can see from the code, the variable i cycle for growing indefinitely. But the coordinate x of our MovieClip never exceeds a certain value, and repeats indefinitely! Here is a concrete example:

Loading Flash ...

Through the two knobs you can vary the number of columns (the form) and the total number of elements, using the algorithm above.

Continued ...

Papervision3D: BasicView

Papervision3D 2.0 (GreatWhite) is still developing and there are many functions that are added almost weekly. In April, was inaugurated on the developer blog ( http://dev.papervision3d.org/ ), however, release 2.0, is not officially released yet is often hard to snatch the true potential. One of the recent innovations introduced, however, is the new object BasicView an environment that creates 3D with very few lines of code. It is enough to create this object to have the scene, viewport and camera in one fell swoop.

Continued ...

undolibrary: Actionscript 3.0 library on Google Code

I opened a project on Google Code : undolibrary. For now, this library contains only one component (Knob - knob) to be used with Actionscript 3.0. I mention this because this component is a prerequisite to a series of tutorials / sources in Flash that I wanted to make available.

Loading Flash ...

Google Code

First of all I introduce the concept of Google Code for those who were foreign. Google Code is a free service provided by Google in order to share code, but, above all, to share and collaboratively with a versioning system (subversion) and wikis useful to development teams (primarily open source) or to individual programmers. On the Google Code site include:

You can search for other projects, with a purpose-built search engine. Many development groups, made up of teams that are located in distant geographical areas, taking advantage of this sharing to work together, backed by a well established versioning system (checkout / checkin not to overlap or supprot to create branch - spinoff projects) . Libraries and tools such as Papervision3D , Tweener or AS3corelib , for example, are located right on Google Code enjoying one side of a host of other development and public access to download the source and documentation.
Important point, then, is the possibility - open a project - to set access and viewing. If you want to protect your work or make it completely private rather than public.

Continued ...

Creating custom events in ActionScript 3.0

Creating custom events in ActionScript 3.0 is simple. Use them, then, allows you to use the method addEventListener() and make our object of all standards. ) BottoneEvent . If we created a class, such as Bottone , this is correct to associate with one or more events through a special class (derived from the class Event ) BottoneEvent . We could make all the events that affect the operation of our subject: the click, mouse over, or any other event! As well as defining our personal basis. The skeleton - generic - a custom event class is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package {
/ *
** @ Name: BottoneEvent.as
** @ Description: Class derived from Event to manage their own custom event
** @ Author: undo = =
** @ Web: http://www.undolog.com
** @ Email: @ g.fazioli undolog.com
* /
.*; import flash.events .*;

BottoneEvent extends Event { BottoneEvent extends public class Event {

String = 'pluto' ; // codice qualsiasi, anche 'mioevento' in minuscolo public static const MIOEVENTO: String = 'bar', / / any code, even 'mioevento' in lower case

Valore : Number = NaN ; public var value: Number = NaN;
/ *
** @ Name: BottoneEvent
** @ Description: constructor
* /

type , bubbles , cancelable ) ; super (type, bubbles, cancelable);
Value = v ; this. Value = v;
}

/ *
** @ Override
* /
clone ( ) : Event { override public function clone (): Event {
this . type , this . Value , this . bubbles , this . cancelable ) ; KnobEvent return new (this. type, this. Value, this. bubbles, this. cancelable);
}
}
}

Continued ...

FIVe3D: effects of a cube! Waiting for Flash 10

Most likely, when it comes out the new version of Adobe Flash, 3D libraries to "low level" as FIVe3D will end up badly! However, before the "Trash", here is an example of what can be achieved (with the latest release 2.1):

Loading Flash ...

The code of the demo above is quite articulate, so I do not propose entirely online. Insertion, however, some interesting pieces of code.

Update: for the source click here

Continued ...

Adobe Flash Player 10 beta released and Google Maps API

Update: see How to use Google Maps in Adobe Flash CS4

Update: it seems that Google is wrong and instead of writing Flex wrote Flash! Moral of the situation, the Google Maps API has been released only for Flex and Flash do not work in the environment: a demonstration of the confusion that these two "branches" (Flex / Flash) are causing! Read in this connection, it damn google get it right! the google map API for Flex is not Flash!

Continued ...