FLEX类似谷歌地图拖拽功能

时间:2022-04-16 17:19:21

要实现类似于谷歌地图拖拽功能,可以用s:Scroller标签来实现,代码如下:

mxml:

 <s:Scroller width="100%" height="100%" interactionMode="touch" skinClass="skins.ScrollerSkin">
<s:Group>
<component:Diagram id="diagram">
</component:Diagram></s:Group>
</s:Scroller>

其中的component:Diagram为自己定义的组件,只需替换成你要放置的东西就OK.

皮肤文件 -->

1.ScrollerSkin.mxml:

 <?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"> <fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.Scroller")]
]]>
</fx:Metadata> <fx:Script>
<![CDATA[
import skins.*;
/**
* @private
*/
override public function beginHighlightBitmapCapture() : Boolean
{
var needUpdate:Boolean = super.beginHighlightBitmapCapture(); // Draw an opaque rect that fill our entire skin. Our background
// is transparent, but we don't want focus/error skins to
// poke through. This is safe to do since we don't have any
// graphic elements as direct children.
graphics.beginFill(0);
graphics.drawRect(0, 0, width, height);
graphics.endFill(); return needUpdate;
} /**
* @private
*/
override public function endHighlightBitmapCapture() : Boolean
{
var needUpdate:Boolean = super.endHighlightBitmapCapture(); // Clear the rect we drew in beginBitmapCapture();
graphics.clear();
return needUpdate;
}
]]>
</fx:Script>
<s:VScrollBar id="verticalScrollBar" visible="false" skinClass="skins.VScrollerSkin"/>
<s:HScrollBar id="horizontalScrollBar" visible="false" skinClass="skins.HScrollBarSkin"/>
</s:SparkSkin>

2.VScrollerSkin.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" minWidth="15" minHeight="15"
alpha.disabled="0.5" alpha.inactive="0.5" >
<fx:Script>
<![CDATA[ import skins.ScrollerBarTrackSkin;
import skins.ScrollerThumbSkin;
]]>
</fx:Script>
<fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.VScrollBar")]
]]>
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
<s:State name="inactive" />
</s:states>
<s:Button id="track" top="1" bottom="1" width="10"
focusEnabled="false" tabEnabled="false"
skinClass="skins.ScrollerBarTrackSkin" />
<s:Button id="thumb"
skinClass="skins.ScrollerThumbSkin" mouseEnabled="false"
focusEnabled="false" visible.inactive="false" tabEnabled="false"/>
</s:SparkSkin>

3.HScrollBarSkin.mxml:

 <?xml version="1.0" encoding="utf-8"?>
<s:SparkSkin xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009" minWidth="35" minHeight="15"
alpha.disabled="0.5" alpha.inactive="0.5">
<fx:Script>
<![CDATA[ import skins.ScrollerBarTrackSkin;
import skins.ScrollerThumbSkin;
]]>
</fx:Script>
<fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.HScrollBar")]
]]>
</fx:Metadata>
<s:states>
<s:State name="normal" />
<s:State name="disabled" />
<s:State name="inactive" />
</s:states>
<s:Button id="track" left="1" right="1" width="10"
focusEnabled="false" tabEnabled="false"
skinClass="skins.ScrollerBarTrackSkin" />
<s:Button id="thumb"
focusEnabled="false" visible.inactive="false" tabEnabled="false" mouseEnabled="false"
skinClass="skins.ScrollerThumbSkin" /> </s:SparkSkin>

4.ScrollerBarTrackSkin.mxml:

 <?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
minWidth="10" minHeight="10"
alpha.disabled="0.5">
<fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.Button")]
]]>
</fx:Metadata>
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<s:Rect top="0" bottom="0" left="0" right="0" minWidth="10" minHeight="10">
</s:Rect>
</s:SparkButtonSkin>

5.ScrollerThumbSkin.mxml:

 <?xml version="1.0" encoding="utf-8"?>
<s:SparkButtonSkin xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
minWidth="10" minHeight="10"
alpha.disabled="0.5">
<fx:Metadata>
<![CDATA[
/**
* @copy spark.skins.spark.ApplicationSkin#hostComponent
*/
[HostComponent("spark.components.Button")]
]]>
</fx:Metadata>
<s:states>
<s:State name="up" />
<s:State name="over" />
<s:State name="down" />
<s:State name="disabled" />
</s:states>
<s:Rect top="1" left="1" right="1" bottom="1" radiusX="5" radiusY="5">
<s:fill>
<s:SolidColor color="0xC0C0C0" alpha="0.8"/>
</s:fill>
</s:Rect>
</s:SparkButtonSkin>

效果见下图,当内容超过s:Scroller大小,并且只有拖拽的时候才会出现这个滚动条, 标签自带的拖到头部或尾部还会有弹性,就像谷歌地图的效果那样   O(∩_∩)O~:

FLEX类似谷歌地图拖拽功能

