StageExt Class: resizable in Flash movies

The technique of Fullsize (antechamber for Fullscreen - of which more later) was, until recently, mainly used in Flash applications (RIAs), then composed by a more or less complex user interface, where the container (Adobe AIR , Browser or the stand-alone player) resized by the user, forced to reposition the objects composing the movie. The downsizing of the container obviously follows a design tool or Refresh able to reposition the MovieClip or redesign the interface in runtime to the new size of the container. Today, this technique is also used in the most advanced websites or articulated only, making the interface more but extremely appealing. The implementation of this technique is quite simple and uses essentially the Stage object native and introduced with Flash MX version. For its implementation here is a class that allows you to get the coordinates of the Stage :

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/ **
*
* @ File StageExt.as
* @ Author Giovan Battista Fazioli (g.fazioli @ undolog.com)
* @ Web http://www.undolog.com
* @ @ Email g.fazioli undolog.com
* /
class {StageExt
/ / Release
__release : String = "1.0" ; private var __ release: String = "1.0";
/ / Properties
__movieWidth : Number = 0 ; private var __ movieWidth: Number = 0;
__movieHeight : Number = 0 ; private var __ movieHeight: Number = 0;
__left : Number = 0 ; private var __ left: Number = 0;
__right : Number = 0 ; private var __ right: Number = 0;
__top : Number = 0 ; private var __ top: Number = 0;
__bottom : Number = 23 ; private var __ bottom: Number = 23;
/ /
w : Number , h : Number ) { StageExt function (w: Number , h: Number ) {
"StageExt::constructor" ) ; trace ("StageExt :: constructor");
/ /
__movieWidth = w;
__movieHeight = h;
/ /
addListener ( this ) ; Stage . addListener (this);
}
/ **
* OnResize () event
* /
onResize ( ) { onResize private function () {
"StageExt::onResize " + Stage . width + ", " + Stage . height ) ; trace (":: StageExt onResize" + Stage . width + "," + Stage . height);
/ /
Number = Math . round ( Stage . width ) ; var sw: Number = Math . round ( Stage . width);
Number = Math . round ( Stage . height ) ; var sh: Number = Math . round ( Stage . height);
Number = Math . round ( this . __movieWidth ) ; var w: Number = Math . rounds (this. __ movieWidth);
Number = Math . round ( this . __movieHeight ) ; var oh: Number = Math . rounds (this. __ movieHeight);

/ / The x coordinate (top left)

__left = - Math . floor ( ( ( sw - ow ) / 2 ) ) ; this. __ left = - Math . floor (((sw - w) / 2));
__top = - Math . floor ( ( ( sh - oh ) / 2 ) ) ; this. __ = top - Math . floor (((sh - oh) / 2));

/ / The x coordinate (top right)

__right = Math . round ( ( sw + ow ) / 2 ) ; this. __ right = Math . round ((sw + w) / 2);

/ / The y coordinate (bottom)

__bottom = Math . round ( ( sh + oh ) / 2 ) ; this. __ bottom = Math . round ((sh + oh) / 2);
}
/ **
* Refresh ()
* /
Refresh ( ) { public function refresh () {
onResize ();
}
/ **
* Left - get
* /
get Left ( ) : Number { public function get Left (): Number {
__left ) ; return (__ left);
}
/ **
* Top - get
* /
get Top ( ) : Number { public function get top (): Number {
__top ) ; return (__ top);
}
/ **
* Right - get
* /
get Right ( ) : Number { public function get Right (): Number {
__right ) ; return (__ right);
}
/ **
* Bottom - get
* /
get Bottom ( ) : Number { public function get Bottom (): Number {
__bottom ) ; return (__ bottom);
}
/ **
* MovieWidth - get / set
* /
get MovieWidth ( ) : Number { public function get MovieWidth (): Number {
__movieWidth ) ; return (__ movieWidth);
}
set MovieWidth ( v : Number ) { public function set MovieWidth (v: ​​Number ) {
__movieWidth = v;
}
/ **
* MovieHeight - get / set
* /
get MovieHeight ( ) : Number { public function get MovieHeight (): Number {
__movieHeight ) ; return (__ movieHeight);
}
set MovieHeight ( v : Number ) { public function set MovieHeight (v: Number ) {
__movieHeight = v;
}
}

Through this class becomes simple reposition MovieClip inside the Stage :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
StageExt = new StageExt ( 320 , 256 ) ; if var: = new StageExt StageExt (320, 256);
/ /
scaleMode = "noscale" ; Stage . scaleMode = "noscale";
addListener ( this ) ; Stage . addListener (this);
/ /
prototype . move = function ( x : Number , y : Number ) { MovieClip . prototype. move = function (x: Number , y: Number ) {
_x = x ; this . _y = y ; this. _x = x; this. _y = y;
}
/ /
onResize function () {
"Custom Resize " + this + " - " + se . Left ) ; trace ("Custom Resize" + this + "-" + if. Left);
/ / Clip_mc._x = se.Left;
/ / Clip_mc._y = se.Top;
se . Left , se . Top ) ; clip_mc. move (if. Left, though. Top);
}

In the example the size of the Stage originals are 320 × 256. These should be included and considered as Flash mode noScale centers movie within the browser. ; OBJECT ed EMBED . Also in the HTML code must be set as 100% size, you open the width for the ' heght ; OBJECT and EMBED .

You also have to organize the hierarchy of the MovieClip in a timely manner and always consider that the position of a MovieClip diventra now "relative".

3 comments to: ""

  1. December 12, 2007 undolog »Blog Archive» Fullscreen Flash in the browser :

    [...] The code to set the fullscreen is very simple and takes advantage of the Stage object discussed on this blog in StageExt Class: movies resizable in Flash: PLAIN TEXT Actionscript: [...]

  2. December 14, 2008 Larry:

    Hello,
    one question: where should I put these 2 scripts?

    Thank you,
    G.

  3. December 15, 2008 Giovan Battista Fazioli :

    @ Larry:

    Hello,
    one question: where should I put these 2 scripts? Thank you,
    G.

    The first "source" is a class that you can enter at any point in your code through education include . The second source is an example of its use. See Actionscript 3.0 for beginners: lesson # 1 on how to set up a simple project in Flash.

Leave a comment

TAG XHTML PERMITS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> CODE ENTRY:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL