ActionScript learning: AS-written scroll
Related Tags:
Two weeks before taking the time to see saw no time has been very interested in the study of XML and graphics API
Feel that we did not imagine before so mysterious:)
Spent three're happy with the time to write this AS1.0 pure AS XML rolling, it counted as exercise.
Please master exhibitions!
Below are all the AS code:
Since the definition of //%%%%%%%%%%%% MC method %%%%%%%%%%%%//
//------ Mapping method ----//
/ / Triangulation method
MovieClip.prototype.sanjiaoxing = function (zuobiao1, zuobiao2, zuobiao3, bangzhi, yanse, toumingdu) (
This.lineStyle (bangzhi, yanse, toumingdu);
This.moveTo (zuobiao1.x, zuobiao1.y);
This.lineTo (zuobiao2.x, zuobiao2.y);
This.lineTo (zuobiao3.x, zuobiao3.y);
This.lineTo (zuobiao1.x, zuobiao1.y);
);
/ / Width of rectangular high, according to the initial point coordinates and identify high and wide rectangular. X, y coordinates for the initial point, and gao kuan rectangular wide and high.
MovieClip.prototype.changkuanjuxing = function (x, y, kuan, gao, bangzhi, yanse, toumingdu) (
This.lineStyle (bangzhi, yanse, toumingdu);
This.moveTo (x, y);
This.lineTo (x kuan, y);
This.lineTo (x kuan, y gao);
This.lineTo (x, y gao);
This.lineTo (x, y);
);
/ / Center rectangular law, according to the center coordinates and identify high and wide rectangular. X, y coordinates for the center, kuan, gao to the length and width of rectangular.
MovieClip.prototype.zhongxinjuxing = function (x, y, kuan, gao, bangzhi, yanse, toumingdu) (
This.lineStyle (bangzhi, yanse, toumingdu);
This.moveTo (x-kuan / 2, y gao / 2);
This.lineTo (x kuan / 2, y gao / 2);
This.lineTo (x kuan / 2, y-gao / 2);
This.lineTo (x-kuan / 2, y-gao / 2);
This.lineTo (x-kuan / 2, y gao / 2);
);
//---- Positioning methods ----//
MovieClip.prototype.dingwei = function (x, y) (
This._x = x;
This._y = y;
);
//---- Color method ----//
/ / Define a color value access, and bring it into the 16-band function
/ / Value of the acquisition after six colors, so that this method can meet the "# FFFFFF" and "0 xFFFFFF" the color of the two formats
Function jinzhizhuanhuan (yansezhi) (
Var yansezhi yansezhi.substr = (6, 6);
Return parseInt (yansezhi, 16);
)
Color.prototype.shangse = function (yansezhi) (
This.setRGB (jinzhizhuanhuan (yansezhi));
);
MovieClip.prototype.shangse = function (yansezhi) (
Var linshi_color = new Color (this);
Linshi_color.shangse (yansezhi);
);
//%%%%%%%%%%% Loading XML documents %%%%%%%%%%%%%//
Gundongtiao_xml = new XML ();
Gundongtiao_xml.ignoreWhite = true;
Gundongtiao_xml.load ( "gundongtiao.xml");
Gundongtiao_xml.onLoad = function () (
Var jiedianlujing_xml = gundongtiao_xml.firstChild.childNodes;
/ / Rolling parameters of the background
With (jiedianlujing_xml [0]) (
Var gundongtiaobeijingse = jinzhizhuanhuan (attributes [ "background color"]);
Var gundongtiaotoumingdu = attributes [ "background transparency"];
Var gundongtiaobiankuangse = jinzhizhuanhuan (attributes [ "frame color"]);
Var gundongtiaobiankuangtoumingdou = attributes [ "Borders transparency"];
Var gundongtiaobiankuangcuxi = attributes [ "frame size"];
Var gundongtiaokuan = attributes [ "lenient"];
)
/ / Parameter box
With (jiedianlujing_xml [1]) (
Var fangkuaibeijingse = jinzhizhuanhuan (attributes [ "background color"]);
Var fangkuaitoumingdu = attributes [ "background transparency"];
Var fangkuaibiankuangse = jinzhizhuanhuan (attributes [ "frame color"]);
Var fangkuaibiankuangtoumingdou = attributes [ "Borders transparency"];
Var fangkuaibiankuangcuxi = attributes [ "frame size"];
)
/ / 1.30 parameters
With (jiedianlujing_xml [2]) (
Var sanjiaoyuanshise = jinzhizhuanhuan (attributes [ "original color"]);
Var sanjiaohuodongse = jinzhizhuanhuan (attributes [ "color"]);
/ / Record of the original color and color activities, and to prepare "," "" the use of button
Jiluyuanshise = attributes [ "original color"];
Jiluhuodongse = attributes [ "color"];
Var sanjiaotoumingdou = attributes [ "transparency"];
)
/ / Slider parameters
With (jiedianlujing_xml [3]) (
Var huakuaibeijingse = jinzhizhuanhuan (attributes [ "background color"]);
Var huakuaitoumingdu = attributes [ "background transparency"];
Var huakuaibiankuangse = jinzhizhuanhuan (attributes [ "frame color"]);
Var huakuaibiankuangtoumingdou = attributes [ "Borders transparency"];
Var huakuaibiankuangcuxi = attributes [ "frame size"];
)
/ / According to the text before the domain of the high-rolling set high
Gundongtiaogao = wenben_txt._height;
//////////// Centre of the Background of the drawing rectangle of rolling
CreateEmptyMovieClip ( "gundongtiao_mc", 1000);
Gundongtiao_mc.beginFill (gundongtiaobeijingse, gundongtiaotoumingdu);
Gundongtiao_mc.zhongxinjuxing (0, 0, gundongtiaokuan, gundongtiaogao, gundongtiaobiankuangcuxi, gundongtiaobiankuangse, gundongtiaobiankuangtoumingdou);
Gundongtiao_mc.endFill ();
/ / According to determine the location of domain text scrolling Position in the text to keep the right-hand domain
Gundongtiao_mc.dingwei (wenben_txt._x wenben_txt._width gundongtiao_mc._width / 2, wenben_txt._y wenben_txt._height / 2);
///////// Focal point of drawing rectangular buttons from top to Bottom of the rolling
Drawing on the background ////// button box
Gundongtiao_mc.createEmptyMovieClip ( "shangfangkuai_mc" 1);
Gundongtiao_mc.shangfangkuai_mc.beginFill (fangkuaibeijingse, fangkuaitoumingdu);
Gundongtiao_mc.shangfangkuai_mc.zhongxinjuxing (0, 0, gundongtiao_mc._width, gundongtiao_mc._width, fangkuaibiankuangcuxi, fangkuaibiankuangse, fangkuaitoumingdu);
Gundongtiao_mc.shangfangkuai_mc.endFill ();
/ / Locator box on the button background
Gundongtiao_mc.shangfangkuai_mc.dingwei (0,-gundongtiao_mc._height / 2 gundongtiao_mc.shangfangkuai_mc._height / 2);
Drawing on the triangle button //////
Gundongtiao_mc.createEmptyMovieClip ( "shangsanjiao_mc", 2);
/ / Focal point of rendering triangles
/ / First definition of a factor, the factor is the equilateral triangle center to the vertex distance to positioning the triangle vertex position.
Var yinzi = gundongtiaokuan / 3;
Var zuobiao1x =-1 / 2 * Math.pow (3, 1 / 2) * yinzi;
Var zuobiao1y = 1 / 2 * yinzi;
Var zuobiao2x = 1 / 2 * Math.pow (3, 1 / 2) * yinzi;
Var zuobiao2y = 1 / 2 * yinzi;
Var zuobiao3x = 0;
Var zuobiao3y =-yinzi;
Var zuobiao1 = (x: zuobiao1x, y: zuobiao1y);
Var zuobiao2 = (x: zuobiao2x, y: zuobiao2y);
Var zuobiao3 = (x: zuobiao3x, y: zuobiao3y);
Gundongtiao_mc.shangsanjiao_mc.beginFill (sanjiaoyuanshise, sanjiaotoumingdou);
Gundongtiao_mc.shangsanjiao_mc.sanjiaoxing (zuobiao1, zuobiao2, zuobiao3, 1, 0x000000, 0);
Gundongtiao_mc.shangsanjiao_mc.endFill ();
/ / Positioning triangle
Gundongtiao_mc.shangsanjiao_mc.dingwei (0,-gundongtiao_mc._height / 2 gundongtiao_mc.shangfangkuai_mc._height / 2);
////// Copy button on the Background box and triangle, and positioning in the bottom
/ / Copy the box
Gundongtiao_mc.shangfangkuai_mc.duplicateMovieClip ( "xiafangkuai_mc", 3);
/ / Background positioning button box, where Y coordinates plus one, is to enable the box at the bottom of alignment with the text box!
Gundongtiao_mc.xiafangkuai_mc.dingwei (0, Math.floor (gundongtiao_mc._height/2-gundongtiao_mc.xiafangkuai_mc._height/2) 1);
/ / Copy triangular
Gundongtiao_mc.shangsanjiao_mc.duplicateMovieClip ( "xiasanjiao_mc", 4);
/ / Rotate 180 degrees
Gundongtiao_mc.xiasanjiao_mc._rotation = 180;
/ / Triangular positioning
Gundongtiao_mc.xiasanjiao_mc.dingwei (0, gundongtiao_mc._height/2-gundongtiao_mc.xiafangkuai_mc._height/2);
Drawing slider ///////////
/ / Length and width of rectangular drawing rectangular slider
Gundongtiao_mc.createEmptyMovieClip ( "huakuai_mc", 5);
Gundongtiao_mc.huakuai_mc.beginFill (huakuaibeijingse, huakuaitoumingdu);
Gundongtiao_mc.huakuai_mc.changkuanjuxing (-gundongtiao_mc._width / 2, 0, gundongtiao_mc._width, gundongtiao_mc._width, huakuaibiankuangcuxi, huakuaibiankuangse, huakuaibiankuangtoumingdou);
Gundongtiao_mc.huakuai_mc.endFill ();
//--------- Rolling initialization ---------//
/ / Slider initial height, and record
Chushigaodu = Math.floor (gundongtiao_mc.xiafangkuai_mc._y-gundongtiao_mc.shangfangkuai_mc._y-gundongtiao_mc.shangfangkuai_mc._height);
/ / Initialization slider Y coordinates, and record
Gundongtiao_mc.huakuai_mc._y ychushiweizhi = = Math.round (gundongtiao_mc.shangfangkuai_mc._y gundongtiao_mc.
Shangfangkuai_mc._height / 2);
/ / Slider not that small
Gundongtiao_mc.huakuai_mc._visible = false;
);
//%%%%%%%%%%%%%%%% Rolling code %%%%%%%%%%%%%%%%%%//
////////// Father edited text domain registration interception, interception to changes in the text field, it is in the text was printed in the coming time, the implementation of the code below. This need not worry about code execution order!
Var zhentingqi = new Object ();
Wenben_txt.addListener (zhentingqi);
/ / When the complete text printed in the field, why trigger onScroller events, rather than onChange incident?
Zhentingqi.onScroller = function () (
Trace ("-------------------------");
Trace ( "rolling headquarters several =" wenben_txt.maxscroll);
Trace ( "the current line =" wenben_txt.scroll);
/ / Slider judge whether infants, and in accordance with the number of text slider high definition
If (_parent.wenben_txt.maxscroll! = 1) (
Gundongtiao_mc.huakuai_mc._visible = true;
/ / Definition of a highly factor, the factor with the increase of loading text will tend to an unlimited.
Var gaoduyinzi = 1 - (wenben_txt.maxscroll-1.5) / wenben_txt.maxscroll;
/ / Initialize the Height of the slider, it is defined as the minimum height of 2 pixels.
Gundongtiao_mc.huakuai_mc._height gaodu = = Math.floor (chushigaodu * Math.pow (gaoduyinzi, 1 / 6));
Trace ( "high slider =" gaodu);
)
/ / Slider rolling the total number of pixels
Var zongxiangsu = gundongtiao_mc.xiafangkuai_mc._y gundongtiao_mc.shangfangkuai_mc._height---gundongtiao_mc.shangfangkuai_mc._y gundongtiao_mc.huakuai_mc._height;
/ / Definition of average pixels, each row covered by pixels, each rolling text of his domain, the slider mobile needs of a few.
Var pingjunxiangsu = zongxiangsu / (wenben_txt.maxscroll-1);
/ / Definition of the average number of firms, each pixel contains the number of rows, each moving a slider material, text domain should be rolling in theory the number of rows (although non-integer line did not reflect the visual).
Var pingjunhangshu = (wenben_txt.maxscroll-1) / Math.floor (zongxiangsu);
Trace ( "rolling total pixels =" zongxiangsu);
Trace ( "average pixel value =" pingjunxiangsu);
/////////// Definition button
Gundongtiao_mc.shangfangkuai_mc.onRollOver = function () (
Gundongtiao_mc.shangsanjiao_mc.shangse (jiluhuodongse);
This.onPress = function () (
This.onEnterFrame = function () (
Wenben_txt.scroll--;
/ / Slider to the children moved to the corresponding position.
Ychushiweizhi pingjunxiangsu gundongtiao_mc.huakuai_mc._y = * (wenben_txt.scroll-1);
Trace ( "slider Y coordinates =" gundongtiao_mc.huakuai_mc._y);
);
);
This.onRelease = function () (
Delete this.onEnterFrame;
);
This.onRollOut = function () (
Gundongtiao_mc.shangsanjiao_mc.shangse (jiluyuanshise);
);
);
//////////// Definition of a button
Gundongtiao_mc.xiafangkuai_mc.onRollOver = function () (
Gundongtiao_mc.xiasanjiao_mc.shangse (jiluhuodongse);
This.onPress = function () (
This.onEnterFrame = function () (
Wenben_txt.scroll;
/ / Slider to the children moved to the corresponding position.
Ychushiweizhi pingjunxiangsu gundongtiao_mc.huakuai_mc._y = * (wenben_txt.scroll-1);
Trace ( "slider Y coordinates =" gundongtiao_mc.huakuai_mc._y);
);
);
This.onRelease = function () (
Delete this.onEnterFrame;
);
This.onRollOut = function () (
Gundongtiao_mc.xiasanjiao_mc.shangse (jiluyuanshise);
);
);
/////////// For use MOUSE onMouseWheel methods in the object interception Implementation slider with the mouse ball rolling
MouseListener = new Object ();
Mouse.addListener (mouseListener);
MouseListener.onMouseWheel = function (delta) (
Delta = 1;
Ychushiweizhi pingjunxiangsu gundongtiao_mc.huakuai_mc._y = * (wenben_txt.scroll-1);
);
/////////// Slider MC incident, when the mouse or pressed
Gundongtiao_mc.huakuai_mc.onPress = function () (
/ / Start Drag
This.startDrag (false, this._x, ychushiweizhi, this._x, Math.round (gundongtiao_mc.xiafangkuai_mc._y-gundongtiao_mc.xiafangkuai_mc._height/2-gundongtiao_mc.huakuai_mc._height));
/ / Slider rolling with the text
This.onEnterFrame = function () (
/ / In the process of rolling immediate "slider location"
Var xianzaiweizhi = Math.floor (this._y);
Trace ( "You are here =" xianzaiweizhi);
/ / Rolling with the text of the rolling, why should add one here, we can see that scroll attribute values should take positive, which means it will be deleted decimal part, rather than a rounding system?
Wenben_txt.scroll = (xianzaiweizhi-ychushiweizhi) * pingjunhangshu 1;
Trace ( "scroll =" Math.floor ((xianzaiweizhi-ychushiweizhi) * pingjunhangshu 1));
Trace ( "initial position =" ychushiweizhi);
Trace ( "You are here =" xianzaiweizhi);
);
);
/ / MC slider incident, or release the mouse out of
Gundongtiao_mc.huakuai_mc.onRelease gundongtiao_mc.huakuai_mc.onRollOut = = function () (
/ / "Slide" stop dragging
This.stopDrag ();
/ / Stop the rolling text with the slider incident
Delete this.onEnterFrame;
);
);
Below are the XML document code:
<? Xml version = "1.0" encoding = "UTF-8">
<Scroll>
<Rolling background of the Background Color = "# 666666" background transparency = "100" frame color = "# 666666" transparency Border = "100" frame size = "1" width = "20" />
<Box background color = "# 000000" transparent background = "100" frame color = "# 999999" transparency border = "100" frame size = "0" />
<1.30 original color = "# ffff00" color = "# ff0000" transparency = "100" />
<Slider background color = "# 000000" transparent background = "100" frame color = "# 999999" transparency border = "100" frame size = "0" />
</ Scroll>
Description:
As I scroll of this is written entirely by AS, as you only need to insert the html pages JS script, just as those above AS code you insert the text of the domain Fok, operation, we will be rolling automatic drawing Adsorption and the text box to your right!
NOTE:
★ your domain terrible text entitled: wenben_txt. As is the practice, I did not deal with interface, I am sorry:)
XML ★ You can modify the corresponding parameters.
★ this with the rolling of the Basic components of the scrollbar all of the features, including the precise location, but also avoid the easy text input in the slider beating incident. Of course, and the most crucial of all is: I only 2 of this rolling more than K!
★ this work is purely for our own amusement and challenge themselves. AS1.0 based on the prototype, code written in relatively indiscriminate, senior master exhibitions.
- Learning CSS
- Css learning Notes - yyy431706 (of Portland)
- CSS layout of the learning some ideas
- CSS layout learning experience
- Css learning Notes
- Five learning css
- Css learning my feelings!
- CSS learning
- CSS learning from entry to the master
- Css learning in the Filter
- CSS cascading style of learning [2]
- CSS learning should pay attention to learning method
- Learning css 4
- Css learning (1)
- Learning css 3
- CSS cascading style of learning [1]
- CSS learning "text attributes"
- Css learning Notes (1)
- Css learning pace
- Css learning some experience