FLEX类似谷歌地图拖拽功能的更多相关文章

  1. React Editor 应用编辑器&lpar;1&rpar; - 拖拽功能剖析

    这是可视化编辑器 Gaea-Editor 的第一篇连载分析文章,希望我能在有限的篇幅讲清楚制作这个网页编辑器的动机,以及可能带来的美好使用前景(画大饼).它会具有如下几个特征: 运行在网页 文档流布局 ...

  2. 使用NGUI实现拖拽功能(拼图小游戏)

    上一次用UGUI实现了拼图小游戏,这次,我们来用NGUI来实现 实现原理 NGUI中提供了拖拽的基类UIDragDropItem,所以我们要做的就是在要拖拽的图片上加一个继承于该类的脚本,并实现其中的 ...

  3. 关于 JS 拖拽功能的冲突问题及解决方法

    前言 我在之前写过关于 JS 拖拽的文章,实现方式和网上能搜到的方法大致相同,别无二致,但是在一次偶然的测试中发现,这种绑定事件的方式可能会和其它的拖拽事件产生冲突,由此产生了对于事件绑定的思考.本文 ...

  4. &lpar;Demo分享&rpar;利用JavaScript(JS)实现一个九宫格拖拽功能

    利用JavaScript(JS)实现一个九宫格拖拽功能   Demo实现了对任意方格进行拖拽,可以交换位置,其中Demo-1利用了勾股定理判断距离! Demo-1整体思路: 1.首先div实现*移动 ...

  5. html5中的拖拽功能

    拖拽元素支持的事件 ondrag 应用于拖拽元素,整个拖拽过程都会调用 ondragstart 应用于拖拽元素,当拖拽开始时调用 ondragleave 应用于拖拽元素,当鼠标离开拖拽元素是调用 on ...

  6. android五子棋游戏、资讯阅读、大学课程表、地图拖拽检测、小说搜索阅读app等源码

    Android精选源码 Android 自动生成添加控件 android旋转动画.圆形进度条组合效果源码 一款很强的手机五子棋app源码 android地图拖拽区域检测效果源码 实现Android大学 ...

  7. RCP:拖拽功能的实现 Drag and Drop

    SWT中的拖拽是使用的org.eclipse.swt.dnd. 有三个需要密切注意的类: 1.DragSource 2.DropTarget 3.Transfer DragSource封装了需要被拖拽 ...

  8. js实现登陆页面的拖拽功能

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>登 ...

  9. duilib中控件拖拽功能的实现方法(附源码)

    转载请说明原出处,谢谢~~:http://blog.csdn.net/zhuhongshu/article/details/41144283 duilib库中原本没有显示的对控件增加拖拽的功能,而实际 ...

随机推荐

  1. java正则表达式入门

    http://www.cnblogs.com/jingmoxukong/p/6026474.html 这篇文章写的不错

  2. Windows下HG服务器的搭建

    1.环境和所需工具安装 1. 安装python-2.7.9.exe 2. 安装mercurial-3.2.3.win32-py2.7.exe 3. 安装mercurial-3.2.3-x86.msi ...

  3. Linux 下源码包安装MariaDB

    .8.5]# cd cmake-2.8.5 [root@zabbix_server cmake-2.8.5]# ./bootstrap [root@zabbix_server cmake-2.8.5] ...

  4. var隐式类型

    var dogName = "ruiky"; 1.[编译器]会在编译时自动根据值的类型推断这个变量的类型:       2.变量类型不可更改:因为声明的时候已经确定类型了. 3.可 ...

  5. iOS 启动连续闪退保护方案

    引言 “如果某个实体表现出以下任何一种特性,它就具备自主性:自我修复.自我保护.自我维护.对目标的自我控制.自我改进.” —— 凯文·凯利 iOS App 有时可能遇到启动必 crash 的绝境:每次 ...

  6. spring2&period;0 Consider renaming one of the beans or enabling overriding by setting spring&period;main&period;allow-bean-definiti

    1. 报错信息 Description: The bean 'dataSource', defined in BeanDefinition defined in class path resource ...

  7. &lbrack;Swift&rsqb;LeetCode326&period; 3的幂 &vert; Power of Three

    Given an integer, write a function to determine if it is a power of three. Example 1: Input: 27 Outp ...

  8. ubuntu 16&period;04安装mysql

    首先执行下面三条命令: sudo apt-get install mysql-server sudo apt install mysql-client sudo apt install libmysq ...

  9. ORA-39006错误原因及解决办法

    使用impdp导出数据时碰到ora-39006错误,错误提示如下所示: ORA-39006: internal error ORA-39213: Metadata processing is not ...

  10. c3p0的几种使用方式&lpar;原文地址&colon; https&colon;&sol;&sol;my&period;oschina&period;net&sol;liangtee&sol;blog&sol;101047&rpar;

    package com.c3p0.test; import java.sql.Connection; import java.sql.SQLException; import java.beans.P ...