I plan to create a map editor for the game. The scroll bar is required when the map is large,
The scroll bar that comes with Flash is not very useful, so I made a simple scroll bar to control the display of the image,
You can modify and add new features as needed.
First, use cs4 to create a vertical MC
,
The up arrow, down arrow, scroll bar (CTRL), and background (BAK) are all MC, and then a horizontal MC is created in the same way, the four Mc values are left, right, Ctrl, and Bak.
Next, create the image display board mapfloor, draw a x mask, and drag the two scroll bars to the left and bottom respectively, and set the name to BARC and Barr. Create a MC under the mask (Name: floorimage)
Now we can use these MC to control the image display.
First, find a slightly larger image,
Use _ loader to read images,
_ Map = new mapfloor ();
Addchild (_ map );
_ Loader = new loader ();
_ Loader. contentloaderinfo. addeventlistener (event. Complete, setjpgover );
_ Loader. Load (New URLRequest ("images/test.jpg "));
After reading, set the scroll bar status:
_ Loader. contentloaderinfo. removeeventlistener (event. Complete, setjpgover );
_ Image = Bitmap (_ loader. content );
_ Map. floorimage. addchild (_ image );
If (_ map. floorimage. width> 480 ){
_ Map. Barr. Bak. width = 480;
_ Map. Barr. Right. x = 466;
_ Map. Barr. addeventlistener (mouseevent. mouse_down, barrmousedown );
_ Map. Barr. addeventlistener (mouseevent. mouse_up, barrmouseup );
_ Map. Barr. Left. addeventlistener (mouseevent. mouse_down, barrup );
_ Map. Barr. Right. addeventlistener (mouseevent. mouse_down, barrdown );
} Else {
_ Map. Barr. Visible = false;
}
If (_ map. floorimage. Height> 480 ){
_ Map. BARC. Bak. Height = 480;
_ Map. BARC. Down. Y = 466;
_ Map. BARC. addeventlistener (mouseevent. mouse_down, barcmousedown );
_ Map. BARC. addeventlistener (mouseevent. mouse_up, barcmouseup );
_ Map. BARC. Up. addeventlistener (mouseevent. mouse_down, barcup );
_ Map. BARC. Down. addeventlistener (mouseevent. mouse_down, barcdown );
} Else {
_ Map. BARC. Visible = false;
}
Private function barcup (Event: mouseevent): void {
_ Map. BARC. CTRL. Y-= 10;
If (_ map. BARC. CTRL. Y <14 ){
_ Map. BARC. CTRL. Y = 14;
}
Maptoy ();
}
Private function barcdown (Event: mouseevent): void {
_ Map. BARC. CTRL. Y + = 10;
If (_ map. BARC. CTRL. Y> 416 ){
_ Map. BARC. CTRL. Y = 416;
}
Maptoy ();
}
Private function barrup (Event: mouseevent): void {
_ Map. Barr. CTRL. X-= 10;
If (_ map. Barr. CTRL. x <14 ){
_ Map. Barr. CTRL. x = 14;
}
Maptox ();
}
Private function barrdown (Event: mouseevent): void {
_ Map. Barr. CTRL. x + = 10;
If (_ map. Barr. CTRL. x> 416 ){
_ Map. Barr. CTRL. x = 416;
}
Maptox ();
}
Private function barcmousedown (Event: mouseevent): void {
Barctomouse (event );
_ Map. BARC. addeventlistener (mouseevent. mouse_move, barcmousemove );
}
Private function barcmouseup (Event: mouseevent): void {
_ Map. BARC. removeeventlistener (mouseevent. mouse_move, barcmousemove );
}
Private function barcmousemove (Event: mouseevent): void {
Barctomouse (event );
}
Private function barrmousedown (Event: mouseevent): void {
Barrtomouse (event );
_ Map. Barr. addeventlistener (mouseevent. mouse_move, barrmousemove );
}
Private function barrmouseup (Event: mouseevent): void {
_ Map. Barr. removeeventlistener (mouseevent. mouse_move, barrmousemove );
}
Private function barrmousemove (Event: mouseevent): void {
Barrtomouse (event );
}
Private function barrtomouse (Event: mouseevent): void {
If (event. currenttarget. mousex <14 | event. currenttarget. mousex> 466 ){
Return;
}
_ Map. Barr. CTRL. x = event. currenttarget. mousex-11;
If (_ map. Barr. CTRL. x <14 ){
_ Map. Barr. CTRL. x = 14;
} Else if (_ map. Barr. CTRL. x> 416 ){
_ Map. Barr. CTRL. x = 416;
}
Maptox ();
}
Private function maptox (): void {
_ Map. floorimage. x =-1 * (_ map. Barr. CTRL. X-14) * (_ map. floorimage. Width-480)/402;
}
Private function barctomouse (Event: mouseevent): void {
If (event. currenttarget. Mousey <14 | event. currenttarget. Mousey> 466 ){
Return;
}
_ Map. BARC. CTRL. Y = event. currenttarget. mousey-11;
If (_ map. BARC. CTRL. Y <14 ){
_ Map. BARC. CTRL. Y = 14;
} Else if (_ map. BARC. CTRL. Y> 416 ){
_ Map. BARC. CTRL. Y = 416;
}
Maptoy ();
}
Private function maptoy (): void {
_ Map. floorimage. Y =-1 * (_ map. BARC. CTRL. Y-14) * (_ map. floorimage. Height-480)/402;
}
Press Ctrl + enter to test the function. You can see that the scroll bar can control the image.