/*jshint bitwise: false*/ /** * swf2js (version 0.7.8) * develop: https://github.com/ienaga/swf2js * readme: https://github.com/ienaga/swf2js/blob/master/readme.md * web: https://swf2js.wordpress.com * contact: ienaga@tvon.jp * copyright (c) 2013 toshiyuki ienaga. licensed under the mit license. */ if (!("swf2js" in window)){(function(window) { var _document = window.document; var _math = math; var _min = _math.min; var _max = _math.max; var _floor = _math.floor; var _ceil = _math.ceil; var _pow = _math.pow; var _random = _math.random; var _atan2 = _math.atan2; var _sqrt = _math.sqrt; var _cos = _math.cos; var _sin = _math.sin; var _log = _math.log; var _abs = _math.abs; var _sqrt2 = _math.sqrt2; var _ln2 = _math.ln2; var _ln2_2 = _ln2 / 2; var _log1p = 0.29756328478758615; var _pi = _math.pi; var _number = number; var _fromcharcode = string.fromcharcode; var _isnan = isnan; var _settimeout = settimeout; var _cleartimeout = cleartimeout; var _setinterval = setinterval; var _clearinterval = clearinterval; var func = function; var alert = window.alert; var console = window.console; var isbtoa = ("btoa" in window); var iswebgl = (window.webglrenderingcontext && _document.createelement("canvas").getcontext("webgl")) ? true : false; iswebgl = false; // todo var requestanimationframe = window.requestanimationframe || window.webkitrequestanimationframe || window.mozrequestanimationframe || window.settimeout; // params var resizeid = 0; var stageid = 0; var stages = []; var loadstages = []; var instanceid = 0; var tmpcontext; var startdate = new date(); var _navigator = window.navigator; var ua = _navigator.useragent; var isandroid = (ua.indexof("android") > 0); var isandroid4x = (ua.indexof("android 4.") > 0); var isios = (ua.indexof("iphone") > 0 || ua.indexof("ipod") > 0); var ischrome = (ua.indexof("chrome") > 0); var istouch = (isandroid || isios); var xmlhttprequest = new xmlhttprequest(); var isxhr2 = (typeof xmlhttprequest.responsetype !== "undefined"); var isarraybuffer = window.arraybuffer; var quality = (iswebgl) ? 1 : 0.8; var devicepixelratio = window.devicepixelratio || 1; var _devicepixelratio = devicepixelratio * quality; var _event = null; var _keyevent = null; var startevent = "mousedown"; var moveevent = "mousemove"; var endevent = "mouseup"; if (istouch) { startevent = "touchstart"; moveevent = "touchmove"; endevent = "touchend"; } // alpha bug var isalphabug = isandroid; var chkcanvas = _document.createelement("canvas"); chkcanvas.width = 1; chkcanvas.height = 1; tmpcontext = chkcanvas.getcontext("2d"); if (isandroid) { var imagedata = tmpcontext.createimagedata(1, 1); var pixelarray = imagedata.data; pixelarray[0] = 128; pixelarray[3] = 128; tmpcontext.putimagedata(imagedata, 0, 0); imagedata = tmpcontext.getimagedata(0, 0, 1, 1); pixelarray = imagedata.data; isalphabug = (pixelarray[0] === 255); imagedata = null; pixelarray = null; } if (typeof object.defineproperty !== "function") { object.defineproperty = function (obj, prop, desc) { if ("value" in desc) { obj[prop] = desc.value; } if ("get" in desc) { obj.__definegetter__(prop, desc.get); } if ("set" in desc) { obj.__definesetter__(prop, desc.set); } return obj; }; } if (typeof object.defineproperties !== "function") { object.defineproperties = function (obj, descs) { for (var prop in descs) { if (descs.hasownproperty(prop)) { object.defineproperty(obj, prop, descs[prop]); } } return obj; }; } if (typeof object.getprototypeof !== "function") { object.getprototypeof = function (obj) { return obj.__proto__; }; } if (typeof object.setprototypeof !== "function") { object.setprototypeof = function (obj, proto) { obj.__proto__ = proto; return obj; }; } // shift-jis var jct11280 = new func('var a="zkv33~jz4zn=~ji36xazm93y!{~k2y!o~k0zlw6zn?3wz3w?{ekzk[33[`y|;-~j^yotz$!~kny|l1$353~jv3zkk3~k-4p4zk_2+~jy4y!xyhr~jlz$_~jk4z$e3x5he<0y!wy|x3[:~l|vu[f3vz056hy!nz/m1xd61+1xy1e1=1y|bzkiz!h034zkj~mez#c5za3-3x$1~mbz$$3~lyz#,4yn5~mez#{zkz3v%7y}!j3x-yex_j(3~maz =v;ke0/y|f3y!}~m>z/u~mi~j_2+~ma~jp2;~m@~k32;~m>v}2u~mex#2x~mby+x2242(~mby,;2242(~may->2&xkg2;~miy-_2&nxd2;~mgz,{4<6:.:b*b:xc4>6:.>b*bbxsa+a:x]e&e<~r#z+625z s2+zn=`hxi@ymxiaxzyum8x4k/:q!z&33 3ywx[~mb`{zkt4z (zv/z 3zrw2%wd39]s11z$paxh5xb;zqwu1zgwp%3~o@{dgl#gd}t){uo{y5_d{e@}c(} wu9|cb{w}bzvv|)[} h|zt}d||0~{]q|(l{|x{iv{dw}(5}[z|kuz }cq{{y|ij}.i{idbof%cu^d}rj^y|-m{esygyfyszsls`?zdyo__glyrz&fvb4okfhsf^d|c#ryw=}ey{l+`)][yf_ub^h4}[x|?r|u_ex}tl@yr]j{srxgo*|gv|rk}b#mu{r1}hs|dp{c7|^qt3|@p{yvv |8&}#d}ef{e/{rl|>hni}r1{z#{d[}cqlq||e}[s{sg_+i8eply[=[|ec[$yxn#`hcm}yr|{ci(_[ql|?8p3]-}^t{wy}4la&pc|3e{rp{lqij],] `kc(]@chynrm`o^,zlyhzb]ywyfgy~aex!_qww{a!|)*lhrm{n+n&yyj~z b c#e_[hzson|rot`}hbxa^i{lh|<0||r{kj{kni)|x,|0auy{d!^sce{w;|@s|ca}xn{c1h${e]z-xgz*xpbp]^_qbh^e[`ym|a||+=]!lc}]vdbc=j-yszd]ymyylykz9z>xcczc2{yh}9fc#z.l{}(d{g{{mrhc|l3b#|xk[bepj#ut`h[,{e9yr}1b{[e]{zfk7[zybz0xl]}ye[(`d}c!|*y`dg=b;gr]hm=hjho}r-[n}9;{n![7k_{ubmn]rf#pte[x8}!qcs_rs[m`|>n}^v})7{^r|/e}),}hh{oye2{skx)e<_.cj.cjomhc^d}0uyzd!^j_@g,[[[?{i@][|3s}yl3|!1|ez|5iyw|1d}e7|cv{ohbnx-`wvb[6[4} =g+k:{c:}ed{s]|2m]-}wz|/q{lf|dyu^}gs^c{z=}h>|/i|{w]:|ip{n:|zt|s<{dh[p_tvd{n<[8axo{x4a.^o^x>yfa59`#zbygy~_t^9`jzhzn`>g[oajz;x,i)z.^~yje zizf^{][[#zt^|]fjx]&_5dddw]p0c[-]}]d|y {c_juql] |opaa[z{lp|rz}:mu#]_yf6{ep?f5`$[6^d][^u[$[6^.z8]]epc2u/=]k^_+^m{q*|9tyuz,s(ds{i=|bnbb{ug}0jzoa:[-]dytu3]:]<{dj_sziqr_`l=yt`gktnxb3d@kiq0a`z{|!b|}e}ww{sp,^z|0>_z}36|]a|-t}lt{r6pi|v8hpu#{c>yozhymg/z4nick[}hf_bg|yrz7c|crkzyzy}_ixcz.|)u|l5{r~qi^uga@y[xb}&qdbd6h5|btw[}c<{ds53[y7]?z<|e0{l[zk]mxkz#z2^tavf0`pe[osoap`4gi`qjdymgys/?[nc,}eeb,el]g[n{e_b/vcvgb.{kcwi`~v%|0:|ik{jh_vf5lb}kl|(oi=lrzhhy_^@`zgf[~g)[j_0fk_v{t)}i_{d&_/d9w/|mu[)f$xw}?$xr4<{lb{y4}&u{xj|cm{iu{jq}cmkd{cx|7a}g~{kt)nb|d5|<-}wj}@||d@|iy}ts|il|/^|no|0;}l6{pm]7}$zf:|r2}?c_k{r(}-w|`g{gy[g]bvje=_0|pt{^y^yjtt[[[l!ye_`zn]@[n_)j3negma]ytypzy].d-y_cjb~y~[nc~sci3|zg}b0}do{o^{|$`_|d{}u&|0+{j3|8*]iayx{a{xj_9|,c{ee]qxlyb]$[%ymc*]w[aafe]avyi[fzeii[xq2yqzhg]y~h#|y:thre^@^|_f^cbtbg_1^qf7{l-`vfx zr|@ez;gkz@slgko`[e}t:{cu^pddz_`yav^ea+[#zbbsbo`elqflui}.f|txycbq`xehcge~fc^rlv{d_0zaej[l&jshxg[ipb_=u:eu}3e8[=j|{d(}do{do[byuz0/]aye]alyhzcylyp/^-^{yt_1_-;yt`p4bzg=ioz&]h[e]yyd[9^f[1ydzxz?z{z<]ba2[5yb[0z4l?]d_;_)a?ygeyiyv`_xmzs4zjy^zb]6gqgax^9y}dxzr[g|]y}k afzp^k^f]m`^{o1ys]zcgcv4|e>}8eb7}l`{l5[z_faq|c2}fj}hw^#|ng|b||w2|sh{v+[g}ab|my}a{|8o}x~{e8paz:]i^njq]new)`-z>haounwhn}c#{dfz|fk]kqgz=:u|fqoqcv}2ssm}.r{]{nifv{jw)[k|,z{uxc|]l_kdcb%]cfobya3`p}g^|lzisc]u|(x|kblvg[kno({o:g:|-n|qt}9?{mbil}sq{`p|3a|u.{uaq:{_o|^s}jx{fob0`;|#y_@[v[k|cw[<_ }ku|0f}d3|et{q7{luzttsmf^kyz`af`}$x}u`|ww}d]| >}k,r&|xi|*e{c/a-bmr1fid4[;b>tq_:]hk{b-pmge]gfpo.|(w[jgv{ec1z,yhay^q,_g[c_g[j0yx]`[h^hyk^_yib,` {i6vf@ym^hdokzzn(jgz>bzsdc^z%[[o9[2=/yhz(_/gu_`*|8z{duzxyt^vuvzjhi^lc&gud4|zb]r|{7{j@cu^{{cbiyohlng]f+nq[bktn/}<-d9q {kxadzyo+n|l[|lc}v2{[a{s4zam~za^`{hh{xx_svf|ak=c^[v^7_ryt`ld@]:_ub%[$[m](shu}g2{e.zu_l_r{tz`vj(f?^}hswz}gdz}{s:h`ad|?w|`dgg|if{a8|j1{n,}-ao3{h#{mfsp|[ bzn+}_q{mt{u4khcj_q`ezj[8o0jy{p7}c|[}l){muyy{|ff!ykn3{rt|m,^r|,r}$~ykgx{p!]>ixh6[l[/}jgcg{jyz.^qyfyizl[gz#xj[pc7yyzd^+yt;4;`e8yyzvbq7yzzxxja.7syl[s]2^/ha$[6zgyrb%xiydf2]h]kzkz*zq[zys^hzxccc%z|[(bvz]]:ojq_dzcg<[,]%zaa [g{c00hy[c%[chyz,z_`pbxa+eh`^&jpi0a[ggvhlekl]w{yp^v}[e{~;k%a&k^|nr_z_qng}[e}*wq:{k^{fjzpxrhmh3^p>de^=_7`|zbaaztdhz?n4zl]u`9znc3g%[6b=e.zvfc[zz^^^hd{e(9c(kyz=bb|sq{k`|vmr>izlh[u|e`}49}y%}ft{[z{rk}bz{tcc/lmiaqkf(m$hdc;qooi[}^o:c^|qm}a_{mrz(pa`,}<2sy| adf_%|}`}y5u;}/4|d>|$x{jw{c<|f.hk|*a{mrz8zsm?imzm_?brywzryx`yvzc3a@f?ak^ojed {bn}/3zh]/$yzhm^&j 9|(s|b]mf}ui{q&am]lcrz5^.|[j`t_v_gak}9j[ zczd|^h{n9{~&[6zd{}b}2o|cv]k}3s}uy|l,fihw{eg`j_qop~z$f^zexs`dcisfhzbxp|.vn|_hyq|)9|cr]<`&z6]m_(zhpcsg>`z]5`~1`0xcb4k1{o!bz|cn_t{lr|a/gfcd|j<{z._[f)mpc:1`wtiat1cgykzoavzoyfree[}t$}ch}mk{k-^@]fh{hdi`c*z&|kt{if[c{q;{xyb`dyix:zb[}]*[{{p9|4gyrh2ao{ds|v+[zd$`f[zxkadb*a] ys]maif~a/z2bmclb8{jro_rz|x9chojbz{gzzx_)]:{waayedlx}<=`g{h1{l#}9i|)=|lp{qq}.({la|!y{i2ezfp=c*}cc{edvvb|;g}2t{w4av^bn=]ri,|y?|3+}t*ckz*{ffr5e%|sb{lx^0]ezb]9[sgajs_d|uhzx]dive[c.ypkcq/}db{eqh&hq|eg}g!ljil|bo]x{qr_gkgl~yiywu=c3eb}29v3|d|}4i||.{mv})v{sp1{fx}czw6{cm|vo{ps|e#}a~|1i}81|mw}es|5[}3w{c`h9al]o{}p[g`>i%a1z@`ln2bd[$_h`}zojhdtrh{[j_:k~kv[sdu]ctl}41{i |[[{]zp$]xjxjht_ethoa#h>sst8|gk|tvi[y{t=}bs|b7zpr%{gt|yo{cs[/{iteva|cf^hgn}($_c^wmb^wm+|55jrbf|{9^ q6{c&c+zkdjkq_xoyqzysyxyl`8]-cxzaq/b%b*_vsa[/ybjac/oagz4fza|a)gy{p?| i|y |,pi1n7}9bm9ad|=d{av|2@[(}b`d&|uz}b}{`q|/h|!jkm{fu|cb|.{}az}#p|lk}k{|2rk7{^8^?`/|k>|ka{sq}gz}io{dxzh[yk_#}9<{trdgc]`~z>jymyj]|`!zkz]gucx|^e[rzcd`f9oq[ncd_$zlz;zr}mx|=!|$6zpzytio%fj}cpcn|b,{vdw~gb}@hzg`q{lcma[(bo`<|@$|o1|ss}9z_}tc|g`{f/|9nd}i=}v-{l8aaest]darbujh^xlpq8|}zs4bj[s`j|]?g{p#{rd{]i`olh{hm]vyusyubrc*6[j`8]pz[bt_/^jc*[e8`w^j_y}r{{jp__]ee#e:iwb9q_wkbujrbr}cy`,{mj}gz{q^{t~n|? gsga`v_||:#mi}3t|/i`x{n*|ct|2g{km}gi|{={jc}f;|e}{zzjyf*frmu}8tdroi{t[|+~}hg{cj}dm{lp{ctd&}$hi3|fz| m}kr|38}^c|m_|tr{qv|36}?up>|;s{dv{k_as}bk{p}}9p|t`jr{sam4{d=b4pwa[}xi{ejweki}3s|e?u=x0{jf} s|nm|jc{qo^3cm]-|jux/{cj{s>{crt[uxuv|d~|j|d{yxzr}aq}0r}(_{pjfi_z}0b|-vi)z mfe,{f4|q`b{}^z{hm{rbehz|^x_o|xm|l%|ufxm}@c_{{hhp%a7|0p[xp+^k}9u{bp}: tt}b|}+$|b2|[^|~h{faby[`{}xgygrt~h1[li`c4vz|,7p~b(|mvin}^pg[{n/|g3|^0c,ge|f%|7n{q[|tc|tka{lu}i@|azp(}g-sz{f |qz{}f|f-}rgn6{z]_5})b}uj{ffb2]4zi@v=k,]t_dg5bj]z-]l]vrpdvdglk|gf}g]|iw}y0[g| /bo|te^,_b}#n^^{qhyi[?hxg{[`]d^iyrytb&kj[cri[g_9]ud~^_]rsk0ym[jre]ryiztr*yj{ge|%-lf|y(`=[t}e6{k!|3)}zk} ][g{e~cf{u3u.rj|a9p#o#ze|?|{syc#vv{e=|lc}cu{n8`/`3`9rt[4|he{cq|isyxy`}v |(q|t4{c?]k_vlvk)bz^r<{cl}#h}r+[<|i=}x|{kao]|w<`k{nw|zx}#;|fe{imr<|k~tj_x}aylz?{gvblnrgn}x&{h7|x~}jm{]-| gpnu0}.ok>|c4{pyisrdz|fwh9|hfo@{h~xsbo]odv]%`n]b1y]]|eiz}_-za]aj,>efn+j[aq_+]h[j_m_g]%_wf.`%k1e#z?{cvyu_b^|gk`xfh^m3`afgz-z|[m{l}|k3cp[it ^>yui~d>{t*}yj{q5{jxa$hg|%4`}|lagvb }g}{p=|<;ux{_skr{cv|-*|s-{mp|xp|$g|_j}c6cm{_=_d|*9^$ec{v;|4s{qo|w_|.7}d0|/d}e}|0g{dq]kdp{}dfdi>}b%{gd|nl}lf{c-{y}|anzr}#={t~|-(}c&{pi|ft{lsvp}){|@u}!w|bcmb{d?|iw|:dxj{psko|hl]li:}vyk@|2={fnwt{m3`cz6|)}|xj}bya?vo{e4|l7|b7{l7|1w|lvyo}w8nj|$vih|{t{d*_1|:-n2dblk``ft{ky|-%}m!|xy|-a{pz}[l{kfjz|ih}9n{we{x,|jz}r {p|{d)c=nx|kq|si}ge{sh|[x{rf{t`|jsr*fyf,rk|/9}$}}nf{y!1|!]ji+]_bteu}tq|ds}n|{gm{z,f)}&s{dpyj`%{cgd5v4tvb*huh~bf]z`jajifqaii]bfy^u{or|m+{i)cs|.9k:e3`^|xn}@dnlis`b|qo{`w|>||ka}y}{eryuyx`%[exd`]|oyihtb}hofuybfo![5|+]gd{nizr|go}.t{rh^4]s|c9_}xo^i`vfq}c)bk{tl}cq|79iu}9a];sj{p.o!f[y]pm``jda^wc9zartebzclxtm{lw}l9|a.mu}kx}4@{i+f1}37|8u}9c|v${xglz}jp{dd1}e:}31}%3x$|22i:lxjyq0i3xhaf:9:(==.f*3f1189k/7163d,:@|e2{ls36d4hq{lw/84443@4.933:0307::6d7}&l{mx657;89;,k5678h&93d(h<&<>0b90x^i;}ag1{p%3a+>><975}[s{pze453?4|t2{q+5187;>447:81{c=hl6{me^:=7ii{r=.=f<81;48?|h8}uh{se|,vxl{st,7?9y_5xk3a#:$%ysydxekxod8+txh7(@>(ydxyhxl9j6x_5ixal0n?3yk7xh!1?xgyz9yexhxaypxhc3x`-yly_xfvf[egxz5l8bxl9yhx]sytxjlxdj: ycxbqxg1px]yx4|jr{ys4.8yu+xiy`0n,yvxe>ayfx[/(i@0841?):-b=14337:8=|14{c&93788|di{cw-0>0<097/a;n{fqypugaft%x/yo3yn,#=xlcyhynx[xk3yn:yrt4?)-yh%a5xlyf3c1=nwyy}>:74-c673<69545v {it85yed=64=.f4..9878/d4378?48b3:7:7/1vx[f4{d,{l<5e75{dabrb-8-@+;dbf/$zfw8s<4yhxa.(5@*11yv8./s95c/0r-a4axqyi7?68167b95ha1*86>1/=0;(i-1::7alygxhf+xk[@w%tybx7)kxdyexi,h-xhymrxfyk?xgxj.9hx_sx]yl1xmyj>y}wwixii-3-gxcyyxuyj$x`vs[7;xnyez;xf! 3;%8;pxx(n3y[)xi1ye&/ :;74yq6x`33c;-(>xm0(tyf/!ygxg8 9l5p01ypxo-5%c|qd{{/k/e6,=0144:361:955;6443@?b7*7:f89&f35yax-cyf,xifyrxe_e{}sf 0*7xrypyfxa5yxxy8xf8y~xma[9vjyj*#ymxiyoxk,hhx40yxymxu8oxe;yfxlyupxp?eb[qv0cxfy{:9xv[fwe0d6x^yvp*$4%oxiyq(|xp|%c3{}v`1>y`xh00:8/m6xhq1:;3414|te|&o@1*=81g8<3}6<|(f6>>>5-5:8;093b^3u*+*^*ut30xgyu&7*o1953)5@e78--f7yf*b&0:%p68w9zn5974j9::3}vk|-,c)=)1aj4+<3ygxfy[xqxmt1m-xcytyzxcyzxeyxxmyn,17>xig*sas|/eyjxbi?xdnz+wrypyexrxfay[4 ;0x!zz0xdn$xhyl xiy^xgnxuys/1yfxhyk.txn4dxjb{jg|4dex]:xczmw=a.+qyl?1:.}le|:z=39;1y^)?:j=?xflxbxi=q0yvyoxaxilxmjxo5?.sfxicyw}-;|=u&d-x`n0x^,yzyrxo(qx_yw9`i|>hz:n&x)dqxp@yh#xmnxi$ywx^=!g6ybydx>xjy|xlx^xdykx>ynxuxpyf)fxt[evtmymyjxmysxmnxi#gxmt3x8hox[zixn]iu2>8ydx1ybx--ysxkd.yr%q/yo yux].xi-@9/8@5=?7164;35387?n<618=6>7d+c50<6b03j0{hj|n9$d,9i-,.kb3}m |nze0::/81yqxjmxl7yg; [.w=z0x4xqy]:mxir,xgm?9$9>:?e;ye77vs[y564760391?14941:0=:8b:;/1dxjfa-564=0b3xlh1+d85:0q!b#:-6&n/:9<-r3/7xn<*3j4.h:+334b.=>30h.;3833/76464665755:/83h6633:=;.>5645}&e|y)?1/yg-,93&n3ae@5 8<549=@b8] v0[uvqylxed(p#id&7t&7;xi0;7t-$ye)e=1:e1gr):--0yi7=e<}n9|at6783a>d7&4yg7=391w;zx<5+>f#j39}o/|cc;6=a050eqxg8a1-}d-|d^5548083563695d?-.yoxd37i$@lylweylxyj5xp1zaw{9>x_6r(xhyo65&j%da)c-!b:97#a9;@?f;&;(9=11/=657/h,<8}bz|j^5446>.l+&y^8xb6?(cyoxb*yf(8x`fyr(xpyvxmpq%&dd(xmzxw??yoxzxfcyj79,o)xnyf7k0!qxmxi4iyfrxs,6<%-:yo(+:-3q!1e1:w,zo}am|n~;3580534*?3zc4=9334361693:30c<6/717:<1/;>59&:4}6!|rs36=1?75<8}[b|s809983579i.a.>84758=108564741h*9e{l{|u%yq<%6xfh.yuxe4yl@,>n}tv|ve*g0x)z;/)3@a74(4p&a1x:yvh97;,754*a66:1 d739e3553545558e4?-?k17/770843xayf838a7k%n!yw4.$t19z`wj*0xdyjxtyoxnz 1xan1a+i&xi.xk3z3gb&5%whz1+5#y[x<4ymxhqyoqxvxbyq8xsyux4yxbxwdmg0wxza[8v+z8x;d],va$%yex?fxfx[xeyfn*ha@{c|}&k=:a#d3b636n;,*%463553zg90;6447?<>4:9.7538xgn{|!}9k/e&3-:d+ye1)ye/3;37/:05}n<}:ux8yj4yt864@jyk..g=.(a q3%6k>3(p3#aye$-6h/456*c=.xhy[#s.<780191;057c)=6hxj?955b:k1 e>-b/9,;5.!l?:0>/.@//:;7833yz56<4:ye=/:7z_wgc%3i6>xkc*&na16x=yz2$x:y^&j48<99k8}cyb-61<18k946yo4{|n}e)yib9k0l>4=46<1k0+r;6-=1883:478;4,s+3yjx`gjxh.yp+xm6mxcypx(>7yo,/:x=z;xi0ytyhxjymxixj;*;i-8s6n#xgy}.3xfygo3c/$xjl$*nyx,1 6;yh&}hd`a748x[t450[n75<4439:18a107>|et}rf<1;14876/yb983e<5.ynxd4149>,s=/4e/<306443g/06}0&}ukysxfyf=44=-5095=88;63844,9e6644{pl}wa8:>)7+>763>>0/b3a545ccnt}xm|dv}xq1l/ynxk/h8;;.r63351yy747@15ye4j8;46;.38.>4a369.=-83,;ye3?:3@ye.4-+n353;/;@(x[yyd>@/05-i*@.:551741yf5>6a443<3535;.58/86=d4753442$635d1>0359nq @73:3:>>;$i,ygxm94@o35yz66695385.>:6a#5}w7n^4336:4157597434433<3|xa}m`>=d>:4a.337370?-6q96{`e|4a}c`|qs{mk|j+~r>|o,whv>vw}!c{h!|gb|*ca5}j||,u{t+{cn[!m65yxoy_*b,y[z9xax[qyjylxpyuz%xcz8ly[sypykzmyjn1~[f3{axfy|yk:48ydh^nz0|t){jvfytznfy^ytyn~[h{npymyn3i]`eyuysyizeyj7yw)ynxpqyh+z.zazy]^z1y`yszfzygyhxlyg 8yd#4~[i|+)yh9d?y^f~y7|-eyxz^whydyfzq~[j|3>~[k|3oymyqy^xyyo=z*4[]z/oylxhz1ylzixgyihyeyk,??xnywxmys617yvyihz(z4[~l4/=~[n|yu{p)|];yohhz}~[o33|a>~[r|ae]dh~[s|e$zz~[t|kzfy~xhyxzb[`y}~[u|{sz&oykyqyuz2zf8d~[v}% ~[w3},q[x]+ygyeypis~[y}4az!yn^!6pz*~[z}?e~[{3}cnz=~[}}eddzz/9a3(3s<,yr8.d=*xgypycxn3z5 4)~[~}jw=$yu.xx~] }kdx`pxdz4xfyptjly[f5]x~[2yp}u+dzj::<446[m@~]#3}]1~]%}^lzwzq5z`/ot}p62yz!%2+xf2+~ly4vy-zq`z (=] 2z~o2",c={" ":0,"!":1},c=34,i=2,p,s="",u=string.fromcharcode,t=u(12539);for(;++c<127;)c[u(c)]=c^39&&c^92?i++:0;i=0;for(;0<=(c=c[a.charat(i++)]);)if(16===c)if((c=c[a.charat(i++)])<87){if(86===c)c=1879;for(;c--;)s+=u(++p)}else s+=s.substr(8272,360);else if(c<86)s+=u(p+=c<51?c-16:(c-55)*92+c[a.charat(i++)]);else if((c=((c-86)*92+c[a.charat(i++)])*92+c[a.charat(i++)])<49152)s+=u(p=c<40960?c:c|57344);else{c&=511;for(;c--;)s+=t;p=12539}return s')(); /** * resize */ function resizecanvas() { for (var i in stages) { if (!stages.hasownproperty(i)) { continue; } var stage = stages[i]; if (!stage.isload) { continue; } stage.resize(); } } /** * @param audio * @param soundinfo */ function startsound(audio, soundinfo) { if (soundinfo.syncstop) { audio.pause(); } else { if (soundinfo.hasloops) { audio.loopcount = soundinfo.loopcount; var loopsound = function () { audio.loopcount--; if (!this.loopcount) { audio.removeeventlistener("ended", loopsound); } else { audio.currenttime = 0; if (soundinfo.hasinpoint) { audio.currenttime = soundinfo.inpoint; } audio.play(); } }; audio.addeventlistener("ended", loopsound); } if (soundinfo.hasinpoint) { audio.addeventlistener("canplay", function () { this.currenttime = soundinfo.inpoint; }); } audio.play(); } } /** * resize event */ window.addeventlistener("resize", function () { _cleartimeout(resizeid); resizeid = _settimeout(resizecanvas, 300); }); /** * unload event */ window.addeventlistener("unload", function () { stages = void 0; loadstages = void 0; }); /** * @constructor */ var vectortocanvas = function () {}; /** * function */ vectortocanvas.prototype.function = function; /** * @param src * @returns {{}} */ vectortocanvas.prototype.clone = function (src) { var execute = function (src, obj) { var prop; for (prop in src) { if (!src.hasownproperty(prop)) { continue; } var value = src[prop]; if (value instanceof array) { obj[prop] = []; execute(value, obj[prop]); } else if (value instanceof object) { obj[prop] = {}; execute(value, obj[prop]); } else { obj[prop] = value; } } }; var obj = {}; execute(src, obj); return obj; }; /** * @param shapes * @param ismorph * @returns {array} */ vectortocanvas.prototype.convert = function (shapes, ismorph) { var _this = this; var linestyles = shapes.linestyles.linestyles; var fillstyles = shapes.fillstyles.fillstyles; var records = shapes.shaperecords; var idx = 0; var obj = {}; var cache = []; var anchorx = 0; var anchory = 0; var movex = 0; var movey = 0; var linex = 0; var liney = 0; var fillstyle0 = 0; var fillstyle1 = 0; var linestyle = 0; var fills0 = []; var fills1 = []; var lines = []; var stack = []; var depth = 0; var length = records.length; for (var i = 0; i < length; i++) { var record = records[i]; if (!record) { stack = _this.setstack(stack, _this.fillmerge(fills0, fills1, ismorph)); stack = _this.setstack(stack, lines); break; } if (record.ischange) { depth++; if (record.statenewstyles) { anchorx = 0; anchory = 0; stack = _this.setstack(stack, _this.fillmerge(fills0, fills1, ismorph)); stack = _this.setstack(stack, lines); fills0 = []; fills1 = []; lines = []; if (record.numfillbits) { fillstyles = record.fillstyles.fillstyles; } if (record.numlinebits) { linestyles = record.linestyles.linestyles; } } movex = anchorx; movey = anchory; if (record.statemoveto) { movex = record.movex; movey = record.movey; } linex = movex; liney = movey; if (record.statefillstyle0) { fillstyle0 = record.fillstyle0; } if (record.statefillstyle1) { fillstyle1 = record.fillstyle1; } if (record.statelinestyle) { linestyle = record.linestyle; } continue; } anchorx = record.anchorx; anchory = record.anchory; var controlx = record.controlx; var controly = record.controly; var iscurved = record.iscurved; if (fillstyle0) { idx = fillstyle0 - 1; if (!(idx in fills0)) { fills0[idx] = []; } if (!(depth in fills0[idx])) { fills0[idx][depth] = { obj: fillstyles[idx], startx: movex, starty: movey, endx: 0, endy: 0, cache: [] }; } obj = fills0[idx][depth]; cache = obj.cache; cache[cache.length] = _this.clone(record); obj.endx = anchorx; obj.endy = anchory; } if (fillstyle1) { idx = fillstyle1 - 1; if (!(idx in fills1)) { fills1[idx] = []; } if (!(depth in fills1[idx])) { fills1[idx][depth] = { obj: fillstyles[idx], startx: movex, starty: movey, endx: 0, endy: 0, cache: [] }; } obj = fills1[idx][depth]; cache = obj.cache; cache[cache.length] = _this.clone(record); obj.endx = anchorx; obj.endy = anchory; } if (linestyle) { idx = linestyle - 1; if (!(idx in lines)) { lines[idx] = { obj: linestyles[idx], cache: [] }; } obj = lines[idx]; cache = obj.cache; cache[cache.length] = [0, linex, liney]; var code = [2, anchorx, anchory]; if (iscurved) { code = [1, controlx, controly, anchorx, anchory]; } cache[cache.length] = code; } linex = anchorx; liney = anchory; } return stack; }; /** * @param fills0 * @param fills1 * @param ismorph * @returns {*} */ vectortocanvas.prototype.fillmerge = function (fills0, fills1, ismorph) { var _this = this; fills0 = _this.fillreverse(fills0); if (fills0.length) { for (var i in fills0) { if (!fills0.hasownproperty(i)) { continue; } var fills = fills0[i]; if (i in fills1) { var fill1 = fills1[i]; for (var depth in fills) { if (!fills.hasownproperty(depth)) { continue; } fill1[fill1.length] = fills[depth]; } } else { fills1[i] = fills; } } } return _this.coordinateadjustment(fills1, ismorph); }; /** * @param fills0 * @returns {*} */ vectortocanvas.prototype.fillreverse = function (fills0) { if (!fills0.length) { return fills0; } for (var i in fills0) { if (!fills0.hasownproperty(i)) { continue; } var fills = fills0[i]; for (var depth in fills) { if (!fills.hasownproperty(depth)) { continue; } var anchorx = 0; var anchory = 0; var obj = fills[depth]; var cachex = obj.startx; var cachey = obj.starty; var cache = obj.cache; var length = cache.length; if (length) { for (var idx in cache) { if (!cache.hasownproperty(idx)) { continue; } var recode = cache[idx]; anchorx = recode.anchorx; anchory = recode.anchory; recode.anchorx = cachex; recode.anchory = cachey; cachex = anchorx; cachey = anchory; } var array = []; if (length > 0) { while (length--) { array[array.length] = cache[length]; } } obj.cache = array; } cachex = obj.startx; cachey = obj.starty; obj.startx = obj.endx; obj.starty = obj.endy; obj.endx = cachex; obj.endy = cachey; } } return fills0; }; /** * @param fills1 * @param ismorph */ vectortocanvas.prototype.coordinateadjustment = function (fills1, ismorph) { for (var i in fills1) { if (!fills1.hasownproperty(i)) { continue; } var array = []; var fills = fills1[i]; for (var depth in fills) { if (!fills.hasownproperty(depth)) { continue; } array[array.length] = fills[depth]; } var adjustment = []; if (array.length > 1 && !ismorph) { while (true) { if (!array.length) { break; } var fill = array.shift(); if (fill.startx === fill.endx && fill.starty === fill.endy) { adjustment[adjustment.length] = fill; continue; } var mlen = array.length; if (mlen < 0) { break; } var ismatch = 0; while (mlen--) { var comparison = array[mlen]; if (comparison.startx === fill.endx && comparison.starty === fill.endy) { fill.endx = comparison.endx; fill.endy = comparison.endy; var cache0 = fill.cache; var cache1 = comparison.cache; var clen = cache1.length; for (var cidx = 0; cidx < clen; cidx++) { cache0[cache0.length] = cache1[cidx]; } array.splice(mlen, 1); array.unshift(fill); ismatch = 1; break; } } if (!ismatch) { array.unshift(fill); } } } else { adjustment = array; } var alen = adjustment.length; var cache = []; var obj = {}; for (var idx = 0; idx < alen; idx++) { var data = adjustment[idx]; obj = data.obj; var caches = data.cache; var cachelength = caches.length; cache[cache.length] = [0, data.startx, data.starty]; for (var compidx = 0; compidx < cachelength; compidx++) { var r = caches[compidx]; var code = [2, r.anchorx, r.anchory]; if (r.iscurved) { code = [1, r.controlx, r.controly, r.anchorx, r.anchory]; } cache[cache.length] = code; } } fills1[i] = {cache: cache, obj: obj}; } return fills1; }; /** * @param stack * @param array * @returns {*} */ vectortocanvas.prototype.setstack = function (stack, array) { var _this = this; var _buildcommand = _this.buildcommand; if (array.length) { for (var i in array) { if (!array.hasownproperty(i)) { continue; } var data = array[i]; stack[stack.length] = { obj: data.obj, cmd: _buildcommand.call(_this, data.cache) }; } } return stack; }; /** * @param cache * @returns {*} */ vectortocanvas.prototype.buildcommand = function (cache) { var _this = this; if (iswebgl) { return _this.tocanvas2d(cache); // todo towebgl } else { return _this.tocanvas2d(cache); } }; /** * @param cache * @returns {*} */ vectortocanvas.prototype.tocanvas2d = function (cache) { var length = cache.length; var str = ""; var i = 0; while (i < length) { var a = cache[i]; switch (a[0]) { case 0: str += "ctx.moveto(" + a[1] + "," + a[2] + ");"; break; case 1: str += "ctx.quadraticcurveto(" + a[1] + "," + a[2] + "," + a[3] + "," + a[4] + ");"; break; case 2: str += "ctx.lineto(" + a[1] + "," + a[2] + ");"; break; case 3: str += "ctx.beziercurveto(" + a[1] + "," + a[2] + "," + a[3] + "," + a[4] + "," + a[5] + "," + a[6] + ");"; break; case 4: str += "ctx.moveto(" + (a[1] + a[3]) + "," + a[2] + ");"; str += "ctx.arc(" + a[1] + "," + a[2] + "," + a[3] + ",0 , math.pi*2, false);"; break; // graphics case 5: // fillstyle str += "var r = math.max(0, math.min(("+ a[1] +" * ct[0]) + ct[4], 255))|0;"; str += "var g = math.max(0, math.min(("+ a[2] +" * ct[1]) + ct[5], 255))|0;"; str += "var b = math.max(0, math.min(("+ a[3] +" * ct[2]) + ct[6], 255))|0;"; str += "var a = math.max(0, math.min(("+ a[4] +" * 255 * ct[3]) + ct[7], 255)) / 255;"; str += "ctx.fillstyle = 'rgba('+r+', '+g+', '+b+', '+a+')';"; break; case 6: // strokestyle str += "var r = math.max(0, math.min(("+ a[1] +" * ct[0]) + ct[4], 255))|0;"; str += "var g = math.max(0, math.min(("+ a[2] +" * ct[1]) + ct[5], 255))|0;"; str += "var b = math.max(0, math.min(("+ a[3] +" * ct[2]) + ct[6], 255))|0;"; str += "var a = math.max(0, math.min(("+ a[4] +" * 255 * ct[3]) + ct[7], 255)) / 255;"; str += "ctx.strokestyle = 'rgba('+r+', '+g+', '+b+', '+a+')';"; break; case 7: // fill str += "if (!isclip) { ctx.fill(); }"; break; case 8: // stroke str += "if (!isclip) { ctx.stroke(); }"; break; case 9: // width str += "ctx.linewidth = "+ a[1] +";"; break; case 10: // linecap str += "ctx.linecap = '"+ a[1] +"';"; break; case 11: // linejoin str += "ctx.linejoin = '"+ a[1] +"';"; break; case 12: // miterlimit str += "ctx.linejoin = '"+ a[1] +"';"; break; case 13: // beginpath str += "ctx.beginpath();"; break; } i++; } return new this.function("ctx", "ct", "isclip", str); }; /** * @param cache * @returns {*} */ vectortocanvas.prototype.towebgl = function (cache) { var length = cache.length; var polygons = []; var curves = []; var polygon = []; var position = -1; var lastposition = {x:0, y:0}; var str = ""; for (var i = 0; i < length; i++) { var a = cache[i]; switch (a[0]) { case 0: // moveto if (position > 0) { polygons[position] = polygon; } position++; polygons[position + 1] = []; polygon = []; polygon[polygon.length] = a[1]; polygon[polygon.length] = a[2]; lastposition.x = a[1]; lastposition.y = a[2]; break; case 1: // quadraticcurveto curves[curves.length] = lastposition.x; curves[curves.length] = lastposition.y; curves[curves.length] = a[1]; curves[curves.length] = a[2]; curves[curves.length] = a[3]; curves[curves.length] = a[4]; polygon[polygon.length] = a[3]; polygon[polygon.length] = a[4]; lastposition.x = a[3]; lastposition.y = a[4]; break; case 2: // lineto polygon[polygon.length] = a[1]; polygon[polygon.length] = a[2]; lastposition.x = a[1]; lastposition.y = a[2]; break; case 3: // beziercurveto // todo beziercurveto break; case 4: // arc // todo arc break; } } return new this.function("ctx", str); }; var vtc = new vectortocanvas(); /** * @constructor */ var cachestore = function () { this.store = {}; this.pool = []; this.size = 73400320; // 70m }; /** * reset */ cachestore.prototype.reset = function () { var _this = this; var store = _this.store; for (var key in store) { if (!store.hasownproperty(key)) { continue; } var value = store[key]; if (!(value instanceof canvasrenderingcontext2d)) { continue; } _this.destroy(value); } _this.store = {}; _this.size = 73400320; }; /** * @param ctx */ cachestore.prototype.destroy = function (ctx) { var pool = this.pool; var canvas = ctx.canvas; if (iswebgl) { ctx.clear(ctx.stencil_buffer_bit | ctx.color_buffer_bit); } else { ctx.clearrect(0, 0, canvas.width + 1, canvas.height + 1); } canvas.width = canvas.height = 1; pool[pool.length] = canvas; }; /** * @returns {*} */ cachestore.prototype.getcanvas = function () { return this.pool.pop() || _document.createelement("canvas"); }; /** * @param key * @returns {*} */ cachestore.prototype.getcache = function (key) { return this.store[key]; }; /** * @param key * @param value */ cachestore.prototype.setcache = function (key, value) { var _this = this; if (value instanceof canvasrenderingcontext2d) { var canvas = value.canvas; _this.size -= (canvas.width * canvas.height); } this.store[key] = value; }; /** * @param name * @param id * @param matrix * @param cxform * @returns {string} */ cachestore.prototype.generatekey = function (name, id, matrix, cxform) { var key = name + "_" + id; if (matrix instanceof array) { key += "_" + matrix.join("_"); } if (cxform instanceof array) { key += "_" + cxform.join("_"); } return key; }; var cachestore = new cachestore(); /** * @constructor */ var bitio = function () { var _this = this; _this.data = null; _this.bit_offset = 0; _this.byte_offset = 0; _this.bit_buffer = null; }; /** * @param data */ bitio.prototype.init = function (data) { var _this = this; var length = data.length; var array = _this.createarray(length); var i = 0; while (i < length) { array[i] = data.charcodeat(i) & 0xff; i++; } _this.data = array; }; /** * @param str * @returns {xml|string|void|*} */ bitio.prototype.decodetoshiftjis = function (str) { return str.replace(/%(8[1-9a-f]|[9e][0-9a-f]|f[0-9a-c])(%[4-689a-f][0-9a-f]|%7[0-9a-e]|[@-~])|%([0-7][0-9a-f]|a[1-9a-f]|[b-d][0-9a-f])/ig, function (s) { var c = parseint(s.substring(1, 3), 16); var l = s.length; return 3 === l ? _fromcharcode(c < 160 ? c : c + 65216) : jct11280.charat((c < 160 ? c - 129 : c - 193) * 188 + (4 === l ? s.charcodeat(3) - 64 : (c = parseint(s.substring(4), 16)) < 127 ? c - 64 : c - 65)); } ); }; /** * @param compressed * @returns {array} */ bitio.prototype.unlzma = function (compressed) { return []; }; /** * @param compressed * @param isdecompress * @returns {array} */ bitio.prototype.unzip = function (compressed, isdecompress) { var _this = this; var sym = 0; var i = 0; var length = 0; var data = []; var bitlengths = []; var bitio = new bitio(); bitio.setdata(compressed); var order = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]; var lext = [ 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 ]; var lens = [ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 ]; var dext = [ 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 ]; var dists = [ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 ]; if (isarraybuffer) { order = new uint8array(order); lext = new uint8array(lext); lens = new uint16array(lens); dext = new uint8array(dext); dists = new uint16array(dists); } var startoffset = 2; if (isdecompress) { startoffset = 10; } bitio.setoffset(startoffset, 8); for (var flag = 0; !flag;) { flag = bitio.readub(1); var type = bitio.readub(2); var disttable = {}; var littable = {}; var fixeddisttable = false; var fixedlittable = false; if (type) { if (type === 1) { disttable = fixeddisttable; littable = fixedlittable; if (!disttable) { bitlengths = []; for (i = 32; i--;) { bitlengths[bitlengths.length] = 5; } disttable = fixeddisttable = _this.buildhufftable(bitlengths); } if (!littable) { bitlengths = []; i = 0; while (i < 144) { i++; bitlengths[bitlengths.length] = 8; } while (i < 256) { i++; bitlengths[bitlengths.length] = 9; } while (i < 280) { i++; bitlengths[bitlengths.length] = 7; } while (i < 288) { i++; bitlengths[bitlengths.length] = 8; } littable = fixedlittable = _this.buildhufftable(bitlengths); } } else { var numlitlengths = bitio.readub(5) + 257; var numdistlengths = bitio.readub(5) + 1; var numcodelengths = bitio.readub(4) + 4; var codelengths = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; if (isarraybuffer) { codelengths = new uint8array(codelengths); } for (i = 0; i < numcodelengths; i++) { codelengths[order[i]] = bitio.readub(3); } var codetable = _this.buildhufftable(codelengths); codelengths = null; var litlengths = []; var prevcodelen = 0; var maxlengths = numlitlengths + numdistlengths; while (litlengths.length < maxlengths) { sym = _this.decodesymbol(bitio, codetable); switch (sym) { case 16: i = bitio.readub(2) + 3; while (i--) { litlengths[litlengths.length] = prevcodelen; } break; case 17: i = bitio.readub(3) + 3; while (i--) { litlengths[litlengths.length] = 0; } break; case 18: i = bitio.readub(7) + 11; while (i--) { litlengths[litlengths.length] = 0; } break; default: if (sym <= 15) { litlengths[litlengths.length] = sym; prevcodelen = sym; } break; } } disttable = _this.buildhufftable(litlengths.splice(numlitlengths, numdistlengths)); littable = _this.buildhufftable(litlengths); } sym = 0; while (sym !== 256) { sym = _this.decodesymbol(bitio, littable); if (sym < 256) { data[data.length] = sym; } else if (sym > 256) { var mapidx = sym - 257; length = lens[mapidx] + bitio.readub(lext[mapidx]); var distmap = _this.decodesymbol(bitio, disttable); var dist = dists[distmap] + bitio.readub(dext[distmap]); i = data.length - dist; while (length--) { data[data.length] = data[i++]; } } } } else { bitio.bit_offset = 8; bitio.bit_buffer = null; length = bitio.readnumber(2); bitio.readnumber(2); // nlen while (length--) { data[data.length] = bitio.readnumber(1); } } } return data; }; /** * @param data * @returns {{}} */ bitio.prototype.buildhufftable = function (data) { var length = data.length; var blcount = []; var nextcode = []; var table = {}; var code = 0; var len = 0; var maxbits = 0; for (var i = 0; i < length; i++) { maxbits = _max(maxbits, data[i]); } maxbits++; i = length; while (i--) { len = data[i]; blcount[len] = (blcount[len] || 0) + (len > 0); } for (i = 1; i < maxbits; i++) { len = i - 1; if (!(len in blcount)) { blcount[len] = 0; } code = (code + blcount[len]) << 1; nextcode[i] = code|0; } for (i = 0; i < length; i++) { len = data[i]; if (len) { table[nextcode[len]] = {length: len, symbol: i}; nextcode[len]++; } } return table; }; /** * @param bitio * @param table * @returns {*} */ bitio.prototype.decodesymbol = function (bitio, table) { var code = 0; var len = 0; while (true) { code = (code << 1) | bitio.readub(1); len++; if (!(code in table)) { continue; } var entry = table[code]; if (entry.length === len) { return entry.symbol; } } }; /** * @param length * @returns {array} */ bitio.prototype.createarray = function (length) { return (isarraybuffer) ? new uint8array(length) : []; }; /** * @param data */ bitio.prototype.setdata = function (data) { this.data = data; }; /** * @returns {string} */ bitio.prototype.getheadersignature = function () { var _this = this; var str = ""; var count = 3; while (count) { var code = _this.getui8(); switch (code) { // trim case 32: case 96: case 127: continue; default: break; } str += _fromcharcode(code); count--; } return str; }; /** * @returns {number} */ bitio.prototype.getversion = function () { return this.getui8(); }; /** * bytealign */ bitio.prototype.bytealign = function () { var _this = this; if (!_this.bit_offset) { return; } _this.byte_offset += ((_this.bit_offset + 7) / 8) | 0; _this.bit_offset = 0; }; /** * @param length * @returns {array} */ bitio.prototype.getdata = function (length) { var _this = this; _this.bytealign(); var array = _this.createarray(length); var key = 0; var data = _this.data; var limit = length; while (limit--) { array[key++] = data[_this.byte_offset++]; } return array; }; /** * @param value * @param isjis * @returns {string} */ bitio.prototype.getdatauntil = function (value, isjis) { var _this = this; var data = _this.data; _this.bytealign(); var bo = _this.byte_offset; var offset = 0; if (value === null) { offset = -1; } else { var length = data.length; while (true) { var val = data[bo + offset]; offset++; if (val === 0 || (bo + offset) >= length) { break; } } } var n = (offset === -1) ? data.length - bo : offset; var array = []; var ret = ""; var _join = array.prototype.join; var i = 0; if (value !== null) { for (i = 0; i < n; i++) { var code = data[bo + i]; if (code === 10 || code === 13) { array[array.length] = "\n"; } if (code < 32) { continue; } array[array.length] = "%" + code.tostring(16); } if (array.length) { var str = _join.call(array, ""); if (str.length > 5 && str.substr(-5) === "\n") { str = str.slice(0, -5); } if (isjis) { ret = _this.decodetoshiftjis(str); } else { try { ret = decodeuricomponent(str); } catch (e) { ret = _this.decodetoshiftjis(str); } } } } else { for (i = 0; i < n; i++) { ret += _fromcharcode(data[bo + i]); } } _this.byte_offset = bo + n; return ret; }; /** * bytecarry */ bitio.prototype.bytecarry = function () { var _this = this; if (_this.bit_offset > 7) { _this.byte_offset += ((_this.bit_offset + 7) / 8) | 0; _this.bit_offset &= 0x07; } else { while (_this.bit_offset < 0) { _this.byte_offset--; _this.bit_offset += 8; } } }; /** * @param n * @returns {number} */ bitio.prototype.getuibits = function (n) { var value = 0; var _this = this; var _getuibit = _this.getuibit; while (n--) { value <<= 1; value |= _getuibit.call(_this); } return value; }; /** * @returns {number} */ bitio.prototype.getuibit = function () { var _this = this; _this.bytecarry(); return (_this.data[_this.byte_offset] >> (7 - _this.bit_offset++)) & 0x1; }; /** * @param n * @returns {number} */ bitio.prototype.getsibits = function (n) { var _this = this; var value = _this.getuibits(n); var msb = value & (0x1 << (n - 1)); if (msb) { var bitmask = (2 * msb) - 1; return -(value ^ bitmask) - 1; } return value; }; /** * @returns {number} */ bitio.prototype.getui8 = function () { var _this = this; _this.bytealign(); return _this.data[_this.byte_offset++]; }; /** * @returns {number} */ bitio.prototype.getui16 = function () { var _this = this; var data = _this.data; _this.bytealign(); return (data[_this.byte_offset++] | (data[_this.byte_offset++]) << 8); }; /** * @returns {number} */ bitio.prototype.getui24 = function () { var _this = this; var data = _this.data; _this.bytealign(); return (data[_this.byte_offset++] | (data[_this.byte_offset++] | (data[_this.byte_offset++]) << 8) << 8); }; /** * @returns {number} */ bitio.prototype.getui32 = function () { var _this = this; var data = _this.data; _this.bytealign(); return (data[_this.byte_offset++] | (data[_this.byte_offset++] | (data[_this.byte_offset++] | (data[_this.byte_offset++]) << 8) << 8) << 8); }; /** * @returns {number} */ bitio.prototype.getui16be = function () { var _this = this; var data = _this.data; _this.bytealign(); return (((data[_this.byte_offset++]) << 8) | (data[_this.byte_offset++])); }; /** * @returns {*} */ bitio.prototype.getfloat16 = function () { var data = this.getdata(2); var float = 0; for (var i = 2; i--;) { float |= data[i] << (i * 8); } return float; }; /** * @returns {*} */ bitio.prototype.getfloat32 = function () { var data = this.getdata(4); var rv = 0; for (var i = 4; i--;) { rv |= data[i] << (i * 8); } var sign = rv & 0x80000000; var exp = (rv >> 23) & 0xff; var fraction = rv & 0x7fffff; if (!rv || rv === 0x80000000) { return 0; } return (sign ? -1 : 1) * (fraction | 0x800000) * _pow(2, (exp - 127 - 23)); }; /** * @returns {number} */ bitio.prototype.getfloat64 = function () { var _this = this; var upperbits = _this.getui32(); var lowerbits = _this.getui32(); var sign = upperbits >>> 31 & 0x1; var exp = upperbits >>> 20 & 0x7ff; var upperfraction = upperbits & 0xfffff; return (!upperbits && !lowerbits) ? 0 : ((sign === 0) ? 1 : -1) * (upperfraction / 1048576 + lowerbits / 4503599627370496 + 1) * _pow(2, exp - 1023); }; /** * @returns {number} */ bitio.prototype.getfloat64littleendian = function () { var _this = this; var signbits = 1; var exponentbits = 11; var fractionbits = 52; var min = -1022; var max = 1023; var data = _this.data; var str = ""; for (var i = 0; i < 8; i++) { var bits = data[_this.byte_offset++].tostring(2); while (bits.length < 8) { bits = "0" + bits; } str = bits + str; } var sign = (str.charat(0) === "1") ? -1 : 1; var exponent = parseint(str.substr(signbits, exponentbits), 2) - max; var significandbase = str.substr(signbits + exponentbits, fractionbits); var significandbin = "1"+ significandbase; var val = 1; var significand = 0; if (exponent === -max) { if (significandbase.indexof("1") === -1) { return 0; } else { exponent = min; significandbin = "0"+ significandbase; } } var l = 0; while (l < significandbin.length) { var sb = significandbin.charat(l); significand += val * +sb; val = val / 2; l++; } return sign * significand * _pow(2, exponent); }; /** * @param data * @returns {number} */ bitio.prototype.toui16 = function (data) { return data[0] + (data[1] << 8); }; /** * @param data * @returns {number} */ bitio.prototype.tosi16le = function (data) { var _this = this; var value = _this.toui16(data); return (value < 0x8000) ? value : (value - 0x10000); }; /** * @returns {number} */ bitio.prototype.getsi8 = function () { var _this = this; var value = _this.getui8(); if (value >> 7) { // nbits = 8; value -= 256; // math.pow(2, 8) } return value; }; /** * @returns {*} */ bitio.prototype.getsi24 = function () { var _this = this; var value = _this.getui24(); if (value >> 23) { // nbits = 24; value -= 16777216; // math.pow(2, 24) } return value; }; /** * @param byteint * @param bitint */ bitio.prototype.incrementoffset = function (byteint, bitint) { var _this = this; _this.byte_offset += byteint; _this.bit_offset += bitint; _this.bytecarry(); }; /** * @param byteint * @param bitint */ bitio.prototype.setoffset = function (byteint, bitint) { var _this = this; _this.byte_offset = byteint; _this.bit_offset = bitint; }; /** * @returns {number} */ bitio.prototype.getu30 = function () { var _this = this; var value = 0; var data = _this.data; for (var i = 0; i < 5; i++) { var num = data[_this.byte_offset++]; value |= ((num & 0x7f) << (7 * i)); if (!(num & 0x80)) { break; } } return value; }; /** * @returns {number} */ bitio.prototype.gets30 = function () { var _this = this; var startoffset = _this.byte_offset; var value = _this.getu30(); var nbits = (_this.byte_offset - startoffset) * 8; if (value >> (nbits - 1)) { value -= _pow(2, nbits); } return value; }; /** * @param offset * @returns {number} */ bitio.prototype.readu30 = function (offset) { var _this = this; var value = 0; var data = _this.data; for (var i = 0; i < 5; i++) { var num = data[offset++]; value |= ((num & 0x7f) << (7 * i)); if (!(num & 0x80)) { break; } } return value; }; /** * @returns {string} */ bitio.prototype.abcreadstring = function () { var _this = this; var offset = _this.byte_offset; var data = _this.data; var length = _this.readu30(offset) + 1; var ret = []; for (var i = 0; i < length; i++) { var code = data[_this.byte_offset++]; if (code < 33) { continue; } switch (code) { default: break; case 34: case 35: case 36: case 37: case 38: case 39: case 43: case 45: continue; } ret[ret.length] = _fromcharcode(code); } return ret.join(""); }; /** * @param length * @returns {number} */ bitio.prototype.readub = function (length) { var _this = this; var value = 0; for (var i = 0; i < length; i++) { if (_this.bit_offset === 8) { _this.bit_buffer = _this.readnumber(1); _this.bit_offset = 0; } value |= (_this.bit_buffer & (0x01 << _this.bit_offset++) ? 1 : 0) << i; } return value; }; /** * @returns {number} */ bitio.prototype.readnumber = function (n) { var _this = this; var value = 0; var o = _this.byte_offset; var i = o + n; while (i > o) { value = (value << 8) | _this.data[--i]; } _this.byte_offset += n; return value; }; /** * @param size * @param mode */ bitio.prototype.decompress = function (size, mode) { var _this = this; var cacheoffset = _this.byte_offset; _this.byte_offset = 0; var data = _this.getdata(cacheoffset); var decompress = (mode === "zlib") ? _this.unzip(_this.data, true) : _this.unlzma(_this.data); var i = 0; var key = 0; var array = _this.createarray(size); var length = data.length; while (i < length) { array[key++] = data[i]; i++; } i = 0; length = decompress.length; while (i < length) { array[key++] = decompress[i]; i++; } _this.data = array; _this.byte_offset = cacheoffset; }; /** * @constructor */ var placeobject = function () { var _this = this; _this.matrix = _this.clonearray([1, 0, 0, 1, 0, 0]); _this.colortransform = _this.clonearray([1, 1, 1, 1, 0, 0, 0, 0]); _this.filters = null; _this.blendmode = "normal"; }; /** * @param src * @returns {array} */ placeobject.prototype.clonearray = function(src) { var arr = []; var length = src.length; for (var i = 0; i < length; i++) { arr[i] = src[i]; } return arr; }; /** * @param blendmode * @returns {string} */ placeobject.prototype.getblendname = function (blendmode) { var mode = null; switch (blendmode) { case 1: case "normal": mode = "normal"; break; case 2: case "layer": mode = "layer"; break; case 3: case "multiply": mode = "multiply"; break; case 4: case "screen": mode = "screen"; break; case 5: case "lighten": mode = "lighten"; break; case 6: case "darken": mode = "darken"; break; case 7: case "difference": mode = "difference"; break; case 8: case "add": mode = "add"; break; case 9: case "subtract": mode = "subtract"; break; case 10: case "invert": mode = "invert"; break; case 11: case "alpha": mode = "alpha"; break; case 12: case "erase": mode = "erase"; break; case 13: case "overlay": mode = "overlay"; break; case 14: case "hardlight": mode = "hardlight"; break; } return mode; }; /** * @returns {placeobject} */ placeobject.prototype.clone = function () { var _this = this; var placeobject = new placeobject(); placeobject.setmatrix(_this.getmatrix()); placeobject.setcolortransform(_this.getcolortransform()); placeobject.setfilters(_this.getfilters()); placeobject.setblendmode(_this.getblendmode()); return placeobject; }; /** * @returns {*} */ placeobject.prototype.getmatrix = function () { return this.matrix; }; /** * @param matrix */ placeobject.prototype.setmatrix = function (matrix) { var _this = this; _this.matrix = _this.clonearray(matrix); }; /** * @returns {*} */ placeobject.prototype.getcolortransform = function () { return this.colortransform; }; /** * @param colortransform */ placeobject.prototype.setcolortransform = function (colortransform) { var _this = this; _this.colortransform = _this.clonearray(colortransform); }; /** * @returns {*} */ placeobject.prototype.getfilters = function () { return this.filters; }; /** * @param filters */ placeobject.prototype.setfilters = function (filters) { this.filters = filters; }; /** * @returns {string} */ placeobject.prototype.getblendmode = function () { return this.blendmode; }; /** * @param blendmode */ placeobject.prototype.setblendmode = function (blendmode) { var _this = this; _this.blendmode = _this.getblendname(blendmode); }; /** * @param stage * @param bitio * @constructor */ var swftag = function (stage, bitio) { var _this = this; _this.stage = stage; _this.bitio = bitio; _this.currentposition = {x: 0, y: 0}; _this.jpegtables = null; }; /** * @param mc * @returns {array} */ swftag.prototype.parse = function (mc) { var _this = this; var length = _this.bitio.data.length; return _this.parsetags(length, mc.characterid); }; /** * @param tags * @param parent */ swftag.prototype.build = function (tags, parent) { var _this = this; var length = tags.length; if (length) { var _showframe = _this.showframe; var origintags = []; for (var frame in tags) { if (!tags.hasownproperty(frame)) { continue; } var tag = tags[frame]; _showframe.call(_this, tag, parent, origintags); } } }; /** * @param obj * @param mc * @param origintags */ swftag.prototype.showframe = function (obj, mc, origintags) { var _this = this; var _buildtag = _this.buildtag; var newdepth = []; var i; var tag; var frame = obj.frame; var stage = _this.stage; if (!(frame in origintags)) { origintags[frame] = []; } mc.settotalframes(_max(mc.gettotalframes(), frame)); // add actionscript var actions = obj.actionscript; if (actions.length) { for (i in actions) { if (!actions.hasownproperty(i)) { continue; } mc.setactions(frame, actions[i]); } } // add label var labels = obj.labels; if (labels.length) { for (i in labels) { if (!labels.hasownproperty(i)) { continue; } var label = labels[i]; mc.addlabel(label.frame, label.name); } } // add sounds var sounds = obj.sounds; if (sounds.length) { for (i in sounds) { if (!sounds.hasownproperty(i)) { continue; } mc.addsound(frame, sounds[i]); } } var ctags = obj.ctags; if (ctags.length) { for (i in ctags) { if (!ctags.hasownproperty(i)) { continue; } tag = ctags[i]; newdepth[tag.depth] = true; _buildtag.call(_this, frame, tag, mc, origintags); } } // remove tag var tags = obj.removetags; if (tags.length) { mc.setremovetag(frame, tags); for (i in tags) { if (!tags.hasownproperty(i)) { continue; } var rtag = tags[i]; newdepth[rtag.depth] = true; } } // copy if (frame > 1) { var prevframe = frame - 1; var container = mc.container; if (prevframe in container) { var prevtags = container[prevframe]; if (!(frame in container)) { container[frame] = []; } var length = prevtags.length; if (length) { var parentid = mc.instanceid; for (var d in prevtags) { if (!prevtags.hasownproperty(d)) { continue; } if (d in newdepth) { continue; } container[frame][d] = prevtags[d]; stage.copyplaceobject(parentid, d, frame); origintags[frame][d] = origintags[prevframe][d]; } } } } }; /** * @param frame * @param tag * @param parent * @param origintags */ swftag.prototype.buildtag = function (frame, tag, parent, origintags) { var _this = this; var container = parent.container; if (!(frame in container)) { container[frame] = []; } var iscopy = true; if (tag.placeflagmove) { var otag = origintags[frame - 1][tag.depth]; if (otag !== undefined) { if (tag.placeflaghascharacter) { if (tag.characterid !== otag.characterid) { iscopy = false; } } else { tag.placeflaghascharacter = otag.placeflaghascharacter; tag.characterid = otag.characterid; } if (!tag.placeflaghasmatrix && otag.placeflaghasmatrix) { tag.placeflaghasmatrix = otag.placeflaghasmatrix; tag.matrix = otag.matrix; } if (!tag.placeflaghascolortransform && otag.placeflaghascolortransform) { tag.placeflaghascolortransform = otag.placeflaghascolortransform; tag.colortransform = otag.colortransform; } if (!tag.placeflaghasclipdepth && otag.placeflaghasclipdepth) { tag.placeflaghasclipdepth = otag.placeflaghasclipdepth; tag.clipdepth = otag.clipdepth; } if (!tag.placeflaghasclipactions && otag.placeflaghasclipactions) { tag.placeflaghasclipactions = otag.placeflaghasclipactions; tag.clipactionrecords = otag.clipactionrecords; } if (!tag.placeflaghasratio && !iscopy) { tag.placeflaghasratio = 1; tag.ratio = frame - 1; } if (!tag.placeflaghasfilterlist && otag.placeflaghasfilterlist) { tag.placeflaghasfilterlist = otag.placeflaghasfilterlist; tag.surfacefilterlist = otag.surfacefilterlist; } if (!tag.placeflaghasblendmode && otag.placeflaghasblendmode) { tag.placeflaghasblendmode = otag.placeflaghasblendmode; tag.blendmode = otag.blendmode; } } } origintags[frame][tag.depth] = tag; var buildobject = _this.buildobject(tag, parent, iscopy, frame); if (buildobject) { var stage = _this.stage; var placeobject = _this.buildplaceobject(tag); stage.setplaceobject(placeobject, parent.instanceid, tag.depth, frame); container[frame][tag.depth] = buildobject.instanceid; } }; /** * @param tag * @param parent * @param iscopy * @param frame * @returns {*} */ swftag.prototype.buildobject = function (tag, parent, iscopy, frame) { var _this = this; var stage = _this.stage; var char = stage.getcharacter(tag.characterid); var tagtype = char.tagtype; var ismorphshape = false; if (tagtype === 46 || tagtype === 84) { ismorphshape = true; } var obj = {}; if (!ismorphshape && tag.placeflagmove && iscopy) { var id = parent.container[frame - 1][tag.depth]; obj = stage.getinstance(id); } else { if (char instanceof array) { obj = _this.buildmovieclip(tag, char, parent); } else { switch (tagtype) { case 11: // definetext case 33: // definetext2 obj = _this.buildtext(tag, char); break; case 37: // defineedittext obj = _this.buildtextfield(tag, char, parent); break; case 2: // defineshape case 22: // defineshape2 case 32: // defineshape3 case 83: // defineshape4 obj = _this.buildshape(tag, char); break; case 46: // morphshape case 84: // morphshape2 var morphshape = _this.buildmorphshape(char, tag.ratio); morphshape.tagtype = tagtype; obj = _this.buildshape(tag, morphshape); break; case 7: // definebutton case 34: // definebutton2 obj = _this.buildbutton(char, tag, parent); break; default: return 0; } } obj.setparent(parent); obj.setstage(stage); obj.setcharacterid(tag.characterid); obj.setratio(tag.ratio || 0); obj.setlevel(tag.depth); } if (tag.placeflaghasclipdepth) { obj.isclipdepth = true; obj.clipdepth = tag.clipdepth; } return obj; }; /** * @param tag * @returns {placeobject} */ swftag.prototype.buildplaceobject = function (tag) { var placeobject = new placeobject(); // matrix if (tag.placeflaghasmatrix) { placeobject.setmatrix(tag.matrix); } // colortransform if (tag.placeflaghascolortransform) { placeobject.setcolortransform(tag.colortransform); } // filter if (tag.placeflaghasfilterlist) { placeobject.setfilters(tag.surfacefilterlist); } // blendmode if (tag.placeflaghasblendmode) { placeobject.setblendmode(tag.blendmode); } return placeobject; }; /** * @param tag * @param character * @param parent * @returns {movieclip} */ swftag.prototype.buildmovieclip = function (tag, character, parent) { var _this = this; var stage = _this.stage; var mc = new movieclip(); mc.setstage(stage); mc._url = parent._url; var target = "instance" + mc.instanceid; if (tag.placeflaghasname) { mc.setname(tag.name); target = tag.name; } mc.settarget(parent.gettarget() + "/" + target); _this.build(character, mc); if (tag.placeflaghasclipactions) { var clipactionrecords = tag.clipactionrecords; var length = clipactionrecords.length; var eventname; for (var i = 0; i < length; i++) { var actionrecord = clipactionrecords[i]; var eventflag = actionrecord.eventflags; for (eventname in eventflag) { if (!eventflag.hasownproperty(eventname)) { continue; } if (!eventflag[eventname]) { continue; } var action = mc.createactionscript(actionrecord.actions); mc.addeventlistener(eventname, action); } } } return mc; }; /** * @param tag * @param character * @param parent * @returns {textfield} */ swftag.prototype.buildtextfield = function (tag, character, parent) { var _this = this; var stage = _this.stage; var textfield = new textfield(); textfield.setstage(stage); textfield.setparent(parent); textfield.setinitparams(); textfield.settagtype(character.tagtype); textfield.setbounds(character.bounds); var target = "instance" + textfield.instanceid; if (tag.placeflaghasname) { textfield.setname(tag.name); target = tag.name; } textfield.settarget(parent.gettarget() + "/" + target); var data = character.data; var obj = {}; var fontdata = null; var fontid = data.fontid; if (data.hasfont) { fontdata = stage.getcharacter(fontid); } textfield.fontid = fontid; textfield.fontscale = data.fontheight / 1024; if (fontdata && fontdata.zonetable) { textfield.fontscale /= 20; } textfield.initialtext = data.initialtext; obj.autosize = data.autosize; obj.border = data.border; if (obj.border) { obj.background = 1; } obj.bottomscroll = 1; obj.condensewhite = 0; obj.embedfonts = (data.hasfont && data.useoutlines && fontdata.fontflagshaslayout && !data.password) ? 1 : 0; obj.hscroll = 0; obj.maxscroll = 0; obj.scroll = 0; obj.maxhscroll = 0; obj.html = data.html; obj.htmltext = (data.html) ? data.initialtext : null; obj.length = 0; obj.maxchars = 0; obj.multiline = data.multiline; obj.password = data.password; obj.selectable = data.noselect; obj.tabenabled = 0; obj.tabindex = 0; obj.text = data.initialtext; obj.textcolor = data.textcolor; obj.textheight = 0; obj.textwidth = 0; obj.type = data.readonly ? "dynamic" : "input"; var variable = data.variablename; obj.variable = variable; if (variable) { parent.setvariable(variable, data.initialtext); } obj.wordwrap = data.wordwrap; // textformat obj.blockindent = 0; obj.bullet = 0; if (fontdata) { obj.bold = fontdata.fontflagsbold; var font = textfield.getvariable("font"); obj.font = "'" + fontdata.fontname + "', " + font; obj.italic = fontdata.fontflagsitalic; } if (data.haslayout) { switch (data.align) { case 1: obj.align = "right"; break; case 2: obj.align = "center"; break; case 3: obj.align = "justify"; break; } obj.leftmargin = data.leftmargin; obj.rightmargin = data.rightmargin; obj.indent = data.indent; obj.leading = (14400 > data.leading) ? data.leading : data.leading - 65535; } obj.size = data.fontheight / 20; obj.tabstops = []; obj.target = null; obj.underline = 0; obj.url = null; for (var name in obj) { if (!obj.hasownproperty(name)) { continue; } textfield.setproperty(name, obj[name]); } if (obj.type === "input") { textfield.setinputelement(); } return textfield; }; /** * @param tag * @param character * @returns {statictext} */ swftag.prototype.buildtext = function (tag, character) { var _this = this; var stage = _this.stage; var statictext = new statictext(); statictext.settagtype(character.tagtype); statictext.setbounds(character.bounds); var records = character.textrecords; var length = records.length; var offsetx = 0; var offsety = 0; var scale = 1; var textheight = 0; var shapetable = null; var cmatrix = character.matrix; var color = null; var iszonetable = false; for (var i = 0; i < length; i++) { var record = records[i]; if ("fontid" in record) { var fontid = record.fontid; var fontdata = stage.getcharacter(fontid); shapetable = fontdata.glyphshapetable; iszonetable = false; if ("zonetable" in fontdata) { iszonetable = true; } } if ("xoffset" in record) { offsetx = record.xoffset; } if ("yoffset" in record) { offsety = record.yoffset; } if ("textcolor" in record) { color = record.textcolor; } if ("textheight" in record) { textheight = record.textheight; if (iszonetable) { textheight /= 20; } } var entries = record.glyphentries; var count = record.glyphcount; scale = textheight / 1024; for (var idx = 0; idx < count; idx++) { var entry = entries[idx]; var shapes = shapetable[entry.glyphindex]; var data = vtc.convert(shapes); var matrix = [scale, cmatrix[1], cmatrix[2], scale, cmatrix[4] + offsetx, cmatrix[5] + offsety]; var textrecode = new textrecord(); textrecode.setdata(data); textrecode.setcolor(color); textrecode.setmatrix(matrix); statictext.addrecord(textrecode); offsetx += entry.glyphadvance; } } return statictext; }; /** * @param tag * @param character * @returns {shape} */ swftag.prototype.buildshape = function (tag, character) { var shape = new shape(); shape.settagtype(character.tagtype); shape.setbounds(character.bounds); shape.setdata(character.data); return shape; }; /** * @param character * @param tag * @param parent * @returns {simplebutton} */ swftag.prototype.buildbutton = function (character, tag, parent) { var _this = this; var stage = _this.stage; var characters = character.characters; var button = new simplebutton(); button.setstage(stage); button.setparent(parent); button.setlevel(tag.depth); if ("actions" in character) { button.setactions(character.actions); } var target = "instance" + button.instanceid; if (tag.placeflaghasname) { button.setname(tag.name); target = tag.name; } button.settarget(parent.gettarget() + "/" + target); var downstate = button.getsprite("down"); if (character.buttonstatedownsoundid) { downstate.soundid = character.buttonstatedownsoundid; downstate.soundinfo = character.buttonstatedownsoundinfo; } var hitstate = button.getsprite("hit"); if (character.buttonstatehittestsoundid) { hitstate.soundid = character.buttonstatehittestsoundid; hitstate.soundinfo = character.buttonstatehittestsoundinfo; } var overstate = button.getsprite("over"); if (character.buttonstateoversoundid) { overstate.soundid = character.buttonstateoversoundid; overstate.soundinfo = character.buttonstateoversoundinfo; } var upstate = button.getsprite("up"); if (character.buttonstateupsoundid) { upstate.soundid = character.buttonstateupsoundid; upstate.soundinfo = character.buttonstateupsoundinfo; } for (var depth in characters) { if (!characters.hasownproperty(depth)) { continue; } var tags = characters[depth]; for (var idx in tags) { if (!tags.hasownproperty(idx)) { continue; } var btag = tags[idx]; var obj = _this.buildobject(btag, button, false, 1); var placeobject = _this.buildplaceobject(btag); var depth = btag.depth; if (btag.buttonstatedown) { downstate.addtag(depth, obj); stage.setplaceobject(placeobject, downstate.instanceid, depth, 0); } if (btag.buttonstatehittest) { hitstate.addtag(depth, obj); stage.setplaceobject(placeobject, hitstate.instanceid, depth, 0); } if (btag.buttonstateover) { overstate.addtag(depth, obj); stage.setplaceobject(placeobject, overstate.instanceid, depth, 0); } if (btag.buttonstateup) { upstate.addtag(depth, obj); stage.setplaceobject(placeobject, upstate.instanceid, depth, 0); } } } button.setsprite("down", downstate); button.setsprite("hit", hitstate); button.setsprite("over", overstate); button.setsprite("up", upstate); button.settagtype(character.tagtype); return button; }; /** * @param frame * @param characterid * @returns {{ }} */ swftag.prototype.generatedefaulttagobj = function (frame, characterid) { return { frame: frame, characterid: characterid, ctags: [], removetags: [], actionscript: [], labels: [], sounds: [] }; }; /** * @param datalength * @param characterid * @returns {array} */ swftag.prototype.parsetags = function (datalength, characterid) { var _this = this; var _parsetag = _this.parsetag; var _addtag = _this.addtag; var _generatedefaulttagobj = _this.generatedefaulttagobj; var frame = 1; var tags = []; var tagtype = 0; var bitio = _this.bitio; // default set tags[frame] = _generatedefaulttagobj.call(_this, frame, characterid); while (bitio.byte_offset < datalength) { var tagstartoffset = bitio.byte_offset; if (tagstartoffset + 2 > datalength) { break; } var taglength = bitio.getui16(); tagtype = taglength >> 6; // long var length = taglength & 0x3f; if (length === 0x3f) { if (tagstartoffset + 6 > datalength) { bitio.byte_offset = tagstartoffset; bitio.bit_offset = 0; break; } length = bitio.getui32(); } var tagdatastartoffset = bitio.byte_offset; if (tagtype === 1) { frame++; if (datalength > tagdatastartoffset + 2) { tags[frame] = _generatedefaulttagobj.call(_this, frame, characterid); } } var tag = _parsetag.call(_this, tagtype, length); var o = bitio.byte_offset - tagdatastartoffset; if (o !== length) { if (o < length) { var eat = (length - o); if (eat > 0) { bitio.byte_offset += eat; } } } if (tag) { tags = _addtag.call(_this, tagtype, tags, tag, frame); } bitio.bit_offset = 0; } return tags; }; /** * @param tagtype * @param length * @returns {*} */ swftag.prototype.parsetag = function (tagtype, length) { var _this = this; var obj = null; var bitio = _this.bitio; var stage = _this.stage; switch (tagtype) { case 0: // end break; case 1: // showframe break; case 2: // defineshape case 22: // defineshape2 case 32: // defineshape3 case 83: // defineshape4 if (length < 10) { bitio.byte_offset += length; } else { _this.parsedefineshape(tagtype); } break; case 9: // backgroundcolor if (stage.bgcolor) { stage.backgroundcolor = stage.bgcolor; } else { stage.setbackgroundcolor( bitio.getui8(), bitio.getui8(), bitio.getui8() ); } break; case 10: // definefont case 48: // definefont2 case 75: // definefont3 _this.parsedefinefont(tagtype, length); break; case 13: // definefontinfo case 62: // definefontinfo2 _this.parsedefinefontinfo(tagtype, length); break; case 11: // definetext case 33: // definetext2 _this.parsedefinetext(tagtype); break; case 4: // placeobject case 26: // placeobject2 case 70: //placeobject3 obj = _this.parseplaceobject(tagtype, length); break; case 37: // defineedittext _this.parsedefineedittext(tagtype); break; case 39: // definesprite _this.parsedefinesprite(bitio.byte_offset + length); break; case 12: // doaction obj = _this.parsedoaction(length); break; case 59: // doinitaction _this.parsedoinitaction(length); break; case 5: // removeobject case 28: // removeobject2 obj = _this.parseremoveobject(tagtype); break; case 7: // definebutton case 34: // definebutton2 obj = _this.parsedefinebutton(tagtype, length); break; case 43: // framelabel obj = _this.parseframelabel(); break; case 88: // definefontname _this.parsedefinefontname(); break; case 20: // definebitslossless case 36: // definebitslossless2 _this.parsedefinebitslossless(tagtype, length); break; case 6: // definebits case 21: // definebitsjpeg2 case 35: // definebitsjpeg3 case 90: // definebitsjpeg4 _this.parsedefinebits(tagtype, length, _this.jpegtables); _this.jpegtables = null; break; case 8: // jpegtables _this.jpegtables = _this.parsejpegtables(length); break; case 56: // exportassets _this.parseexportassets(); break; case 46: // definemorphshape case 84: // definemorphshape2 _this.parsedefinemorphshape(tagtype); break; case 40: // namecharacter bitio.getdatauntil("\0"); // namecharacter break; case 24: // protect bitio.bytealign(); break; case 63: // debugid bitio.getui8(); // uuid break; case 64: // enabledebugger2 bitio.getui16(); // reserved bitio.getdatauntil("\0"); // password break; case 65: // scriptlimits bitio.getui16(); // maxrecursiondepth bitio.getui16(); // scripttimeoutseconds break; case 69: // fileattributes _this.parsefileattributes(); break; case 77: // metadata bitio.getdatauntil("\0"); // metadata break; case 86: // definesceneandframelabeldata obj = _this.parsedefinesceneandframelabeldata(); break; case 18: // soundstreamhead case 45: // soundstreamhead2 obj = _this.parsesoundstreamhead(tagtype); break; case 72: // doabc case 82: // doabc2 _this.parsedoabc(tagtype, length); break; case 76: // symbolclass _this.parsesymbolclass(); break; case 14: // definesound _this.parsedefinesound(tagtype, length); break; case 15: // startsound case 89: // startsound2 obj = _this.parsestartsound(tagtype); break; case 17: // definebuttonsound _this.parsedefinebuttonsound(); break; case 73: // definefontalignzones _this.parsedefinefontalignzones(); break; case 74: // csmtextsettings _this.parsecsmtextsettings(tagtype); break; case 19: // soundstreamblock _this.parsesoundstreamblock(tagtype, length); break; case 60: // definevideostream _this.parsedefinevideostream(tagtype); break; case 61: // videoframe _this.parsevideoframe(tagtype, length); break; case 78: // definescalinggrid _this.parsedefinescalinggrid(); break; case 41: // productinfo bitio.getui32(); // productid bitio.getui32(); // edition bitio.getui8(); // majorversion bitio.getui8(); // minorversion bitio.getui32(); // buildlow bitio.getui32(); // buildhigh bitio.getui32(); // compilationdate bitio.getui32(); // todo break; case 3: // freecharacter case 16: // stopsound case 23: // definebuttoncxform case 25: // pathsarepostscript case 29: // syncframe case 31: // freeall case 38: // definevideo case 42: // definetextformat case 44: // definebehavior case 47: // frametag case 49: // geproset case 52: // fontref case 53: // definefunction case 54: // placefunction case 55: // gentagobject case 57: // importassets case 58: // enabledebugger case 66: // settabindex case 71: // importassets2 case 87: // definebinarydata case 91: // definefont4 case 93: // enabletelemetry console.log("[base] tagtype -> " + tagtype); break; case 27: // 27 (invalid) case 30: // 30 (invalid) case 67: // 67 (invalid) case 68: // 68 (invalid) case 79: // 79 (invalid) case 80: // 80 (invalid) case 81: // 81 (invalid) case 85: // 85 (invalid) case 92: // 92 (invalid) break; default: // null break; } return obj; }; /** * @param tagtype * @param tags * @param tag * @param frame * @returns {*} */ swftag.prototype.addtag = function (tagtype, tags, tag, frame) { var tagsarray = tags[frame]; switch (tagtype) { case 4: // placeobject case 26: // placeobject2 case 70: // placeobject3 var ctags = tagsarray.ctags; tagsarray.ctags[ctags.length] = tag; break; case 12: // doaction var as = tagsarray.actionscript; tagsarray.actionscript[as.length] = tag; break; case 5: // removeobject case 28: // removeobject2 var removetags = tagsarray.removetags; tagsarray.removetags[removetags.length] = tag; break; case 43: // framelabel var labels = tagsarray.labels; tag.frame = frame; tagsarray.labels[labels.length] = tag; break; case 15: // startsound case 89: // startsound2 var sounds = tagsarray.sounds; tagsarray.sounds[sounds.length] = tag; break; } return tags; }; /** * @param tagtype */ swftag.prototype.parsedefineshape = function (tagtype) { var _this = this; var bitio = _this.bitio; var characterid = bitio.getui16(); var bounds = _this.rect(); if (tagtype === 83) { var obj = {}; obj.edgebounds = _this.rect(); bitio.getuibits(5); // reserved obj.usesfillwindingrule = bitio.getuibits(1); obj.usesnonscalingstrokes = bitio.getuibits(1); obj.usesscalingstrokes = bitio.getuibits(1); } var shapes = _this.shapewithstyle(tagtype); _this.appendshapetag(characterid, bounds, shapes, tagtype); }; /** * @returns {{xmin: number, xmax: number, ymin: number, ymax: number}} */ swftag.prototype.rect = function () { var bitio = this.bitio; bitio.bytealign(); var nbits = bitio.getuibits(5); return { xmin: bitio.getsibits(nbits), xmax: bitio.getsibits(nbits), ymin: bitio.getsibits(nbits), ymax: bitio.getsibits(nbits) }; }; /** * @param tagtype * @returns {{}} */ swftag.prototype.shapewithstyle = function (tagtype) { var _this = this; var bitio = _this.bitio; var fillstyles; var linestyles; if (tagtype === 46 || tagtype === 84) { fillstyles = {fillstylecount: 0, fillstyles: []}; linestyles = {linestylecount: 0, linestyles: []}; } else { fillstyles = _this.fillstylearray(tagtype); linestyles = _this.linestylearray(tagtype); } var numbits = bitio.getui8(); var numfillbits = numbits >> 4; var numlinebits = numbits & 0x0f; var shaperecords = _this.shaperecords(tagtype, { fillbits: numfillbits, linebits: numlinebits }); return { fillstyles: fillstyles, linestyles: linestyles, shaperecords: shaperecords }; }; /** * @param tagtype * @returns {{}} */ swftag.prototype.fillstylearray = function (tagtype) { var _this = this; var bitio = _this.bitio; var fillstylecount = bitio.getui8(); if ((tagtype > 2) && (fillstylecount === 0xff)) { fillstylecount = bitio.getui16(); } var fillstyles = []; for (var i = fillstylecount; i--;) { fillstyles[fillstyles.length] = _this.fillstyle(tagtype); } return { fillstylecount: fillstylecount, fillstyles: fillstyles }; }; /** * @param tagtype * @returns {{}} */ swftag.prototype.fillstyle = function (tagtype) { var _this = this; var bitio = _this.bitio; var obj = {}; var bittype = bitio.getui8(); obj.fillstyletype = bittype; switch (bittype) { case 0x00: if (tagtype === 32 || tagtype === 83) { obj.color = _this.rgba(); } else if (tagtype === 46 || tagtype === 84) { obj.startcolor = _this.rgba(); obj.endcolor = _this.rgba(); } else { obj.color = _this.rgb(); } break; case 0x10: case 0x12: if (tagtype === 46 || tagtype === 84) { obj.startgradientmatrix = _this.matrix(); obj.endgradientmatrix = _this.matrix(); obj.gradient = _this.gradient(tagtype); } else { obj.gradientmatrix = _this.matrix(); obj.gradient = _this.gradient(tagtype); } break; case 0x13: obj.gradientmatrix = _this.matrix(); obj.gradient = _this.focalgradient(tagtype); break; case 0x40: case 0x41: case 0x42: case 0x43: obj.bitmapid = bitio.getui16(); if (tagtype === 46 || tagtype === 84) { obj.startbitmapmatrix = _this.matrix(); obj.endbitmapmatrix = _this.matrix(); } else { obj.bitmapmatrix = _this.matrix(); } break; } return obj; }; /** * @returns {{}} */ swftag.prototype.rgb = function () { var bitio = this.bitio; return { r: bitio.getui8(), g: bitio.getui8(), b: bitio.getui8(), a: 1 }; }; /** * @returns {{}} */ swftag.prototype.rgba = function () { var bitio = this.bitio; return { r: bitio.getui8(), g: bitio.getui8(), b: bitio.getui8(), a: bitio.getui8() / 255 }; }; /** * @returns {array} */ swftag.prototype.matrix = function () { var bitio = this.bitio; bitio.bytealign(); var result = [1, 0, 0, 1, 0, 0]; if (bitio.getuibit()) { var nscalebits = bitio.getuibits(5); result[0] = bitio.getsibits(nscalebits) / 0x10000; result[3] = bitio.getsibits(nscalebits) / 0x10000; } if (bitio.getuibit()) { var nrotatebits = bitio.getuibits(5); result[1] = bitio.getsibits(nrotatebits) / 0x10000; result[2] = bitio.getsibits(nrotatebits) / 0x10000; } var ntranslatebits = bitio.getuibits(5); result[4] = bitio.getsibits(ntranslatebits); result[5] = bitio.getsibits(ntranslatebits); return result; }; /** * gradient * @param tagtype * @returns {{spreadmode: number, interpolationmode: number, gradientrecords: array}} */ swftag.prototype.gradient = function (tagtype) { var _this = this; var spreadmode = 0; var interpolationmode = 0; var numgradients; var bitio = this.bitio; bitio.bytealign(); if (tagtype === 46 || tagtype === 84) { numgradients = bitio.getui8(); } else { spreadmode = bitio.getuibits(2); interpolationmode = bitio.getuibits(2); numgradients = bitio.getuibits(4); } var gradientrecords = []; for (var i = numgradients; i--;) { gradientrecords[gradientrecords.length] = _this.gradientrecord(tagtype); } return { spreadmode: spreadmode, interpolationmode: interpolationmode, gradientrecords: gradientrecords }; }; /** * @param tagtype * @returns {{}} */ swftag.prototype.gradientrecord = function (tagtype) { var _this = this; var bitio = _this.bitio; if (tagtype === 46 || tagtype === 84) { return { startratio: bitio.getui8() / 255, startcolor: _this.rgba(), endratio: bitio.getui8() / 255, endcolor: _this.rgba() }; } else { var ratio = bitio.getui8(); var color = (tagtype < 32) ? _this.rgb() : _this.rgba(); return {ratio: ratio / 255, color: color}; } }; /** * @param tagtype * @returns {{spreadmode: number, interpolationmode: number, gradientrecords: array, focalpoint: number}} */ swftag.prototype.focalgradient = function (tagtype) { var bitio = this.bitio; bitio.bytealign(); var _this = this; var spreadmode = bitio.getuibits(2); var interpolationmode = bitio.getuibits(2); var numgradients = bitio.getuibits(4); var gradientrecords = []; for (var i = numgradients; i--;) { gradientrecords[gradientrecords.length] = _this.gradientrecord(tagtype); } var focalpoint = bitio.getfloat16(); return { spreadmode: spreadmode, interpolationmode: interpolationmode, gradientrecords: gradientrecords, focalpoint: focalpoint }; }; /** * @param tagtype * @returns {{linestylecount: number, linestyles: array}} */ swftag.prototype.linestylearray = function (tagtype) { var _this = this; var bitio = _this.bitio; var linestylecount = bitio.getui8(); if ((tagtype > 2) && (linestylecount === 0xff)) { linestylecount = bitio.getui16(); } var array = []; for (var i = linestylecount; i--;) { array[array.length] = _this.linestyles(tagtype); } return { linestylecount: linestylecount, linestyles: array }; }; /** * @param tagtype * @returns {{}} */ swftag.prototype.linestyles = function (tagtype) { var _this = this; var bitio = _this.bitio; var obj = {}; obj.fillstyletype = 0; if (tagtype === 46) { obj = { startwidth: bitio.getui16(), endwidth: bitio.getui16(), startcolor: _this.rgba(), endcolor: _this.rgba() }; } else if (tagtype === 84) { obj.startwidth = bitio.getui16(); obj.endwidth = bitio.getui16(); obj.startcapstyle = bitio.getuibits(2); obj.joinstyle = bitio.getuibits(2); obj.hasfillflag = bitio.getuibit(); obj.nohscaleflag = bitio.getuibit(); obj.novscaleflag = bitio.getuibit(); obj.pixelhintingflag = bitio.getuibit(); bitio.getuibits(5); // reserved obj.noclose = bitio.getuibit(); obj.endcapstyle = bitio.getuibits(2); if (obj.joinstyle === 2) { obj.miterlimitfactor = bitio.getui16(); } if (obj.hasfillflag) { obj.filltype = _this.fillstyle(tagtype); } else { obj.startcolor = _this.rgba(); obj.endcolor = _this.rgba(); } } else { obj.width = bitio.getui16(); if (tagtype === 83) { // defineshape4 obj.startcapstyle = bitio.getuibits(2); obj.joinstyle = bitio.getuibits(2); obj.hasfillflag = bitio.getuibit(); obj.nohscaleflag = bitio.getuibit(); obj.novscaleflag = bitio.getuibit(); obj.pixelhintingflag = bitio.getuibit(); bitio.getuibits(5); // reserved obj.noclose = bitio.getuibit(); obj.endcapstyle = bitio.getuibits(2); if (obj.joinstyle === 2) { obj.miterlimitfactor = bitio.getui16(); } if (obj.hasfillflag) { obj.filltype = _this.fillstyle(tagtype); } else { obj.color = _this.rgba(); } } else if (tagtype === 32) { // defineshape3 obj.color = _this.rgba(); } else { // defineshape1or2 obj.color = _this.rgb(); } } return obj; }; /** * @param tagtype * @param currentnumbits * @returns {array} */ swftag.prototype.shaperecords = function (tagtype, currentnumbits) { var _this = this; var bitio = _this.bitio; var shaperecords = []; _this.currentposition = {x: 0, y: 0}; var _straightedgerecord = _this.straightedgerecord; var _curvededgerecord = _this.curvededgerecord; var _stylechangerecord = _this.stylechangerecord; while (true) { var first6bits = bitio.getuibits(6); var shape = 0; if (first6bits & 0x20) { var numbits = first6bits & 0x0f; if (first6bits & 0x10) { shape = _straightedgerecord.call(_this, tagtype, numbits); } else { shape = _curvededgerecord.call(_this, tagtype, numbits); } } else if (first6bits) { shape = _stylechangerecord.call(_this, tagtype, first6bits, currentnumbits); } shaperecords[shaperecords.length] = shape; if (!shape) { bitio.bytealign(); break; } } return shaperecords; }; /** * @param tagtype * @param numbits * @returns {{}} */ swftag.prototype.straightedgerecord = function (tagtype, numbits) { var _this = this; var bitio = _this.bitio; var deltax = 0; var deltay = 0; var generallineflag = bitio.getuibit(); if (generallineflag) { deltax = bitio.getsibits(numbits + 2); deltay = bitio.getsibits(numbits + 2); } else { var vertlineflag = bitio.getuibit(); if (vertlineflag) { deltax = 0; deltay = bitio.getsibits(numbits + 2); } else { deltax = bitio.getsibits(numbits + 2); deltay = 0; } } var anchorx = deltax; var anchory = deltay; if (tagtype !== 46 && tagtype !== 84) { anchorx = _this.currentposition.x + deltax; anchory = _this.currentposition.y + deltay; _this.currentposition.x = anchorx; _this.currentposition.y = anchory; } return { controlx: 0, controly: 0, anchorx: anchorx, anchory: anchory, iscurved: false, ischange: false }; }; /** * @param tagtype * @param numbits * @returns {{}} */ swftag.prototype.curvededgerecord = function (tagtype, numbits) { var _this = this; var bitio = _this.bitio; var controldeltax = bitio.getsibits(numbits + 2); var controldeltay = bitio.getsibits(numbits + 2); var anchordeltax = bitio.getsibits(numbits + 2); var anchordeltay = bitio.getsibits(numbits + 2); var controlx = controldeltax; var controly = controldeltay; var anchorx = anchordeltax; var anchory = anchordeltay; if (tagtype !== 46 && tagtype !== 84) { controlx = _this.currentposition.x + controldeltax; controly = _this.currentposition.y + controldeltay; anchorx = controlx + anchordeltax; anchory = controly + anchordeltay; _this.currentposition.x = anchorx; _this.currentposition.y = anchory; } return { controlx: controlx, controly: controly, anchorx: anchorx, anchory: anchory, iscurved: true, ischange: false }; }; /** * @param tagtype * @param changeflag * @param currentnumbits * @returns {{}} */ swftag.prototype.stylechangerecord = function (tagtype, changeflag, currentnumbits) { var _this = this; var bitio = _this.bitio; var obj = {}; obj.statenewstyles = (changeflag >> 4) & 1; obj.statelinestyle = (changeflag >> 3) & 1; obj.statefillstyle1 = (changeflag >> 2) & 1; obj.statefillstyle0 = (changeflag >> 1) & 1; obj.statemoveto = changeflag & 1; if (obj.statemoveto) { var movebits = bitio.getuibits(5); obj.movex = bitio.getsibits(movebits); obj.movey = bitio.getsibits(movebits); _this.currentposition.x = obj.movex; _this.currentposition.y = obj.movey; } obj.fillstyle0 = 0; if (obj.statefillstyle0) { obj.fillstyle0 = bitio.getuibits(currentnumbits.fillbits); } obj.fillstyle1 = 0; if (obj.statefillstyle1) { obj.fillstyle1 = bitio.getuibits(currentnumbits.fillbits); } obj.linestyle = 0; if (obj.statelinestyle) { obj.linestyle = bitio.getuibits(currentnumbits.linebits); } if (obj.statenewstyles) { obj.fillstyles = _this.fillstylearray(tagtype); obj.linestyles = _this.linestylearray(tagtype); var numbits = bitio.getui8(); currentnumbits.fillbits = obj.numfillbits = numbits >> 4; currentnumbits.linebits = obj.numlinebits = numbits & 0x0f; } obj.ischange = true; return obj; }; /** * @param characterid * @param bounds * @param shapes * @param tagtype */ swftag.prototype.appendshapetag = function (characterid, bounds, shapes, tagtype) { var stage = this.stage; stage.setcharacter(characterid, { tagtype: tagtype, data: vtc.convert(shapes, false), bounds: bounds }); }; /** * @param tagtype * @param length */ swftag.prototype.parsedefinebitslossless = function (tagtype, length) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var startoffset = bitio.byte_offset; var characterid = bitio.getui16(); var format = bitio.getui8(); var width = bitio.getui16(); var height = bitio.getui16(); var isalpha = (tagtype === 36); var colortablesize = 0; if (format === 3) { colortablesize = bitio.getui8() + 1; } // uncompress var sub = bitio.byte_offset - startoffset; var compressed = bitio.getdata(length - sub); var data = bitio.unzip(compressed, false); // canvas var canvas = cachestore.getcanvas(); canvas.width = width; canvas.height = height; var imagecontext = canvas.getcontext("2d"); var imgdata = imagecontext.createimagedata(width, height); var pxdata = imgdata.data; var idx = 0; var pxidx = 0; var x = width; var y = height; if (format === 5 && !isalpha) { idx = 0; pxidx = 0; for (y = height; y--;) { for (x = width; x--;) { idx++; pxdata[pxidx++] = data[idx++]; pxdata[pxidx++] = data[idx++]; pxdata[pxidx++] = data[idx++]; pxdata[pxidx++] = 255; } } } else { var bpp = (isalpha) ? 4 : 3; var cmidx = colortablesize * bpp; var pad = 0; if (colortablesize) { pad = ((width + 3) & ~3) - width; } for (y = height; y--;) { for (x = width; x--;) { idx = (colortablesize) ? data[cmidx++] * bpp : cmidx++ * bpp; if (!isalpha) { pxdata[pxidx++] = data[idx++]; pxdata[pxidx++] = data[idx++]; pxdata[pxidx++] = data[idx++]; idx++; pxdata[pxidx++] = 255; } else { var alpha = (format === 3) ? data[idx + 3] : data[idx++]; if (!isalphabug) { pxdata[pxidx++] = data[idx++] * 255 / alpha; pxdata[pxidx++] = data[idx++] * 255 / alpha; pxdata[pxidx++] = data[idx++] * 255 / alpha; } else { pxdata[pxidx++] = data[idx++]; pxdata[pxidx++] = data[idx++]; pxdata[pxidx++] = data[idx++]; } pxdata[pxidx++] = alpha; if (format === 3) { idx++; } } } cmidx += pad; } } imagecontext.putimagedata(imgdata, 0, 0); stage.setcharacter(characterid, imagecontext); }; /** * parseexportassets */ swftag.prototype.parseexportassets = function () { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var count = bitio.getui16(); var exportassets = stage.exportassets; var packages = stage.packages; while (count--) { var id = bitio.getui16(); var name = bitio.getdatauntil("\0"); if (name.substr(0, 10) === "__packages") { packages[id] = 1; } exportassets[name] = id; } stage.exportassets = exportassets; }; /** * @param length * @returns {string} */ swftag.prototype.parsejpegtables = function (length) { return this.bitio.getdata(length); }; /** * @param tagtype * @param length * @param jpegtables */ swftag.prototype.parsedefinebits = function (tagtype, length, jpegtables) { var _this = this; var bitio = _this.bitio; var startoffset = bitio.byte_offset; var characterid = bitio.getui16(); var sub = bitio.byte_offset - startoffset; var imagedatalen = length - sub; if (tagtype === 35 || tagtype === 90) { imagedatalen = bitio.getui32(); } if (tagtype === 90) { var deblockparam = bitio.getui16(); console.log("deblockparam", deblockparam); } var jpegdata = bitio.getdata(imagedatalen); var bitmapalphadata = false; if (tagtype === 35 || tagtype === 90) { bitmapalphadata = bitio.getdata(length - sub - imagedatalen); } bitio.byte_offset = startoffset + length; // render var stage = _this.stage; stage.imgunloadcount++; var image = _document.createelement("img"); image.addeventlistener("load", function() { var width = this.width; var height = this.height; var canvas = cachestore.getcanvas(); canvas.width = width; canvas.height = height; var imagecontext = canvas.getcontext("2d"); imagecontext.drawimage(this, 0, 0, width, height); if (bitmapalphadata) { var data = bitio.unzip(bitmapalphadata, false); var imgdata = imagecontext.getimagedata(0, 0, width, height); var pxdata = imgdata.data; var pxidx = 3; var len = width * height; for (var i = 0; i < len; i++) { pxdata[pxidx] = data[i]; pxidx += 4; } imagecontext.putimagedata(imgdata, 0, 0); } stage.setcharacter(characterid, imagecontext); stage.imgunloadcount--; }); if (jpegtables !== null && jpegtables.length > 4) { var margedata = []; var len = jpegtables.length - 2; for (var idx = 0; idx < len; idx++) { margedata[margedata.length] = jpegtables[idx]; } len = jpegdata.length; for (idx = 2; idx < len; idx++) { margedata[margedata.length] = jpegdata[idx]; } jpegdata = margedata; } image.src = "data:image/jpeg;base64," + _this.base64encode(_this.parsejpegdata(jpegdata)); // for android bug _settimeout(function () {}, 0); }; /** * @param jpegdata * @returns {string} */ swftag.prototype.parsejpegdata = function (jpegdata) { var i = 0; var idx = 0; var str = ""; var length = jpegdata.length; // erroneous if (jpegdata[0] === 0xff && jpegdata[1] === 0xd9 && jpegdata[2] === 0xff && jpegdata[3] === 0xd8) { for (i = 4; i < length; i++) { str += _fromcharcode(jpegdata[i]); } } else if (jpegdata[i++] === 0xff && jpegdata[i++] === 0xd8) { for (idx = 0; idx < i; idx++) { str += _fromcharcode(jpegdata[idx]); } while (i < length) { if (jpegdata[i] === 0xff) { if (jpegdata[i + 1] === 0xd9 && jpegdata[i + 2] === 0xff && jpegdata[i + 3] === 0xd8) { i += 4; for (idx = i; idx < length; idx++) { str += _fromcharcode(jpegdata[idx]); } break; } else if (jpegdata[i + 1] === 0xda) { for (idx = i; idx < length; idx++) { str += _fromcharcode(jpegdata[idx]); } break; } else { var segmentlength = (jpegdata[i + 2] << 8) + jpegdata[i + 3] + i + 2; for (idx = i; idx < segmentlength; idx++) { str += _fromcharcode(jpegdata[idx]); } i += segmentlength - i; } } } } return str; }; /** * @param data * @returns {*} */ swftag.prototype.base64encode = function (data) { if (isbtoa) { return window.btoa(data); } var base64encodechars = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/"; var out = []; var i = 0; var len = data.length; while (i < len) { var c1 = data.charcodeat(i++) & 0xff; if (i === len) { out[out.length] = base64encodechars.charat(c1 >> 2); out[out.length] = base64encodechars.charat((c1 & 0x3) << 4); out[out.length] = "=="; break; } var c2 = data.charcodeat(i++); if (i === len) { out[out.length] = base64encodechars.charat(c1 >> 2); out[out.length] = base64encodechars.charat(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4)); out[out.length] = base64encodechars.charat((c2 & 0xf) << 2); out[out.length] = "="; break; } var c3 = data.charcodeat(i++); out[out.length] = base64encodechars.charat(c1 >> 2); out[out.length] = base64encodechars.charat(((c1 & 0x3) << 4) | ((c2 & 0xf0) >> 4)); out[out.length] = base64encodechars.charat(((c2 & 0xf) << 2) | ((c3 & 0xc0) >> 6)); out[out.length] = base64encodechars.charat(c3 & 0x3f); } return out.join(""); }; /** * @param tagtype * @param length */ swftag.prototype.parsedefinefont = function (tagtype, length) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var endoffset = bitio.byte_offset + length; var i = 0; var len = 0; var obj = {}; obj.tagtype = tagtype; obj.fontid = bitio.getui16(); var numglyphs = 0; if (tagtype === 48 || tagtype === 75) { var fontflags = bitio.getui8(); obj.fontflagshaslayout = (fontflags >>> 7) & 1; obj.fontflagsshiftjis = (fontflags >>> 6) & 1; obj.fontflagssmalltext = (fontflags >>> 5) & 1; obj.fontflagsansi = (fontflags >>> 4) & 1; obj.fontflagswideoffsets = (fontflags >>> 3) & 1; obj.fontflagswidecodes = (fontflags >>> 2) & 1; obj.fontflagsitalic = (fontflags >>> 1) & 1; obj.fontflagsbold = (fontflags) & 1; bitio.bytealign(); obj.languagecode = bitio.getui8(); obj.fontnamelen = bitio.getui8(); if (obj.fontnamelen) { var startoffset = bitio.byte_offset; var data = bitio.getdata(obj.fontnamelen); var str = ""; len = obj.fontnamelen; for (i = 0; i < len; i++) { if (data[i] > 127) { continue; } str += _fromcharcode(data[i]); } var fontname; if (obj.fontflagsshiftjis || obj.languagecode === 2) { fontname = bitio.decodetoshiftjis(str); } else { fontname = decodeuricomponent(str); } obj.fontname = _this.getfontname(fontname); bitio.byte_offset = startoffset + obj.fontnamelen; } numglyphs = bitio.getui16(); obj.numglyphs = numglyphs; } // offset var offset = bitio.byte_offset; if (tagtype === 10) { numglyphs = bitio.getui16(); } if (numglyphs) { var offsettable = []; if (tagtype === 10) { offsettable[0] = numglyphs; numglyphs /= 2; numglyphs--; } if (obj.fontflagswideoffsets) { for (i = numglyphs; i--;) { offsettable[offsettable.length] = bitio.getui32(); } if (tagtype !== 10) { obj.codetableoffset = bitio.getui32(); } } else { for (i = numglyphs; i--;) { offsettable[offsettable.length] = bitio.getui16(); } if (tagtype !== 10) { obj.codetableoffset = bitio.getui16(); } } // shape var glyphshapetable = []; if (tagtype === 10) { numglyphs++; } for (i = 0; i < numglyphs; i++) { bitio.setoffset(offsettable[i] + offset, 0); var numbits = bitio.getui8(); var numfillbits = numbits >> 4; var numlinebits = numbits & 0x0f; var currentnumbits = { fillbits: numfillbits, linebits: numlinebits }; var shapes = {}; shapes.shaperecords = _this.shaperecords(tagtype, currentnumbits); shapes.linestyles = { linestyles: [{ color: {r: 0, g: 0, b: 0, a: 1}, linestyletype: 0 }] }; shapes.fillstyles = { fillstyles: [{ color: {r: 0, g: 0, b: 0, a: 1}, fillstyletype: 0 }] }; glyphshapetable[glyphshapetable.length] = shapes; } obj.glyphshapetable = glyphshapetable; if (tagtype === 48 || tagtype === 75) { bitio.setoffset(obj.codetableoffset + offset, 0); var codetable = []; if (obj.fontflagswidecodes) { for (i = numglyphs; i--;) { codetable[codetable.length] = bitio.getui16(); } } else { for (i = numglyphs; i--;) { codetable[codetable.length] = bitio.getui8(); } } obj.codetable = codetable; if (obj.fontflagshaslayout) { obj.fontascent = bitio.getui16(); obj.fontdescent = bitio.getui16(); obj.fontleading = bitio.getui16(); var fontadvancetable = []; for (i = numglyphs; i--;) { fontadvancetable[fontadvancetable.length] = bitio.getui16(); } obj.fontadvancetable = fontadvancetable; var fontboundstable = []; for (i = numglyphs; i--;) { fontboundstable[fontboundstable.length] = _this.rect(); } obj.fontboundstable = fontboundstable; if (tagtype === 75) { obj.kerningcount = bitio.getui16(); obj.kerningrecord = []; for (i = obj.kerningcount; i--;) { var fontkerningcode1 = (obj.fontflagswidecodes) ? bitio.getui16() : bitio.getui8(); var fontkerningcode2 = (obj.fontflagswidecodes) ? bitio.getui16() : bitio.getui8(); var fontkerningadjustment = bitio.getsibits(16); obj.kerningrecord[obj.kerningrecord.length] = { fontkerningcode1: fontkerningcode1, fontkerningcode2: fontkerningcode2, fontkerningadjustment: fontkerningadjustment }; } } } } } bitio.byte_offset = endoffset; stage.setcharacter(obj.fontid, obj); stage.fonts[obj.fontname] = obj; }; /** * @param tagtype * @param length */ swftag.prototype.parsedefinefontinfo = function (tagtype, length) { var _this = this; var bitio = _this.bitio; var endoffset = bitio.byte_offset + length; var obj = {}; obj.tagtype = tagtype; obj.fontid = bitio.getui16(); var len = bitio.getui8(); var data = bitio.getdata(len); var str = ""; for (var i = 0; i < len; i++) { if (data[i] > 127) { continue; } str += _fromcharcode(data[i]); } obj.fontflagsreserved = bitio.getuibits(2); obj.fontflagssmalltext = bitio.getuibits(1); obj.fontflagsshiftjis = bitio.getuibits(1); obj.fontflagsansi = bitio.getuibits(1); obj.fontflagsitalic = bitio.getuibits(1); obj.fontflagsbold = bitio.getuibits(1); obj.fontflagswidecodes = bitio.getuibits(1); if (tagtype === 62) { obj.languagecode = bitio.getui8(); } var fontname; if (obj.fontflagsshiftjis || obj.languagecode === 2) { fontname = bitio.decodetoshiftjis(str); } else { fontname = decodeuricomponent(str); } obj.fontname = _this.getfontname(fontname); var codetable = []; bitio.bytealign(); var tlen = endoffset - bitio.byte_offset; if (obj.fontflagswidecodes || tagtype === 62) { while (tlen) { codetable[codetable.length] = bitio.getui16(); tlen -= 2; } } else { while (tlen) { codetable[codetable.length] = bitio.getui8(); tlen--; } } obj.codetable = codetable; }; /** * @param fontname * @returns {string} */ swftag.prototype.getfontname = function (fontname) { var length = fontname.length; var str = fontname.substr(length - 1); if (str.charcodeat(0) === 0) { fontname = fontname.slice(0, -1); } switch (fontname) { case "_sans": return "sans-serif"; case "_serif": return "serif"; case "_typewriter": return "monospace"; default: var ander = fontname.substr(0, 1); if (ander === "_") { return "sans-serif"; } return fontname; } }; /** * parsedefinefontname */ swftag.prototype.parsedefinefontname = function () { var bitio = this.bitio; bitio.getui16(); // fontid bitio.getdatauntil("\0"); // fontname bitio.getdatauntil("\0"); // fontcopyright }; /** * @param tagtype */ swftag.prototype.parsedefinetext = function (tagtype) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var obj = {}; var characterid = bitio.getui16(); obj.tagtype = tagtype; obj.bounds = _this.rect(); obj.matrix = _this.matrix(); var glyphbits = bitio.getui8(); var advancebits = bitio.getui8(); obj.textrecords = _this.gettextrecords(tagtype, glyphbits, advancebits); stage.setcharacter(characterid, obj); }; /** * @param tagtype * @param glyphbits * @param advancebits * @returns {array} */ swftag.prototype.gettextrecords = function (tagtype, glyphbits, advancebits) { var _this = this; var bitio = _this.bitio; var array = []; while (bitio.getui8() !== 0) { bitio.incrementoffset(-1, 0); var obj = {}; obj.textrecordtype = bitio.getuibits(1); obj.styleflagsreserved = bitio.getuibits(3); obj.styleflagshasfont = bitio.getuibits(1); obj.styleflagshascolor = bitio.getuibits(1); obj.styleflagshasyoffset = bitio.getuibits(1); obj.styleflagshasxoffset = bitio.getuibits(1); if (obj.styleflagshasfont) { obj.fontid = bitio.getui16(); } if (obj.styleflagshascolor) { if (tagtype === 11) { obj.textcolor = _this.rgb(); } else { obj.textcolor = _this.rgba(); } } if (obj.styleflagshasxoffset) { obj.xoffset = bitio.getui16(); } if (obj.styleflagshasyoffset) { obj.yoffset = bitio.getui16(); } if (obj.styleflagshasfont) { obj.textheight = bitio.getui16(); } obj.glyphcount = bitio.getui8(); obj.glyphentries = _this.getglyphentries( obj.glyphcount, glyphbits, advancebits ); array[array.length] = obj; } return array; }; /** * @param count * @param glyphbits * @param advancebits * @returns {array} */ swftag.prototype.getglyphentries = function (count, glyphbits, advancebits) { var bitio = this.bitio; var array = []; for (var i = count; i--;) { array[array.length] = { glyphindex: bitio.getuibits(glyphbits), glyphadvance: bitio.getsibits(advancebits) }; } return array; }; /** * @param tagtype */ swftag.prototype.parsedefineedittext = function (tagtype) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var obj = {}; var isjis = false; obj.characterid = bitio.getui16(); var bounds = _this.rect(); var flag1 = bitio.getui8(); obj.hastext = (flag1 >>> 7) & 1; obj.wordwrap = (flag1 >>> 6) & 1; obj.multiline = (flag1 >>> 5) & 1; obj.password = (flag1 >>> 4) & 1; obj.readonly = (flag1 >>> 3) & 1; obj.hastextcolor = (flag1 >>> 2) & 1; obj.hasmaxlength = (flag1 >>> 1) & 1; obj.hasfont = flag1 & 1; var flag2 = bitio.getui8(); obj.hasfontclass = (flag2 >>> 7) & 1; obj.autosize = (flag2 >>> 6) & 1; obj.haslayout = (flag2 >>> 5) & 1; obj.noselect = (flag2 >>> 4) & 1; obj.border = (flag2 >>> 3) & 1; obj.wasstatic = (flag2 >>> 2) & 1; obj.html = (flag2 >>> 1) & 1; obj.useoutlines = flag2 & 1; if (obj.hasfont) { obj.fontid = bitio.getui16(); var fontdata = stage.getcharacter(obj.fontid); isjis = (fontdata.fontflagsshiftjis) ? true : false; if (obj.hasfontclass) { obj.fontclass = bitio.getdatauntil("\0"); } obj.fontheight = bitio.getui16(); } if (obj.hastextcolor) { obj.textcolor = _this.rgba(); } if (obj.hasmaxlength) { obj.maxlength = bitio.getui16(); } if (obj.haslayout) { obj.align = bitio.getui8(); obj.leftmargin = bitio.getui16(); obj.rightmargin = bitio.getui16(); obj.indent = bitio.getui16(); obj.leading = bitio.getui16(); } var variablename = bitio.getdatauntil("\0", isjis) + ""; obj.variablename = (variablename === "") ? null : variablename; obj.initialtext = ""; if (obj.hastext) { var text = bitio.getdatauntil("\0", isjis); if (obj.html) { if (text.indexof("") !== -1) { text = text.replace(new regexp("", "gi"), "\n"); } if (text.indexof("") !== -1) { text = text.replace(new regexp("", "gi"), ""); text = text.replace(new regexp("", "gi"), ""); } var span = _document.createelement("span"); span.innerhtml = text; var tags = span.getelementsbytagname("p"); var length = tags.length; var tagdata = []; for (var i = 0; i < length; i++) { tagdata[i] = tags[i]; } obj.initialtext = tagdata; } else { obj.initialtext = text; } } stage.setcharacter(obj.characterid, { data: obj, bounds: bounds, tagtype: tagtype }); }; /** * @param tagtype */ swftag.prototype.parsedefinemorphshape = function (tagtype) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var obj = {}; obj.tagtype = tagtype; obj.characterid = bitio.getui16(); obj.startbounds = _this.rect(); obj.endbounds = _this.rect(); if (tagtype === 84) { obj.startedgebounds = _this.rect(); obj.endedgebounds = _this.rect(); bitio.getuibits(6); // reserved obj.usesnonscalingstrokes = bitio.getuibits(1); obj.usesscalingstrokes = bitio.getuibits(1); } var offset = bitio.getui32(); var endoffset = bitio.byte_offset + offset; obj.morphfillstyles = _this.fillstylearray(tagtype); obj.morphlinestyles = _this.linestylearray(tagtype); obj.startedges = _this.shapewithstyle(tagtype); if (bitio.byte_offset !== endoffset) { bitio.byte_offset = endoffset; } obj.endedges = _this.shapewithstyle(tagtype); // fill1 control var startposition = {x: 0, y: 0}; var endposition = {x: 0, y: 0}; var startrecords = obj.startedges.shaperecords; var endrecords = obj.endedges.shaperecords; var startrecordlength = startrecords.length; var endrecordlength = endrecords.length; var length = _max(startrecordlength, endrecordlength); for (var i = 0; i < length; i++) { var addrecode = {}; var startrecord = startrecords[i]; var endrecord = endrecords[i]; if (!startrecord && !endrecord) { continue; } if (!startrecord.ischange && !endrecord.ischange) { if (startrecord.iscurved) { startposition.x += startrecord.controlx + startrecord.anchorx; startposition.y += startrecord.controly + startrecord.anchory; } else { startposition.x += startrecord.anchorx; startposition.y += startrecord.anchory; } if (endrecord.iscurved) { endposition.x += endrecord.controlx + endrecord.anchorx; endposition.y += endrecord.controly + endrecord.anchory; } else { endposition.x += endrecord.anchorx; endposition.y += endrecord.anchory; } continue; } if (startrecord.ischange && !endrecord.ischange) { addrecode = { fillstyle0: startrecord.fillstyle0, fillstyle1: startrecord.fillstyle1, linestyle: startrecord.linestyle, statefillstyle0: startrecord.statefillstyle0, statefillstyle1: startrecord.statefillstyle1, statelinestyle: startrecord.statelinestyle, statemoveto: startrecord.statemoveto, statenewstyles: startrecord.statenewstyles, ischange: true }; if (startrecord.statemoveto) { addrecode.movex = endposition.x; addrecode.movey = endposition.y; startposition.x = startrecord.movex; startposition.y = startrecord.movey; } endrecords.splice(i, 0, addrecode); } else if (!startrecord.ischange && endrecord.ischange) { addrecode = { fillstyle0: endrecord.fillstyle0, fillstyle1: endrecord.fillstyle1, linestyle: endrecord.linestyle, statefillstyle0: endrecord.statefillstyle0, statefillstyle1: endrecord.statefillstyle1, statelinestyle: endrecord.statelinestyle, statemoveto: endrecord.statemoveto, statenewstyles: endrecord.statenewstyles, ischange: true }; if (endrecord.statemoveto) { addrecode.movex = startposition.x; addrecode.movey = startposition.y; endposition.x = endrecord.movex; endposition.y = endrecord.movey; } startrecords.splice(i, 0, addrecode); } else { if (startrecord.statemoveto) { startposition.x = startrecord.movex; startposition.y = startrecord.movey; } if (endrecord.statemoveto) { endposition.x = endrecord.movex; endposition.y = endrecord.movey; } } } var filltype = 0; var fillstyle = 0; length = obj.startedges.shaperecords.length; for (i = 0; i < length; i++) { var record = startrecords[i]; if (!record.ischange) { continue; } if (record.statefillstyle0) { fillstyle = record.fillstyle0; } if (fillstyle) { record.statefillstyle0 = 1; record.statefillstyle1 = 1; if (filltype) { record.fillstyle0 = 0; record.fillstyle1 = fillstyle; } else { record.fillstyle0 = fillstyle; record.fillstyle1 = 0; } } else { record.statefillstyle1 = 1; record.fillstyle1 = 0; } filltype = (filltype) ? 0 : 1; } stage.setcharacter(obj.characterid, obj); }; /** * @param char * @param ratio * @returns {{data: array, bounds: {xmax: number, xmin: number, ymax: number, ymin: number}}} */ swftag.prototype.buildmorphshape = function (char, ratio) { var per = (ratio === undefined) ? 0 : ratio / 65535; var startper = 1 - per; var newshaperecords = []; var morphlinestyles = char.morphlinestyles; var linestyles = morphlinestyles.linestyles; var linestylecount = morphlinestyles.linestylecount; var morphfillstyles = char.morphfillstyles; var fillstyles = morphfillstyles.fillstyles; var fillstylecount = morphfillstyles.fillstylecount; var startedges = char.startedges; var startshaperecords = startedges.shaperecords; var endedges = char.endedges; var endshaperecords = endedges.shaperecords; var shapes = { linestyles: { linestylecount: linestylecount, linestyles: [] }, fillstyles: { fillstylecount: fillstylecount, fillstyles: [] }, shaperecords: [] }; var position = {x: 0, y: 0}; var len = startshaperecords.length; for (var i = 0; i < len; i++) { var startrecord = startshaperecords[i]; if (!startrecord) { continue; } var newrecord = {}; var endrecord = endshaperecords[i]; if (startrecord.ischange) { var movex = 0; var movey = 0; if (startrecord.statemoveto === 1) { movex = startrecord.movex * startper + endrecord.movex * per; movey = startrecord.movey * startper + endrecord.movey * per; position.x = movex; position.y = movey; } newrecord = { fillstyle0: startrecord.fillstyle0, fillstyle1: startrecord.fillstyle1, linestyle: startrecord.linestyle, movex: movex, movey: movey, statefillstyle0: startrecord.statefillstyle0, statefillstyle1: startrecord.statefillstyle1, statelinestyle: startrecord.statelinestyle, statemoveto: startrecord.statemoveto, statenewstyles: startrecord.statenewstyles, ischange: true }; } else { var anchorx = 0; var anchory = 0; var controlx = 0; var controly = 0; var startanchorx = startrecord.anchorx; var startanchory = startrecord.anchory; var endanchorx = endrecord.anchorx; var endanchory = endrecord.anchory; var startcontrolx = startrecord.controlx; var startcontroly = startrecord.controly; var endcontrolx = endrecord.controlx; var endcontroly = endrecord.controly; if (per > 0 && per < 1 && startrecord.iscurved !== endrecord.iscurved) { if (!startrecord.iscurved) { startanchorx = startrecord.anchorx / 2; startanchory = startrecord.anchory / 2; startcontrolx = startanchorx; startcontroly = startanchory; } if (!endrecord.iscurved) { endanchorx = endrecord.anchorx / 2; endanchory = endrecord.anchory / 2; endcontrolx = endanchorx; endcontroly = endanchory; } } controlx = startcontrolx * startper + endcontrolx * per + position.x; controly = startcontroly * startper + endcontroly * per + position.y; anchorx = startanchorx * startper + endanchorx * per + controlx; anchory = startanchory * startper + endanchory * per + controly; position.x = anchorx; position.y = anchory; newrecord = { anchorx: anchorx, anchory: anchory, controlx: controlx, controly: controly, ischange: false, iscurved: (startrecord.iscurved || endrecord.iscurved) }; } newshaperecords[i] = newrecord; } newshaperecords[newshaperecords.length] = 0; shapes.shaperecords = newshaperecords; var endcolor; var startcolor; var color; for (i = 0; i < linestylecount; i++) { var linestyle = linestyles[i]; endcolor = linestyle.endcolor; startcolor = linestyle.startcolor; color = { r: _floor(startcolor.r * startper + endcolor.r * per), g: _floor(startcolor.g * startper + endcolor.g * per), b: _floor(startcolor.b * startper + endcolor.b * per), a: startcolor.a * startper + endcolor.a * per }; var endwidth = linestyles[i].endwidth; var startwidth = linestyles[i].startwidth; shapes.linestyles.linestyles[i] = { width: _floor(startwidth * startper + endwidth * per), color: color, fillstyletype: 0 }; } for (i = 0; i < fillstylecount; i++) { var fillstyle = fillstyles[i]; var fillstyletype = fillstyle.fillstyletype; if (fillstyletype === 0x00) { endcolor = fillstyle.endcolor; startcolor = fillstyle.startcolor; color = { r: _floor(startcolor.r * startper + endcolor.r * per), g: _floor(startcolor.g * startper + endcolor.g * per), b: _floor(startcolor.b * startper + endcolor.b * per), a: startcolor.a * startper + endcolor.a * per }; shapes.fillstyles.fillstyles[i] = { color: color, fillstyletype: fillstyletype }; } else { var endgradientmatrix = fillstyle.endgradientmatrix; var startgradientmatrix = fillstyle.startgradientmatrix; var matrix = [ startgradientmatrix[0] * startper + endgradientmatrix[0] * per, startgradientmatrix[1] * startper + endgradientmatrix[1] * per, startgradientmatrix[2] * startper + endgradientmatrix[2] * per, startgradientmatrix[3] * startper + endgradientmatrix[3] * per, startgradientmatrix[4] * startper + endgradientmatrix[4] * per, startgradientmatrix[5] * startper + endgradientmatrix[5] * per ]; var grecords = []; var gradient = fillstyle.gradient; var gradientrecords = gradient.gradientrecords; var glen = gradientrecords.length; for (var gidx = 0; gidx < glen; gidx++) { var grecord = gradientrecords[gidx]; endcolor = grecord.endcolor; startcolor = grecord.startcolor; color = { r: _floor(startcolor.r * startper + endcolor.r * per), g: _floor(startcolor.g * startper + endcolor.g * per), b: _floor(startcolor.b * startper + endcolor.b * per), a: startcolor.a * startper + endcolor.a * per }; grecords[gidx] = { color: color, ratio: grecord.startratio * startper + grecord.endratio * per }; } shapes.fillstyles.fillstyles[i] = { gradient: {gradientrecords: grecords}, gradientmatrix: matrix, fillstyletype: fillstyletype }; } } var endbounds = char.endbounds; var startbounds = char.startbounds; var bounds = { xmax: startbounds.xmax * startper + endbounds.xmax * per, xmin: startbounds.xmin * startper + endbounds.xmin * per, ymax: startbounds.ymax * startper + endbounds.ymax * per, ymin: startbounds.ymin * startper + endbounds.ymin * per }; return { data: vtc.convert(shapes, true), bounds: bounds }; }; /** * @returns {{}} */ swftag.prototype.parseframelabel = function () { return { name: this.bitio.getdatauntil("\0"), frame: 0 }; }; /** * @param tagtype * @returns {*} */ swftag.prototype.parseremoveobject = function (tagtype) { var bitio = this.bitio; if (tagtype === 5) { console.log("removeobject"); return { characterid: bitio.getui16(), depth: bitio.getui16() }; } return {depth: bitio.getui16()}; }; /** * @param tagtype * @param length * @returns {{}} */ swftag.prototype.parsedefinebutton = function (tagtype, length) { var obj = {}; obj.tagtype = tagtype; var _this = this; var bitio = _this.bitio; var stage = _this.stage; var endoffset = bitio.byte_offset + length; obj.buttonid = bitio.getui16(); var actionoffset = 0; if (tagtype !== 7) { obj.reservedflags = bitio.getuibits(7); obj.trackasmenu = bitio.getuibits(1); actionoffset = bitio.getui16(); } obj.characters = _this.buttoncharacters(); // actionscript if (tagtype === 7) { obj.actions = _this.parsedoaction(endoffset - bitio.byte_offset); } else if (actionoffset > 0) { obj.actions = _this.buttonactions(endoffset); } // set layer stage.setcharacter(obj.buttonid, obj); if (bitio.byte_offset !== endoffset) { bitio.byte_offset = endoffset; } return obj; }; /** * @returns {array} */ swftag.prototype.buttoncharacters = function () { var characters = []; var _this = this; var bitio = _this.bitio; while (bitio.getui8() !== 0) { bitio.incrementoffset(-1, 0); var record = _this.buttonrecord(); var depth = record.depth; if (!(record.depth in characters)) { characters[depth] = []; } characters[depth].push(record); } return characters; }; /** * @returns {{}} */ swftag.prototype.buttonrecord = function () { var _this = this; var bitio = _this.bitio; var obj = {}; bitio.getuibits(2); // reserved obj.placeflaghasblendmode = bitio.getuibits(1); obj.placeflaghasfilterlist = bitio.getuibits(1); obj.buttonstatehittest = bitio.getuibits(1); obj.buttonstatedown = bitio.getuibits(1); obj.buttonstateover = bitio.getuibits(1); obj.buttonstateup = bitio.getuibits(1); obj.characterid = bitio.getui16(); obj.depth = bitio.getui16(); obj.placeflaghasmatrix = 1; obj.matrix = _this.matrix(); obj.colortransform = _this.colortransform(); obj.placeflaghascolortransform = (obj.colortransform === undefined) ? 0 : 1; if (obj.placeflaghasblendmode) { obj.blendmode = bitio.getui8(); } if (obj.placeflaghasfilterlist) { obj.surfacefilterlist = _this.getfilterlist(); } obj.placeflaghasratio = 0; obj.placeflaghasclipdepth = 0; obj.sound = null; return obj; }; /** * @param endoffset * @returns {array} */ swftag.prototype.buttonactions = function (endoffset) { var _this = this; var bitio = _this.bitio; var results = []; while (true) { var obj = {}; var startoffset = bitio.byte_offset; var condactionsize = bitio.getui16(); obj.condidletooverdown = bitio.getuibits(1); obj.condoutdowntoidle = bitio.getuibits(1); obj.condoutdowntooverdown = bitio.getuibits(1); obj.condoverdowntooutdown = bitio.getuibits(1); obj.condoverdowntooverup = bitio.getuibits(1); obj.condoveruptooverdown = bitio.getuibits(1); obj.condoveruptoidle = bitio.getuibits(1); obj.condidletooverup = bitio.getuibits(1); obj.condkeypress = bitio.getuibits(7); obj.condoverdowntoidle = bitio.getuibits(1); // actionscript var length = endoffset - bitio.byte_offset + 1; obj.actionscript = _this.parsedoaction(length); results[results.length] = obj; if (!condactionsize) { break; } bitio.byte_offset = startoffset + condactionsize; } return results; }; /** * @param tagtype * @param length * @returns {{}} */ swftag.prototype.parseplaceobject = function (tagtype, length) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var obj = {}; obj.tagtype = tagtype; var startoffset = bitio.byte_offset; if (tagtype === 4) { obj.characterid = bitio.getui16(); obj.depth = bitio.getui16(); obj.matrix = _this.matrix(); obj.placeflaghasmatrix = 1; bitio.bytealign(); if ((bitio.byte_offset - startoffset) < length) { obj.colortransform = _this.colortransform(); obj.placeflaghascolortransform = 1; } } else { obj.placeflaghasclipactions = bitio.getuibits(1); if (stage.getversion() < 5) { obj.placeflaghasclipactions = 0; } obj.placeflaghasclipdepth = bitio.getuibits(1); obj.placeflaghasname = bitio.getuibits(1); obj.placeflaghasratio = bitio.getuibits(1); obj.placeflaghascolortransform = bitio.getuibits(1); obj.placeflaghasmatrix = bitio.getuibits(1); obj.placeflaghascharacter = bitio.getuibits(1); obj.placeflagmove = bitio.getuibits(1); // placeobject3 if (tagtype === 70) { bitio.getuibits(1); // reserved obj.placeflagopaquebackground = bitio.getuibits(1); obj.placeflaghasvisible = bitio.getuibits(1); obj.placeflaghasimage = bitio.getuibits(1); obj.placeflaghasclassname = bitio.getuibits(1); obj.placeflaghascacheasbitmap = bitio.getuibits(1); obj.placeflaghasblendmode = bitio.getuibits(1); obj.placeflaghasfilterlist = bitio.getuibits(1); } obj.depth = bitio.getui16(); if (obj.placeflaghasclassname || (obj.placeflaghasimage && obj.placeflaghascharacter) ) { obj.classname = bitio.getdatauntil("\0"); } if (obj.placeflaghascharacter) { obj.characterid = bitio.getui16(); } if (obj.placeflaghasmatrix) { obj.matrix = _this.matrix(); } if (obj.placeflaghascolortransform) { obj.colortransform = _this.colortransform(); } if (obj.placeflaghasratio) { obj.ratio = bitio.getui16(); } if (obj.placeflaghasname) { obj.name = bitio.getdatauntil("\0"); } if (obj.placeflaghasclipdepth) { obj.clipdepth = bitio.getui16(); } if (tagtype === 70) { if (obj.placeflaghasfilterlist) { obj.surfacefilterlist = _this.getfilterlist(); } if (obj.placeflaghasblendmode) { obj.blendmode = bitio.getui8(); } if (obj.placeflaghascacheasbitmap) { obj.bitmapcache = bitio.getui8(); } if (obj.placeflaghasvisible) { obj.visible = bitio.getui8(); obj.backgroundcolor = _this.rgba(); } } if (obj.placeflaghasclipactions) { bitio.getui16(); // reserved obj.alleventflags = _this.parseclipeventflags(); var endlength = startoffset + length; var actionrecords = []; while (bitio.byte_offset < endlength) { var clipactionrecord = _this.parseclipactionrecord(endlength); actionrecords[actionrecords.length] = clipactionrecord; if (endlength <= bitio.byte_offset) { break; } var endflag = (stage.getversion() <= 5) ? bitio.getui16() : bitio.getui32(); if (!endflag) { break; } if (stage.getversion() <= 5) { bitio.byte_offset -= 2; } else { bitio.byte_offset -= 4; } if (clipactionrecord.keycode) { bitio.byte_offset -= 1; } } obj.clipactionrecords = actionrecords; } } bitio.bytealign(); bitio.byte_offset = startoffset + length; return obj; }; /** * @returns {{}} */ swftag.prototype.parseclipactionrecord = function (endlength) { var _this = this; var bitio = _this.bitio; var obj = {}; var eventflags = _this.parseclipeventflags(); if (endlength > bitio.byte_offset) { var actionrecordsize = bitio.getui32(); if (eventflags.keypress) { obj.keycode = bitio.getui8(); } obj.eventflags = eventflags; obj.actions = _this.parsedoaction(actionrecordsize); } return obj; }; /** * @returns {{}} */ swftag.prototype.parseclipeventflags = function () { var _this = this; var obj = {}; var bitio = _this.bitio; var stage = _this.stage; obj.keyup = bitio.getuibits(1); obj.keydown = bitio.getuibits(1); obj.mouseup = bitio.getuibits(1); obj.mousedown = bitio.getuibits(1); obj.mousemove = bitio.getuibits(1); obj.unload = bitio.getuibits(1); obj.enterframe = bitio.getuibits(1); obj.load = bitio.getuibits(1); if (stage.getversion() >= 6) { obj.dragover = bitio.getuibits(1); obj.rollout = bitio.getuibits(1); obj.rollover = bitio.getuibits(1); obj.releaseoutside = bitio.getuibits(1); obj.release = bitio.getuibits(1); obj.press = bitio.getuibits(1); obj.initialize = bitio.getuibits(1); } obj.data = bitio.getuibits(1); if (stage.getversion() >= 6) { bitio.getuibits(5); // reserved obj.construct = bitio.getuibits(1); obj.keypress = bitio.getuibits(1); obj.dragout = bitio.getuibits(1); bitio.getuibits(8); // reserved } bitio.bytealign(); return obj; }; /** * @returns {array} */ swftag.prototype.getfilterlist = function () { var _this = this; var bitio = _this.bitio; var result = []; var _getfilter = _this.getfilter; var numberoffilters = bitio.getui8(); for (var i = 0; i < numberoffilters; i++) { var filter = _getfilter.call(_this); if (filter) { result[result.length] = filter; } } return (result.length) ? result : null; }; /** * @return {{}} */ swftag.prototype.getfilter = function () { var _this = this; var bitio = _this.bitio; var filterid = bitio.getui8(); var filter; switch (filterid) { case 0: filter = _this.dropshadowfilter(); break; case 1: filter = _this.blurfilter(); break; case 2: filter = _this.glowfilter(); break; case 3: filter = _this.bevelfilter(); break; case 4: filter = _this.gradientglowfilter(); break; case 5: filter = _this.convolutionfilter(); break; case 6: filter = _this.colormatrixfilter(); break; case 7: filter = _this.gradientbevelfilter(); break; } return filter; }; /** * @returns {dropshadowfilter} */ swftag.prototype.dropshadowfilter = function () { var _this = this; var bitio = _this.bitio; var rgba = _this.rgba(); var alpha = rgba.a; var color = rgba.r << 16 | rgba.g << 8 | rgba.b; var blurx = bitio.getui32() / 0x10000; var blury = bitio.getui32() / 0x10000; var angle = bitio.getui32() / 0x10000 * 180 / _pi; var distance = bitio.getui32() / 0x10000; var strength = bitio.getfloat16() / 256; var inner = (bitio.getuibits(1)) ? true : false; var knockout = (bitio.getuibits(1)) ? true : false; var hideobject = (bitio.getuibits(1)) ? false : true; var quality = bitio.getuibits(5); if (!strength) { return null; } return new dropshadowfilter( distance, angle, color, alpha, blurx, blury, strength, quality, inner, knockout, hideobject ); }; /** * @returns {blurfilter} */ swftag.prototype.blurfilter = function () { var bitio = this.bitio; var blurx = bitio.getui32() / 0x10000; var blury = bitio.getui32() / 0x10000; var quality = bitio.getuibits(5); bitio.getuibits(3); // reserved return new blurfilter(blurx, blury, quality); }; /** * @returns {glowfilter} */ swftag.prototype.glowfilter = function () { var _this = this; var bitio = _this.bitio; var rgba = _this.rgba(); var alpha = rgba.a; var color = rgba.r << 16 | rgba.g << 8 | rgba.b; var blurx = bitio.getui32() / 0x10000; var blury = bitio.getui32() / 0x10000; var strength = bitio.getfloat16() / 256; var inner = (bitio.getuibits(1)) ? true : false; var knockout = (bitio.getuibits(1)) ? true : false; bitio.getuibits(1); // compositesource var quality = bitio.getuibits(5); if (!strength) { return null; } return new glowfilter( color, alpha, blurx, blury, strength, quality, inner, knockout ); }; /** * @returns {bevelfilter} */ swftag.prototype.bevelfilter = function () { var _this = this; var bitio = _this.bitio; var rgba; rgba = _this.rgba(); var highlightalpha = rgba.a; var highlightcolor = rgba.r << 16 | rgba.g << 8 | rgba.b; rgba = _this.rgba(); var shadowalpha = rgba.a; var shadowcolor = rgba.r << 16 | rgba.g << 8 | rgba.b; var blurx = bitio.getui32() / 0x10000; var blury = bitio.getui32() / 0x10000; var angle = bitio.getui32() / 0x10000 * 180 / _pi; var distance = bitio.getui32() / 0x10000; var strength = bitio.getfloat16() / 256; var inner = (bitio.getuibits(1)) ? true : false; var knockout = (bitio.getuibits(1)) ? true : false; bitio.getuibits(1); // compositesource var ontop = bitio.getuibits(1); var quality = bitio.getuibits(4); var type = "inner"; if (!inner) { if (ontop) { type = "full"; } else { type = "outer"; } } if (!strength) { return null; } return new bevelfilter( distance, angle, highlightcolor, highlightalpha, shadowcolor, shadowalpha, blurx, blury, strength, quality, type, knockout ); }; /** * @returns {gradientglowfilter} */ swftag.prototype.gradientglowfilter = function () { var _this = this; var bitio = _this.bitio; var i; var numcolors = bitio.getui8(); var colors = []; var alphas = []; for (i = 0; i < numcolors; i++) { var rgba = _this.rgba(); alphas[alphas.length] = rgba.a; colors[colors.length] = rgba.r << 16 | rgba.g << 8 | rgba.b; } var ratios = []; for (i = 0; i < numcolors; i++) { ratios[ratios.length] = bitio.getui8(); } var blurx = bitio.getui32() / 0x10000; var blury = bitio.getui32() / 0x10000; var angle = bitio.getui32() / 0x10000 * 180 / _pi; var distance = bitio.getui32() / 0x10000; var strength = bitio.getfloat16() / 256; var inner = (bitio.getuibits(1)) ? true : false; var knockout = (bitio.getuibits(1)) ? true : false; bitio.getuibits(1); // compositesource var ontop = bitio.getuibits(1); var quality = bitio.getuibits(4); var type = "inner"; if (!inner) { if (ontop) { type = "full"; } else { type = "outer"; } } if (!strength) { return null; } return new gradientglowfilter( distance, angle, colors, alphas, ratios, blurx, blury, strength, quality, type, knockout ); }; /** * @returns {convolutionfilter} */ swftag.prototype.convolutionfilter = function () { var _this = this; var bitio = _this.bitio; var obj = {}; obj.matrixx = bitio.getui8(); obj.matrixy = bitio.getui8(); obj.divisor = bitio.getfloat16() | bitio.getfloat16(); obj.bias = bitio.getfloat16() | bitio.getfloat16(); var count = obj.matrixx * obj.matrixy; var matrixarr = []; while (count--) { matrixarr[matrixarr.length] = bitio.getui32(); } obj.defaultcolor = _this.rgba(); bitio.getuibits(6); // reserved obj.clamp = bitio.getuibits(1); obj.preservealpha = bitio.getuibits(1); return new convolutionfilter( ); }; /** * @returns {gradientbevelfilter} */ swftag.prototype.gradientbevelfilter = function () { var _this = this; var bitio = _this.bitio; var numcolors = bitio.getui8(); var i; var colors = []; var alphas = []; for (i = 0; i < numcolors; i++) { var rgba = _this.rgba(); alphas[alphas.length] = rgba.a; colors[colors.length] = rgba.r << 16 | rgba.g << 8 | rgba.b; } var ratios = []; for (i = 0; i < numcolors; i++) { ratios[ratios.length] = bitio.getui8(); } var blurx = bitio.getui32() / 0x10000; var blury = bitio.getui32() / 0x10000; var angle = bitio.getui32() / 0x10000 * 180 / _pi; var distance = bitio.getui32() / 0x10000; var strength = bitio.getfloat16() / 256; var inner = (bitio.getuibits(1)) ? true : false; var knockout = (bitio.getuibits(1)) ? true : false; bitio.getuibits(1); // compositesource var ontop = bitio.getuibits(1); var quality = bitio.getuibits(4); var type = "inner"; if (!inner) { if (ontop) { type = "full"; } else { type = "outer"; } } if (!strength) { return null; } return new gradientbevelfilter( distance, angle, colors, alphas, ratios, blurx, blury, strength, quality, type, knockout ); }; /** * @returns {colormatrixfilter} */ swftag.prototype.colormatrixfilter = function () { var bitio = this.bitio; var matrixarr = []; for (var i = 0; i < 20; i++) { matrixarr[matrixarr.length] = bitio.getui32(); } return new colormatrixfilter( ); }; /** * @returns {array} */ swftag.prototype.colortransform = function () { var bitio = this.bitio; bitio.bytealign(); var result = [1, 1, 1, 1, 0, 0, 0, 0]; var first6bits = bitio.getuibits(6); var hasaddterms = first6bits >> 5; var hasmultiterms = (first6bits >> 4) & 1; var nbits = first6bits & 0x0f; if (hasmultiterms) { result[0] = bitio.getsibits(nbits) / 256; result[1] = bitio.getsibits(nbits) / 256; result[2] = bitio.getsibits(nbits) / 256; result[3] = bitio.getsibits(nbits) / 256; } if (hasaddterms) { result[4] = bitio.getsibits(nbits); result[5] = bitio.getsibits(nbits); result[6] = bitio.getsibits(nbits); result[7] = bitio.getsibits(nbits); } return result; }; /** * @param datalength */ swftag.prototype.parsedefinesprite = function (datalength) { var _this = this; var bitio = _this.bitio; var characterid = bitio.getui16(); bitio.getui16(); // framecount var stage = _this.stage; stage.setcharacter(characterid, _this.parsetags(datalength, characterid)); }; /** * @param length * @returns {actionscript} */ swftag.prototype.parsedoaction = function (length) { var _this = this; var bitio = _this.bitio; var data = bitio.getdata(length); return new actionscript(data); }; /** * @param length */ swftag.prototype.parsedoinitaction = function (length) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var spriteid = bitio.getui16(); var as = new actionscript(bitio.getdata(length - 2), undefined, undefined, true); var mc = stage.getparent(); mc.variables = {}; var action = mc.createactionscript2(as); var packages = stage.packages; if (spriteid in packages) { mc.active = true; action.apply(mc); mc.active = false; } stage.initactions[spriteid] = action; }; /** * @returns {{}} */ swftag.prototype.parsedefinesceneandframelabeldata = function () { var i; var bitio = this.bitio; var obj = {}; obj.scenecount = bitio.getu30(); obj.sceneinfo = []; for (i = 0; i < obj.scenecount; i++) { obj.sceneinfo[i] = { offset: bitio.getu30(), name: decodeuricomponent(bitio.getdatauntil("\0")) }; } obj.framelabelcount = bitio.getu30(); obj.frameinfo = []; for (i = 0; i < obj.framelabelcount; i++) { obj.frameinfo[i] = { num: bitio.getu30(), label: decodeuricomponent(bitio.getdatauntil("\0")) }; } return obj; }; /** * @param tagtype * @returns {{}} */ swftag.prototype.parsesoundstreamhead = function (tagtype) { var obj = {}; obj.tagtype = tagtype; var bitio = this.bitio; bitio.getuibits(4); // reserved // 0 = 5.5khz, 1 = 11khz, 2 = 22khz, 3 = 44khz obj.playbacksoundrate = bitio.getuibits(2); // 0 = 8-bit, 1 = 16-bit obj.playbacksoundsize = bitio.getuibits(1); // 0 = mono, 1 = stereo obj.playbacksoundtype = bitio.getuibits(1); // 0 = uncompressed(native-endian) // 1 = adpcm // 2 = mp3 // 3 = uncompressed(little-endian) // 4 = nellymoser 16 khz // 5 = nellymoser 8 khz // 6 = nellymoser // 11 = speex obj.streamsoundcompression = bitio.getuibits(4); // 0 = 5.5khz, 1 = 11khz, 2 = 22khz, 3 = 44khz obj.streamsoundrate = bitio.getuibits(2); // 0 = 8-bit, 1 = 16-bit obj.streamsoundsize = bitio.getuibits(1); // 0 = mono, 1 = stereo obj.streamsoundtype = bitio.getuibits(1); obj.streamsoundsamplecount = bitio.getui16(); if (obj.streamsoundcompression === 2) { obj.latencyseek = bitio.getsibits(2); } return obj; }; /** * @param tagtype * @param length */ swftag.prototype.parsedoabc = function (tagtype, length) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; stage.abcflag = true; var startoffset = bitio.byte_offset; var obj = {}; obj.tagtype = tagtype; obj.flags = bitio.getui32(); obj.name = bitio.getdatauntil("\0"); var offset = length - (bitio.byte_offset - startoffset); var abcdata = bitio.getdata(offset); var abcbitio = new bitio(); abcbitio.setdata(abcdata); // version obj.minorversion = abcbitio.getui16(); obj.majorversion = abcbitio.getui16(); // integer obj.integer = _this.abcinteger(abcbitio); // uinteger obj.uinteger = _this.abcuinteger(abcbitio); // double obj.double = _this.abcdouble(abcbitio); // string_info obj.string = _this.abcstringinfo(abcbitio); // namespace_info obj.namespace = _this.abcnamespaceinfo(abcbitio); // ns_set_info obj.nsset = _this.abcnssetinfo(abcbitio); // multiname_info; obj.multiname_info = _this.abcmultinameinfo(abcbitio); var i = 0; // method_info obj.method = []; var methodcount = abcbitio.getu30(); if (methodcount) { var method = []; for (i = 0; i < methodcount; i++) { method[i] = _this.abcmethodinfo(abcbitio); } obj.method = method; } // metadata_info obj.metadata = []; var metadatacount = abcbitio.getu30(); if (metadatacount) { var metadatainfo = []; for (i = 0; i < metadatacount; i++) { metadatainfo[i] = _this.abcmetadatainfo(abcbitio); } obj.metadata = metadatainfo; } var classcount = abcbitio.getu30(); obj.instance = []; obj.class = []; if (classcount) { // instance_info var instance = []; for (i = 0; i < classcount; i++) { instance[i] = _this.abcinstanceinfo(abcbitio); } obj.instance = instance; // class_info var classinfo = []; for (i = 0; i < classcount; i++) { classinfo[i] = _this.abcclassinfo(abcbitio); } obj.class = classinfo; } // script_info obj.script = []; var scriptcount = abcbitio.getu30(); if (scriptcount) { var script = []; for (i = 0; i < scriptcount; i++) { script[i] = _this.abcscriptinfo(abcbitio); } obj.script = script; } // method_body_info obj.methodbody = []; var methodbodycount = abcbitio.getu30(); if (methodbodycount) { var methodbody = []; for (i = 0; i < methodbodycount; i++) { var mbody = _this.abcmethodbodyinfo(abcbitio); methodbody[mbody.method] = mbody; } obj.methodbody = methodbody; } // build names obj = _this.abcmultinametostring(obj); // build instance _this.abcbuildinstance(obj); }; /** * @param obj */ swftag.prototype.abcbuildinstance = function (obj) { var _this = this; var instances = obj.instance; var length = instances.length; var namespaces = obj.namespace; var string = obj.string; var stage = _this.stage; var names = obj.names; for (var i = 0; i < length; i++) { var instance = instances[i]; var flag = instance.flags; var nsindex = null; if (flag & 0x08) { nsindex = instance.protectedns; } var object = {}; if (nsindex) { var nobj = namespaces[nsindex]; object = string[nobj.name]; } else { object = names[instance.name]; } var values = object.split(":"); var classname = values.pop(); var ns = values.pop(); // build parent var avm2 = function (mc) { this["__swf2js__::builder"] = mc; }; var prop = avm2.prototype; // constructor prop[classname] = _this.abccreateactionscript3(obj, instance.iinit, object); // prototype var traits = instance.trait; var tlength = traits.length; var register = []; var rcount = 1; if (tlength) { for (var idx = 0; idx < tlength; idx++) { var trait = traits[idx]; var tname = names[trait.name]; var tnames = tname.split("::"); var pname = tnames.pop(); var kind = trait.kind; var val = undefined; switch (kind) { case 0: // slot register[rcount++] = pname; break; case 1: // method case 2: // getter case 3: // setter val = _this.abccreateactionscript3(obj, trait.data.info, object); break; case 4: // class console.log("build: class"); break; case 5: // function console.log("build: function"); break; case 6: // const console.log("build: const"); break; } prop[pname] = val; } } var localname = "__swf2js__:"+ object; prop[localname] = {}; // extends var supername = instance.supername; prop[localname].extends = names[supername]; // register prop[localname].register = register; // build var abc = stage.abc; var classobj = stage.avm2; if (ns) { var nss = ns.split("."); var nlen = nss.length; for (var nidx = 0; nidx < nlen; nidx++) { if (!(nss[nidx] in classobj)) { classobj[nss[nidx]] = {}; abc[nss[nidx]] = {}; } classobj = classobj[nss[nidx]]; abc = abc[nss[nidx]]; } } abc[classname] = avm2; classobj[classname] = new avm2(); } }; /** * @param obj * @param methodid * @param abckey */ swftag.prototype.abccreateactionscript3 = function (obj, methodid, abckey) { var stage = this.stage; return (function (data, id, ns, stage) { return function () { var as3 = new actionscript3(data, id, ns, stage); as3.caller = this; as3.args = arguments; return as3.execute(); }; })(obj, methodid, abckey, stage); }; /** * @param obj * @returns {*} */ swftag.prototype.abcmultinametostring = function (obj) { var multinames = obj.multiname_info; var length = multinames.length; var string = obj.string; var ns = obj.namespace; var names = []; for (var i = 1; i < length; i++) { var info = multinames[i]; var str = ""; switch (info.kind) { case 0x07: // qname case 0x0d: // qnamea var namespace_info = ns[info.ns]; switch (namespace_info.kind) { default: str += string[namespace_info.name]; break; case 0x05: str += "private"; break; } if (str !== "") { str += "::"; } str += string[info.name]; break; case 0x0f: // rtqname case 0x10: // rtqnamea console.log("rtqname", i, info); break; case 0x09: // multiname case 0x0e: // multinamea str = string[info.name]; break; case 0x1b: // multinamel case 0x1c: // multinamela str = null; break; case 0x11: // rtqnamel case 0x12: // rtqnamela console.log("rtqnamel", i, info); break; } names[i] = str; } obj.names = names; return obj; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abcinteger = function (abcbitio) { var array = []; var count = abcbitio.getu30(); if (count) { for (var i = 1; i < count; i++) { array[i] = abcbitio.gets30(); } } return array; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abcuinteger = function (abcbitio) { var array = []; var count = abcbitio.getu30(); if (count) { for (var i = 1; i < count; i++) { array[i] = abcbitio.getu30(); } } return array; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abcdouble = function (abcbitio) { var array = []; var count = abcbitio.getu30(); if (count) { for (var i = 1; i < count; i++) { array[i] = abcbitio.getfloat64littleendian(); } } return array; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abcstringinfo = function (abcbitio) { var array = []; var count = abcbitio.getu30(); if (count) { for (var i = 1; i < count; i++) { array[i] = abcbitio.abcreadstring(); } } return array; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abcnamespaceinfo = function (abcbitio) { var array = []; var count = abcbitio.getu30(); if (count) { for (var i = 1; i < count; i++) { array[i] = { kind: abcbitio.getui8(), name: abcbitio.getu30() }; } } return array; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abcnssetinfo = function (abcbitio) { var array = []; var count = abcbitio.getu30(); if (count) { for (var i = 1; i < count; i++) { var nscount = abcbitio.getu30(); var ns = []; if (nscount) { for (var j = 0; j < nscount; j++) { ns[j] = abcbitio.getu30(); } } array[i] = ns; } } return array; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abcmultinameinfo = function (abcbitio) { var array = []; var count = abcbitio.getu30(); if (count) { for (var i = 1; i < count; i++) { var obj = {}; obj.kind = abcbitio.getui8(); switch (obj.kind) { case 0x07: // qname case 0x0d: // qnamea obj.ns = abcbitio.getu30(); obj.name = abcbitio.getu30(); break; case 0x0f: // rtqname case 0x10: // rtqnamea obj.name = abcbitio.getu30(); break; case 0x09: // multiname case 0x0e: // multinamea obj.name = abcbitio.getu30(); obj.ns_set = abcbitio.getu30(); break; case 0x1b: // multinamel case 0x1c: // multinamela obj.ns_set = abcbitio.getu30(); break; case 0x11: // rtqnamel case 0x12: // rtqnamela break; } array[i] = obj; } } return array; }; /** * @param abcbitio * @returns {{}} */ swftag.prototype.abcmethodinfo = function (abcbitio) { var obj = {}; var i; var count = abcbitio.getu30(); obj.paramcount = count; obj.returntype = abcbitio.getu30(); obj.paramtype = []; if (count) { var paramtype = []; for (i = 0; i < count; i++) { paramtype[paramtype.length] = abcbitio.getu30(); } obj.paramtype = paramtype; } obj.name = abcbitio.getu30(); obj.flags = abcbitio.getui8(); obj.options = []; if (obj.flags === 0x08) { var options = []; var optioncount = abcbitio.getu30(); if (optioncount) { for (i = 0; i < optioncount; i++) { options[options.length] = { val: abcbitio.getu30(), kind: abcbitio.getui8() }; } } obj.options = options; } obj.paramname = []; if (obj.flags === 0x80) { var paramname = []; if (count) { for (i = 0; i < count; i++) { paramname[paramname.length] = abcbitio.getu30(); } } obj.paramname = paramname; } return obj; }; /** * @param abcbitio * @returns {{}} */ swftag.prototype.abcmetadatainfo = function (abcbitio) { var obj = {}; obj.name = abcbitio.getu30(); obj.items = []; var count = abcbitio.getu30(); if (count) { var items = []; for (var i = 0; i < count; i++) { items[items.length] = { key: abcbitio.getu30(), value: abcbitio.getu30() }; } obj.items = items; } return obj; }; /** * @param abcbitio * @returns {{}} */ swftag.prototype.abcinstanceinfo = function (abcbitio) { var obj = {}; obj.name = abcbitio.getu30(); obj.supername = abcbitio.getu30(); obj.flags = abcbitio.getui8(); if (obj.flags & 0x08) { obj.protectedns = abcbitio.getu30(); } var count = abcbitio.getu30(); obj.interfaces = []; if (count) { var interfaces = []; for (var i = 0; i < count; i++) { interfaces[interfaces.length] = abcbitio.getu30(); } obj.interfaces = interfaces; } obj.iinit = abcbitio.getu30(); obj.trait = this.abctrait(abcbitio); return obj; }; /** * @param abcbitio * @returns {{}} */ swftag.prototype.abcclassinfo = function (abcbitio) { var obj = {}; obj.cinit = abcbitio.getu30(); obj.trait = this.abctrait(abcbitio); return obj; }; /** * @param abcbitio */ swftag.prototype.abcscriptinfo = function (abcbitio) { var obj = {}; obj.init = abcbitio.getu30(); obj.trait = this.abctrait(abcbitio); return obj; }; /** * @param abcbitio * @returns {{}} */ swftag.prototype.abcmethodbodyinfo = function (abcbitio) { var _this = this; var obj = {}; obj.method = abcbitio.getu30(); obj.maxstack = abcbitio.getu30(); obj.localcount = abcbitio.getu30(); obj.initscopedepth = abcbitio.getu30(); obj.maxscopedepth = abcbitio.getu30(); var i; var count = abcbitio.getu30(); var codes = []; if (count) { codes = _this.abcbuildcode(abcbitio, count); } obj.codes = codes; count = abcbitio.getu30(); var exceptions = []; if (count) { for (i = 0; i < count; i++) { exceptions[exceptions.length] = _this.abcexception(abcbitio); } } obj.exceptions = exceptions; obj.trait = _this.abctrait(abcbitio); return obj; }; /** * @param abcbitio * @param count * @returns {array} */ swftag.prototype.abcbuildcode = function (abcbitio, count) { var array = []; var cacheoffset; for (var i = 0; i < count; i++) { var obj = {}; var offset = 0; var code = abcbitio.getui8(); obj.code = code; switch (code) { case 0x86: // astype case 0x41: // call case 0x80: // coerce case 0x42: // construct case 0x49: // constructsuper case 0xf1: // debugfile case 0xf0: // debugline case 0x94: // declocal case 0xc3: // declocal_i case 0x6a: // deleteproperty case 0x06: // dxns case 0x5e: // findproperty case 0x5d: // findpropstrict case 0x59: // getdescendants case 0x6e: // getglobalslot case 0x60: // getlex case 0x62: // getlocal case 0x66: // getproperty case 0x6c: // getslot case 0x04: // getsuper case 0x92: // inclocal case 0xc2: // inclocal_i case 0x68: // initproperty case 0xb2: // istype case 0x08: // kill case 0x56: // newarray case 0x5a: // newcatch case 0x58: // newclass case 0x40: // newfunction case 0x55: // newobject case 0x2f: // pushdouble case 0x2d: // pushint case 0x31: // pushnamespace case 0x25: // pushshort case 0x2c: // pushstring case 0x2e: // pushuint case 0x63: // setlocal case 0x6f: // setglobalslot case 0x61: // setproperty case 0x6d: // setslot case 0x05: // setsuper cacheoffset = abcbitio.byte_offset; obj.value1 = abcbitio.getu30(); offset += (abcbitio.byte_offset - cacheoffset); break; case 0x1b: // lookupswitch obj.value1 = abcbitio.getsi24(); offset += 3; cacheoffset = abcbitio.byte_offset; obj.value2 = abcbitio.getsi24(); offset += (abcbitio.byte_offset - cacheoffset); obj.value3 = abcbitio.getsi24(); offset += 3; break; case 0x65: // getscopeobject case 0x24: // pushbyte obj.value1 = abcbitio.getsi8(); offset += 1; break; case 0x32: // hasnext2 obj.value1 = abcbitio.getsi8(); obj.value2 = abcbitio.getsi8(); offset += 2; break; case 0x13: // ifeq case 0x12: // iffalse case 0x18: // ifge case 0x17: // ifgt case 0x16: // ifle case 0x15: // iflt case 0x0f: // ifnge case 0x0e: // ifngt case 0x0d: // ifnle case 0x0c: // ifnlt case 0x14: // ifne case 0x19: // ifstricteq case 0x1a: // ifstrictne case 0x11: // iftrue case 0x10: // jump obj.value1 = abcbitio.getsi24(); offset += 3; break; case 0x43: // callmethod case 0x46: // callproperty case 0x4c: // callproplex case 0x4f: // callpropvoid case 0x44: // callstatic case 0x45: // callsuper case 0x4e: // callsupervoid case 0x4a: // constructprop case 0xef: // debug cacheoffset = abcbitio.byte_offset; obj.value1 = abcbitio.getu30(); obj.value2 = abcbitio.getu30(); offset += (abcbitio.byte_offset - cacheoffset); break; } obj.offset = offset; array[i] = obj; i += offset; } return array; }; /** * @param abcbitio * @returns {{}} */ swftag.prototype.abcexception = function (abcbitio) { var obj = {}; obj.from = abcbitio.getu30(); obj.to = abcbitio.getu30(); obj.target = abcbitio.getu30(); obj.exctype = abcbitio.getu30(); obj.varname = abcbitio.getu30(); return obj; }; /** * @param abcbitio * @returns {array} */ swftag.prototype.abctrait = function (abcbitio) { var count = abcbitio.getu30(); var trait = []; if (count) { for (var i = 0; i < count; i++) { var tobj = {}; tobj.name = abcbitio.getu30(); var tag = abcbitio.getui8(); var kind = tag & 0x0f; var attributes = (kind >> 4) & 0x0f; var data = {}; switch (kind) { default: console.log("error:"+ kind); break; case 0: // trait_slot case 6: // trait_const data.id = abcbitio.getu30(); data.name = abcbitio.getu30(); data.index = abcbitio.getu30(); data.kind = null; if (data.index !== 0) { data.kind = abcbitio.getui8(); } break; case 1: // trait_method case 2: // trait_getter case 3: // trait_setter data.id = abcbitio.getu30(); data.info = abcbitio.getu30(); break; case 4: // trait_class data.id = abcbitio.getu30(); data.info = abcbitio.getu30(); break; case 5: // trait_function data.id = abcbitio.getu30(); data.info = abcbitio.getu30(); break; } tobj.kind = kind; tobj.data = data; if (attributes & 0x04) { var metadatacount = abcbitio.getu30(); var metadata = []; if (metadatacount) { for (var j = 0; j < metadatacount; j++) { metadata[metadata.length] = abcbitio.getu30(); } } tobj.metadata = metadata; } trait[trait.length] = tobj; } } return trait; }; /** * parsesymbolclass */ swftag.prototype.parsesymbolclass = function () { var bitio = this.bitio; var stage = this.stage; var symbols = stage.symbols; var count = bitio.getui16(); if (count) { while (count--) { var tagid = bitio.getui16(); symbols[tagid] = bitio.getdatauntil("\0"); } } }; /** * @param tagtype * @param length */ swftag.prototype.parsedefinesound = function (tagtype, length) { var obj = {}; var _this = this; var bitio = _this.bitio; var stage = _this.stage; var startoffset = bitio.byte_offset; obj.tagtype = tagtype; obj.soundid = bitio.getui16(); obj.soundformat = bitio.getuibits(4); obj.soundrate = bitio.getuibits(2); obj.soundsize = bitio.getuibit(); obj.soundtype = bitio.getuibit(); obj.soundsamplecount = bitio.getui32(); var sub = bitio.byte_offset - startoffset; var datalength = length - sub; var data = bitio.getdata(datalength); var sounddata = ""; for (var i = 0; i < datalength; i++) { sounddata += _fromcharcode(data[i]); } bitio.byte_offset = startoffset + length; var mimetype = ""; switch (obj.soundformat) { case 0: // uncompressed native-endian case 3: // uncompressed little-endian mimetype = "wave"; break; case 1: // adpcm ? 32kadpcm mimetype = "wave"; break; case 2: // mp3 mimetype = "mpeg"; break; case 4: // nellymoser 16 case 5: // nellymoser 8 case 6: // mimetype = "nellymoser"; break; case 11: // speex mimetype = "speex"; break; case 15: mimetype = "x-aiff"; break; } obj.base64 = "data:audio/" + mimetype + ";base64," + window.btoa(sounddata); stage.sounds[obj.soundid] = obj; }; /** * @param tagtype */ swftag.prototype.parsestartsound = function (tagtype) { var _this = this; var bitio = _this.bitio; var obj = {}; var stage = _this.stage; obj.tagtype = tagtype; obj.soundid = bitio.getui16(); if (tagtype === 89) { obj.soundclassname = bitio.getdatauntil("\0"); } obj.soundinfo = _this.parsesoundinfo(); stage.setcharacter(obj.soundid, obj); var sound = stage.sounds[obj.soundid]; var audio = _document.createelement("audio"); audio.onload = function () { this.load(); this.preload = "auto"; this.autoplay = false; this.loop = false; }; audio.src = sound.base64; var loadsounds = stage.loadsounds; loadsounds[loadsounds.length] = audio; return { soundid: obj.soundid, audio: audio, tagtype: tagtype }; }; /** * parsedefinebuttonsound */ swftag.prototype.parsedefinebuttonsound = function () { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var buttonid = bitio.getui16(); var btnobj = stage.getcharacter(buttonid); for (var i = 0; i < 4; i++) { var soundid = bitio.getui16(); if (soundid) { var soundinfo = _this.parsesoundinfo(); switch (i) { case 0: btnobj.buttonstateupsoundinfo = soundinfo; btnobj.buttonstateupsoundid = soundid; break; case 1: btnobj.buttonstateoversoundinfo = soundinfo; btnobj.buttonstateoversoundid = soundid; break; case 2: btnobj.buttonstatedownsoundinfo = soundinfo; btnobj.buttonstatedownsoundid = soundid; break; case 3: btnobj.buttonstatehittestsoundinfo = soundinfo; btnobj.buttonstatehittestsoundid = soundid; break; } } } stage.setcharacter(buttonid, btnobj); }; /** * @returns {{}} */ swftag.prototype.parsesoundinfo = function () { var obj = {}; var bitio = this.bitio; bitio.getuibits(2); // reserved obj.syncstop = bitio.getuibit(); obj.syncnomultiple = bitio.getuibit(); obj.hasenvelope = bitio.getuibit(); obj.hasloops = bitio.getuibit(); obj.hasoutpoint = bitio.getuibit(); obj.hasinpoint = bitio.getuibit(); if (obj.hasinpoint) { obj.inpoint = bitio.getui32(); } if (obj.hasoutpoint) { obj.outpoint = bitio.getui32(); } if (obj.hasloops) { obj.loopcount = bitio.getui16(); } if (obj.hasenvelope) { obj.envpoints = bitio.getui8(); obj.enveloperecords = []; for (var i = 0; i < obj.envpoints; i++) { obj.enveloperecords[i] = { pos44: bitio.getui32(), leftlevel: bitio.getui16(), rightlevel: bitio.getui16() }; } } return obj; }; /** * parsedefinefontalignzones */ swftag.prototype.parsedefinefontalignzones = function () { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var fontid = bitio.getui16(); var tag = stage.getcharacter(fontid); tag.csmtablehint = bitio.getuibits(2); bitio.getuibits(6); // reserved var numglyphs = tag.numglyphs; var zonetable = []; for (var i = 0; i < numglyphs; i++) { var numzonedata = bitio.getui8(); var zonedata = []; for (var idx = 0; idx < numzonedata; idx++) { zonedata[idx] = bitio.getui32(); } zonetable[i] = { zonedata: zonedata, mask: bitio.getui8() }; } bitio.bytealign(); tag.zonetable = zonetable; stage.setcharacter(fontid, tag); }; /** * @param tagtype */ swftag.prototype.parsecsmtextsettings = function (tagtype) { var _this = this; var obj = {}; var bitio = _this.bitio; obj.tagtype = tagtype; obj.textid = bitio.getui16(); obj.useflashtype = bitio.getuibits(2); obj.gridfit = bitio.getuibits(3); bitio.getuibits(3); // reserved obj.thickness = bitio.getui32(); obj.sharpness = bitio.getui32(); bitio.getui8(); // reserved }; /** * @param tagtype * @param length */ swftag.prototype.parsesoundstreamblock = function (tagtype, length) { var _this = this; var bitio = _this.bitio; var obj = {}; obj.tagtype = tagtype; obj.compressed = bitio.getdata(length); }; /** * @param tagtype */ swftag.prototype.parsedefinevideostream = function (tagtype) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var obj = {}; obj.tagtype = tagtype; obj.characterid = bitio.getui16(); obj.numframes = bitio.getui16(); obj.width = bitio.getui16(); obj.height = bitio.getui16(); bitio.getuibits(4); // reserved obj.videoflagsdeblocking = bitio.getuibits(3); obj.videoflagssmoothing = bitio.getuibits(1); obj.codecid = bitio.getui8(); stage.setcharacter(obj.characterid, obj); console.log(obj); }; /** * * @param tagtype * @param length */ swftag.prototype.parsevideoframe = function (tagtype, length) { var _this = this; var bitio = _this.bitio; var stage = _this.stage; var startoffset = bitio.byte_offset; var obj = {}; obj.tagtype = tagtype; obj.streamid = bitio.getui16(); obj.framenum = bitio.getui16(); var streamdata = stage.getcharacter(obj.streamid); var sub = bitio.byte_offset - startoffset; var datalength = length - sub; var videodata; switch (streamdata.codecid) { case 4: videodata = _this.parsevp6swfvideopacket(datalength); break; } bitio.byte_offset = startoffset + length; // obj.base64 = 'data:image/jpeg;base64,' + window.btoa(videodata); stage.videos[obj.streamid] = obj; }; /** * @param length * @returns {string} */ swftag.prototype.parsevp6swfvideopacket = function (length) { var _this = this; var bitio = _this.bitio; var videodata = ""; var data = bitio.getdata(length); console.log(data); return videodata; }; /** * parsefileattributes */ swftag.prototype.parsefileattributes = function () { var _this = this; var bitio = _this.bitio; var obj = {}; bitio.getuibit(); // reserved obj.usedirectblit = bitio.getuibit(); obj.usegpu = bitio.getuibit(); obj.hasmetadata = bitio.getuibit(); obj.actionscript3 = bitio.getuibit(); obj.reserved2 = bitio.getuibits(3); obj.usenetwork = bitio.getuibit(); obj.reserved3 = bitio.getuibits(24); }; /** * parsedefinescalinggrid */ swftag.prototype.parsedefinescalinggrid = function () { var _this = this; var bitio = _this.bitio; var obj = {}; obj.characterid = bitio.getui16(); obj.splitter = _this.rect(); }; /** * @constructor */ var activation = function () {}; /** * @param data * @param id * @param ns * @param stage * @constructor */ var actionscript3 = function (data, id, ns, stage) { var _this = this; // params _this.id = id; _this.caller = null; _this.parent = null; _this.activation = null; _this.scopestack = []; _this.currentindex = 0; _this.stage = stage; _this.args = []; _this.variables = {}; // abc code and info var methodbody = data.methodbody[id]; _this.body = methodbody; _this.codes = methodbody.codes; _this.info = data.method[methodbody.method]; // pool and data _this.names = data.names; _this.data = data; // ns _this.ns = ns; // register _this.avm2 = _this.getavm2(); _this.register = _this.avm2["__swf2js__:"+ns].register; _this.register[0] = _this.avm2; // trait var trait = methodbody.trait; var length = trait.length; for (var i = 0; i < length; i++) { var obj = trait[i]; var kind = obj.kind; switch (kind) { case 0: // var key = _this.names[obj.name]; break; } } }; /** * @type {{}} */ actionscript3.prototype.methods = { gotoandstop: 1, gotoandplay: 1, play: 1, stop: 1, duplicatemovieclip: 1, getproperty: 1, removemovieclip: 1, setproperty: 1, startdrag: 1, stopdrag: 1, targetpath: 1, updateafterevent: 1, nextframe: 1, nextscene: 1, prevframe: 1, prevscene: 1, stopallsounds: 1, setmask: 1, geturl: 1, loadmovie: 1, loadmovienum: 1, loadvariables: 1, loadvariablesnum: 1, unloadmovie: 1, unloadmovienum: 1, swapdepths: 1, getinstanceatdepth: 1, attachmovie: 1, attachaudio: 1, attachbitmap: 1, getnexthighestdepth: 1, getbytesloaded: 1, getbytestotal: 1, assetpropflags: 1, linestyle: 1, linegradientstyle: 1, beginfill: 1, begingradientfill: 1, beginbitmapfill: 1, graphics: 1, buttonmode: 1, clear: 1, moveto: 1, lineto: 1, curveto: 1, endfill: 1, hittest: 1, getdepth: 1, createemptymovieclip: 1, createtextfield: 1, getbounds: 1, getrect: 1, getswfversion: 1, gettextsnapshot: 1, globaltolocal: 1, localtoglobal: 1, addframescript: 1, trace: 1, addeventlistener: 1, removeeventlistener: 1, x: 1, y: 1, alpha: 1, name: 1, blendmode: 1, filters: 1, visible: 1, rotation: 1, height: 1, width: 1, scalex: 1, scaley: 1, mousex: 1, mousey: 1, mask: 1, mouseenabled: 1 }; /** * @returns {*} */ actionscript3.prototype.getavm2 = function () { var _this = this; var ns = _this.ns; var stage = _this.stage; var values = ns.split(":"); var classname = values.pop(); var nlen = values.length; var classobj = stage.avm2; for (var i = 0; i < nlen; i++) { classobj = classobj[values[i]]; } return classobj[classname]; }; /** * @returns {*} */ actionscript3.prototype.getbuilder = function () { return this.avm2["__swf2js__::builder"]; }; /** * @returns {*} */ actionscript3.prototype.getsuperclass = function () { var _this = this; return _this.avm2["__swf2js__:"+_this.ns].superclass; }; /** * @param superclass */ actionscript3.prototype.setsuperclass = function (superclass) { var _this = this; _this.avm2["__swf2js__:"+_this.ns].superclass = superclass; }; /** * @returns {*} */ actionscript3.prototype.getparent = function () { return this.parent; }; /** * @param name * @returns {*} */ actionscript3.prototype.getproperty = function (name) { var _this = this; var stage = _this.stage; var value; // local1 if (_this.activation) { value = _this.activation[name]; } // parent if (value === undefined) { var parent = _this.getparent(); if (parent) { value = parent.getproperty(name); } } // property if (value === undefined) { var builder = _this.getbuilder(); if (builder) { if (name in _this.methods) { value = builder[name]; } if (value === undefined) { value = builder.getproperty(name); } } } // local2 if (value === undefined && name.indexof("::") !== -1) { var values = name.split("::"); var classname = values.pop(); var path = values.pop(); if (path !== "private") { var patharr = path.split("."); var plen = patharr.length; var classobj = stage.avm2; for (var pidx = 0; pidx < plen; pidx++) { classobj = classobj[patharr[pidx]]; } value = classobj[classname]; if (value === undefined) { value = _this.avm2[classname]; } } else { value = _this.avm2["private::"+ classname]; } } // global if (value === undefined) { value = stage.avm2[name]; } return value; }; /** * setoptions */ actionscript3.prototype.setoptions = function () { var _this = this; var info = _this.info; var paramcount = info.paramcount; if (paramcount) { var data = _this.data; var options = info.options; var paramtype = info.paramtype; var stage = _this.stage; for (var i = 0; i < paramcount; i++) { var value = undefined; if (i in options) { var option = options[i]; var val = option.val; switch (option.kind) { case 0x01: // string value = data.string[val]; break; default: console.log("options", option); break; } } if (i in paramtype) { var ptype = paramtype[i]; if (ptype) { var mname = data.multiname_info[ptype]; var classname = null; var path = ""; switch (mname.kind) { case 0x07: // qname var ns = data.namespace[mname.ns]; switch (ns.kind) { case 0x16: path = data.string[ns.name]; break; default: console.log("setoptions", ns); break; } classname = data.string[mname.name]; break; } if (path) { var values = path.split("."); var plen = values.length; var classobj = stage.avm2; for (var idx = 0; idx < plen; idx++) { classobj = classobj[values[idx]]; } value = classobj[classname]; } } } if (_this.args[i] === undefined) { _this.args[i] = value; } } } }; /** * execute */ actionscript3.prototype.execute = function () { var _this = this; var stack = []; _this.scopestack = []; var i = 0; var offset = 0; var codes = _this.codes; var length = codes.length; _this.setoptions(); while(i < length) { var obj = codes[i]; switch (obj.code) { case 0xa0: _this.actionadd(stack); break; case 0xc5: _this.actionaddi(stack); break; case 0x86: _this.actionastype(stack, obj.value1); break; case 0x87: _this.actionastypelate(stack); break; case 0xa8: _this.actionbitand(stack); break; case 0x97: _this.actionbitnot(stack); break; case 0xa9: _this.actionbitor(stack); break; case 0xaa: _this.actionbitxor(stack); break; case 0x41: _this.actioncall(stack, obj.value1); break; case 0x43: _this.actioncallmethod(stack, obj.value1, obj.value2); break; case 0x46: _this.actioncallproperty(stack, obj.value1, obj.value2); break; case 0x4c: _this.actioncallproplex(stack, obj.value1, obj.value2); break; case 0x4f: _this.actioncallpropvoid(stack, obj.value1, obj.value2); break; case 0x44: _this.actioncallstatic(stack, obj.value1, obj.value2); break; case 0x45: _this.actioncallsuper(stack, obj.value1, obj.value2); break; case 0x4e: _this.actioncallsupervoid(stack, obj.value1, obj.value2); break; case 0x78: _this.actioncheckfilter(stack); break; case 0x80: _this.actioncoerce(stack, obj.value1); break; case 0x82: _this.actioncoercea(stack); break; case 0x85: _this.actioncoerces(stack); break; case 0x42: _this.actionconstruct(stack, obj.value1); break; case 0x4a: _this.actionconstructprop(stack, obj.value1, obj.value2); break; case 0x49: _this.actionconstructsuper(stack, obj.value1); break; case 0x76: _this.actionconvertb(stack); break; case 0x73: _this.actionconverti(stack); break; case 0x75: _this.actionconvertd(stack); break; case 0x77: _this.actionconverto(stack); break; case 0x74: _this.actionconvertu(stack); break; case 0x70: _this.actionconverts(stack); break; case 0xef: _this.actiondebug(stack, obj.value1, obj.value2, obj.value3, obj.value4); break; case 0xf1: _this.actiondebugfile(stack, obj.value1); break; case 0xf0: _this.actiondebugline(stack); break; case 0x94: _this.actiondeclocal(stack, obj.value1); break; case 0xc3: _this.actiondeclocali(stack, obj.value1); break; case 0x93: _this.actiondecrement(stack); break; case 0xc1: _this.actiondecrementi(stack); break; case 0x6a: _this.actiondeleteproperty(stack, obj.value1); break; case 0xa3: _this.actiondivide(stack); break; case 0x2a: _this.actiondup(stack); break; case 0x06: _this.actiondxns(stack, obj.value1); break; case 0x07: _this.actiondxnslate(stack); break; case 0xab: _this.actionequals(stack); break; case 0x72: _this.actionescxattr(stack); break; case 0x71: _this.actionescxelem(stack); break; case 0x5e: _this.actionfindproperty(stack, obj.value1); break; case 0x5d: _this.actionfindpropstrict(stack, obj.value1); break; case 0x59: _this.actiongetdescendants(stack, obj.value1); break; case 0x64: _this.actiongetglobalscope(stack); break; case 0x6e: _this.actiongetglobalslot(stack, obj.value1); break; case 0x60: _this.actiongetlex(stack, obj.value1); break; case 0x62: _this.actiongetlocal(stack, obj.value1); break; case 0xd0: _this.actiongetlocal0(stack); break; case 0xd1: _this.actiongetlocal1(stack); break; case 0xd2: _this.actiongetlocal2(stack); break; case 0xd3: _this.actiongetlocal3(stack); break; case 0x66: _this.actiongetproperty(stack, obj.value1); break; case 0x65: _this.actiongetscopeobject(stack, obj.value1); break; case 0x6c: _this.actiongetslot(stack, obj.value1); break; case 0x04: _this.actiongetsuper(stack, obj.value1); break; case 0xb0: _this.actiongreaterequals(stack); break; case 0xaf: _this.actiongreaterthan(stack); break; case 0x1f: _this.actionhasnext(stack); break; case 0x32: _this.actionhasnext2(stack, obj.value1, obj.value2); break; case 0x12: offset = _this.actioniffalse(stack, obj.value1); i += offset; break; case 0x18: offset = _this.actionifge(stack, obj.value1); i += offset; break; case 0x17: offset = _this.actionifgt(stack, obj.value1); i += offset; break; case 0x16: offset = _this.actionifle(stack, obj.value1); i += offset; break; case 0x15: offset = _this.actioniflt(stack, obj.value1); i += offset; break; case 0x0f: offset = _this.actionifnge(stack, obj.value1); i += offset; break; case 0x0e: offset = _this.actionifngt(stack, obj.value1); i += offset; break; case 0x0d: offset = _this.actionifnle(stack, obj.value1); i += offset; break; case 0x0c: offset = _this.actionifnlt(stack, obj.value1); i += offset; break; case 0x14: offset = _this.actionifne(stack, obj.value1); i += offset; break; case 0x19: offset = _this.actionifstricteq(stack, obj.value1); i += offset; break; case 0x1a: offset = _this.actionifstrictne(stack, obj.value1); i += offset; break; case 0x11: offset = _this.actioniftrue(stack, obj.value1); i += offset; break; case 0xb4: _this.actionin(stack, obj.value1); break; case 0x92: _this.actioninclocal(stack, obj.value1); break; case 0xc2: _this.actioninclocali(stack, obj.value1); break; case 0x91: _this.actionincrement(stack); break; case 0xc0: _this.actionincrementi(stack); break; case 0x68: _this.actioninitproperty(stack, obj.value1); break; case 0xb1: _this.actioninstanceof(stack); break; case 0xb2: _this.actionistype(stack, obj.value1); break; case 0xb3: _this.actionistypelate(stack); break; case 0x10: // actionjump offset = obj.value1; i += offset; break; case 0x08: _this.actionkill(stack, obj.value1); break; case 0x09: _this.actionlabel(stack); break; case 0xae: _this.actionlessequals(stack); break; case 0xad: _this.actionlessthan(stack); break; case 0x1b: _this.actionlookupswitch(stack, obj.value1, obj.value1, obj.value3); break; case 0xa5: _this.actionlshift(stack); break; case 0xa4: _this.actionmodulo(stack); break; case 0xa2: _this.actionmultiply(stack); break; case 0xc7: _this.actionmultiplyi(stack); break; case 0x90: _this.actionnegate(stack); break; case 0xc4: _this.actionnegatei(stack); break; case 0x57: _this.actionnewactivation(stack); break; case 0x56: _this.actionnewarray(stack, obj.value1); break; case 0x5a: _this.actionnewcatch(stack, obj.value1); break; case 0x58: _this.actionnewclass(stack, obj.value1); break; case 0x40: _this.actionnewfunction(stack, obj.value1); break; case 0x55: _this.actionnewobject(stack, obj.value1); break; case 0x1e: _this.actionnextname(stack); break; case 0x23: _this.actionnextvalue(stack); break; case 0x02: _this.actionnop(stack); break; case 0x96: _this.actionnot(stack); break; case 0x29: _this.actionpop(stack); break; case 0x1d: _this.actionpopscope(); break; case 0x24: _this.actionpushbyte(stack, obj.value1); break; case 0x2f: _this.actionpushdouble(stack, obj.value1); break; case 0x27: _this.actionpushfalse(stack, obj.value1); break; case 0x2d: _this.actionpushint(stack, obj.value1); break; case 0x31: _this.actionpushnamespace(stack, obj.value1); break; case 0x28: _this.actionpushnan(stack); break; case 0x20: _this.actionpushnull(stack); break; case 0x30: _this.actionpushscope(stack); break; case 0x25: _this.actionpushshort(stack, obj.value1); break; case 0x2c: _this.actionpushstring(stack, obj.value1); break; case 0x26: _this.actionpushtrue(stack); break; case 0x2e: _this.actionpushuint(stack, obj.value1); break; case 0x21: _this.actionpushundefined(stack); break; case 0x1c: _this.actionpushwith(stack); break; case 0x48: // actionreturnvalue return stack.pop(); case 0x47: // returnvoid return undefined; case 0xa6: _this.actionrshift(stack); break; case 0x63: _this.actionsetlocal(stack, obj.value1); break; case 0xd4: _this.actionsetlocal0(stack); break; case 0xd5: _this.actionsetlocal1(stack); break; case 0xd6: _this.actionsetlocal2(stack); break; case 0xd7: _this.actionsetlocal3(stack); break; case 0x6f: _this.actionsetglobalslot(stack, obj.value1); break; case 0x61: _this.actionsetproperty(stack, obj.value1); break; case 0x6d: _this.actionsetslot(stack, obj.value1); break; case 0x05: _this.actionsetsuper(stack, obj.value1); break; case 0xac: _this.actionstrictequals(stack); break; case 0xa1: _this.actionsubtract(stack); break; case 0xc6: _this.actionsubtracti(stack); break; case 0x2b: _this.actionswap(stack); break; case 0x03: _this.actionthrow(stack); break; case 0x95: _this.actiontypeof(stack); break; case 0xa7: _this.actionurshift(stack); break; } i += obj.offset; i += 1; } }; /** * @param stack */ actionscript3.prototype.actionadd = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 + value2; }; /** * @param stack */ actionscript3.prototype.actionaddi = function (stack) { var value2 = +stack.pop(); var value1 = +stack.pop(); stack[stack.length] = value1 + value2; }; /** * @param stack * @param index */ actionscript3.prototype.actionastype = function (stack, index) { var type = this.names[index]; var value = stack.pop(); stack[stack.length] = (typeof value === type) ? true : null; }; /** * @param stack */ actionscript3.prototype.actionastypelate = function (stack) { var cvalue = stack.pop(); // class var value = stack.pop(); stack[stack.length] = (typeof cvalue === value) ? true : null; }; /** * @param stack */ actionscript3.prototype.actionbitand = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 & value2; }; /** * @param stack */ actionscript3.prototype.actionbitnot = function (stack) { var value = stack.pop(); stack[stack.length] = ~value; }; /** * @param stack */ actionscript3.prototype.actionbitor = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 | value2; }; /** * @param stack */ actionscript3.prototype.actionbitxor = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 ^ value2; }; /** * @param stack * @param argcount */ actionscript3.prototype.actioncall = function (stack, argcount) { var params = []; for (var i = argcount; i--;) { params[i] = stack.pop(); } var receiver = stack.pop(); var func = stack.pop(); var value; if (typeof func === "function") { value = func.apply(receiver, params); } stack[stack.length] = value; }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actioncallmethod = function (stack, index, argcount) { var params = []; for (var i = 0; i < argcount; i++) { params[params.length] = stack.pop(); } var receiver = stack.pop(); var value; if (typeof receiver === "function") { value = receiver.apply(this.caller, params); } stack[stack.length] = value; }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actioncallproperty = function (stack, index, argcount) { var _this = this; var params = []; for (var i = argcount; i--;) { params[params.length] = stack.pop(); } var prop = _this.names[index]; var obj = stack.pop(); var value; if (obj) { var func = null; if (obj instanceof displayobject) { if (prop in _this.methods) { func = obj[prop]; } if (!func) { func = obj.getproperty(prop); } } else { func = obj[prop]; } if (func) { value = func.apply(_this.caller, params); } } stack[stack.length] = value; }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actioncallproplex = function (stack, index, argcount) { var _this = this; var params = []; for (var i = argcount; i--;) { params[params.length] = stack.pop(); } var prop = _this.names[index]; var obj = stack.pop(); var value; if (obj) { value = obj[prop].apply(_this.getbuilder(), params); } stack[stack.length] = value; }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actioncallpropvoid = function (stack, index, argcount) { var _this = this; var params = []; for (var i = argcount; i--;) { params[i] = stack.pop(); } var obj = stack.pop(); var name = _this.names[index]; var values = name.split("::"); // implements var prop = values.pop(); var ns = values.pop(); if (ns) { // console.log(ns, obj, prop); } var func = obj[prop]; if (!func && obj instanceof movieclip) { var stage = obj.getstage(); var symbol = stage.symbols[obj.getcharacterid()]; if (symbol) { var names = symbol.split("."); var classmethod = names.pop(); var length = names.length; var classobj = stage.avm2; for (i = 0; i < length; i++) { classobj = classobj[names[i]]; } if (classobj) { var avm2 = classobj[classmethod]; while (true) { func = avm2[prop]; if (func) { break; } avm2 = avm2.super; if (!avm2 || avm2 instanceof movieclip) { break; } } } } } if (!func) { while (true) { var superclass = obj.super; if (!superclass) { break; } if (superclass instanceof movieclip) { obj = _this.caller; func = obj[prop]; break; } func = superclass[prop]; if (func) { break; } obj = superclass; } } // fscommand if (prop === "fscommand") { obj = _this.stage; } if (func) { func.apply(obj, params); } }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actioncallstatic = function (stack, index, argcount) { console.log("actioncallstatic"); var params = []; for (var i = argcount; i--;) { params[params.length] = stack.pop(); } var receiver = stack.pop(); var value; stack[stack.length] = value; }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actioncallsuper = function (stack, index, argcount) { var params = []; for (var i = argcount; i--;) { params[params.length] = stack.pop(); } var porp = this.names[index]; var receiver = stack.pop(); }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actioncallsupervoid = function (stack, index, argcount) { var params = []; for (var i = argcount; i--;) { params[params.length] = stack.pop(); } var porp = this.names[index]; var receiver = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actioncheckfilter = function (stack) { var value = stack.pop(); stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actioncoerce = function (stack, index) { var value = stack.pop(); var str = this.names[index]; stack[stack.length] = str; }; /** * @param stack */ actionscript3.prototype.actioncoercea = function(stack) { var value = stack.pop(); stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actioncoerces = function (stack) { var value = stack.pop(); stack[stack.length] = string(value); }; /** * @param stack * @param argcount */ actionscript3.prototype.actionconstruct = function (stack, argcount) { var params = []; for (var i = argcount; i--;) { params[params.length] = stack.pop(); } var obj = stack.pop(); stack[stack.length] = obj.construct.apply(obj, params); }; /** * @param stack * @param index * @param argcount */ actionscript3.prototype.actionconstructprop = function (stack, index, argcount) { var _this = this; var params = []; for (var i = argcount; i--;) { params[params.length] = stack.pop(); } var prop = _this.names[index]; var obj = stack.pop(); var value; var stage = _this.stage; var doabc = stage.abc[prop]; if (doabc) { var builder = _this.getbuilder(); var avm2 = new doabc(builder); stage.avm2[prop] = avm2; avm2[prop].apply(builder, params); value = avm2; } else { value = new (function.prototype.bind.apply(obj[prop], params))(); } stack[stack.length] = value; }; /** * @param stack * @param argcount */ actionscript3.prototype.actionconstructsuper = function (stack, argcount) { var _this = this; var params = []; for (var i = argcount; i--;) { params[i] = stack.pop(); } var obj = stack.pop(); var superclassname = obj["__swf2js__:"+_this.ns].extends; var values = superclassname.split("::"); var prop = values.pop(); var ns = values.pop(); var stage = _this.stage; var abcobj = stage.abc; var avmobj = stage.avm2; if (ns) { var names = ns.split("."); var length = names.length; for (i = 0; i < length; i++) { abcobj = abcobj[names[i]]; avmobj = avmobj[names[i]]; } } var sclass = null; var superclass = abcobj[prop]; var builder = _this.getbuilder(); switch (superclass) { case movieclip: sclass = new movieclip(); sclass.setstage(stage); sclass._extend = true; break; case sound: sclass = new sound(); sclass.movieclip = builder; break; default: if (superclass in window) { // object sclass = new (function.prototype.bind.apply(window[superclassname], params))(); } else { sclass = new superclass(builder); avmobj[prop] = sclass; sclass[prop].apply(builder, params); } break; } obj["super"] = sclass; obj["__swf2js__:"+_this.ns].superclass = sclass; }; /** * @param stack */ actionscript3.prototype.actionconvertb = function (stack) { var value = stack.pop(); stack[stack.length] = (value) ? true : false; }; /** * @param stack */ actionscript3.prototype.actionconverti = function (stack) { var value = stack.pop(); stack[stack.length] = value|0; }; /** * @param stack */ actionscript3.prototype.actionconvertd = function (stack) { var value = stack.pop(); stack[stack.length] = +value; }; /** * @param stack */ actionscript3.prototype.actionconverto = function (stack) { var value = stack.pop(); stack[stack.length] = (typeof value === "object") ? value : null; }; /** * @param stack */ actionscript3.prototype.actionconvertu = function (stack) { var value = stack.pop(); value = value|0; if (value < 0) { value *= -1; } stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actionconverts = function (stack) { var value = stack.pop(); stack[stack.length] = string(value); }; /** * @param stack * @param type * @param index * @param reg * @param extra */ actionscript3.prototype.actiondebug = function (stack, type, index, reg, extra) { }; /** * @param stack * @param index */ actionscript3.prototype.actiondebugfile = function (stack, index) { }; /** * @param stack */ actionscript3.prototype.actiondebugline = function (stack) { }; /** * @param stack * @param index */ actionscript3.prototype.actiondeclocal = function (stack, index) { }; /** * @param stack * @param index */ actionscript3.prototype.actiondeclocali = function (stack, index) { }; /** * @param stack */ actionscript3.prototype.actiondecrement = function (stack) { var value = stack.pop(); value -= 1; stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actiondecrementi = function (stack) { var value = stack.pop(); value -= 1; stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actiondeleteproperty = function (stack, index) { var prop = this.name[index]; var obj = stack.pop(); if (obj) { if (prop in obj) { delete obj[prop]; } else { // todo console.log("actiondeleteproperty"); } } stack[stack.length] = true; }; /** * @param stack */ actionscript3.prototype.actiondivide = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 / value2; }; /** * @param stack */ actionscript3.prototype.actiondup = function (stack) { var value = stack.pop(); stack[stack.length] = value; stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actiondxns = function (stack, index) { }; /** * @param stack */ actionscript3.prototype.actiondxnslate = function (stack) { var value = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionequals = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = (value1 == value2); }; /** * @param stack */ actionscript3.prototype.actionescxattr = function (stack) { var value = stack.pop(); stack[stack.length] = string(value); }; /** * @param stack */ actionscript3.prototype.actionescxelem = function (stack) { var value = stack.pop(); stack[stack.length] = string(value); }; /** * @param stack * @param index */ actionscript3.prototype.actionfindproperty = function (stack, index) { var prop = this.names[index]; var obj; stack[stack.length] = obj; }; /** * @param stack * @param index */ actionscript3.prototype.actionfindpropstrict = function (stack, index) { var _this = this; var name = _this.names[index]; var values = name.split("::"); var prop = values.pop(); var ns = values.pop(); var obj = null; // caller var caller = _this.caller; if (caller && !(caller instanceof movieclip)) { if (name in caller) { obj = caller; } } if (!obj) { var avm2 = _this.avm2; if (ns) { var names = ns.split("."); var length = names.length; if (length > 1) { var avmobj = _this.stage.avm2; for (var i = 0; i < length; i++) { avmobj = avmobj[names[i]]; } avm2 = avmobj; } } // local if (prop in avm2) { obj = avm2; } } // find avm if (!obj) { var avm2s = _this.stage.avm2; if (prop in avm2s) { obj = avm2s[prop]; } } // builder if (!obj) { var builder = _this.getbuilder(); if (builder) { if (builder instanceof movieclip) { if (prop in _this.methods) { obj = builder; } if (builder.getproperty() !== undefined) { obj = builder; } } } } if (!obj) { // console.log("actionfindpropstrict::error", name, avm2, this); } stack[stack.length] = obj; }; /** * @param stack * @param index */ actionscript3.prototype.actiongetdescendants = function (stack, index) { console.log("actiongetdescendants"); var porp = this.names[index]; var obj; stack[stack.length] = obj; }; /** * @param stack */ actionscript3.prototype.actiongetglobalscope = function (stack) { var _this = this; var scopestack = _this.scopestack; stack[stack.length] = scopestack[scopestack.length - 1]; }; /** * @param stack * @param index */ actionscript3.prototype.actiongetglobalslot = function (stack, index) { console.log("actiongetglobalslot"); var value; stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actiongetlex = function (stack, index) { var _this = this; var name = _this.names[index]; stack[stack.length] = _this.getproperty(name); }; /** * @param stack * @param index */ actionscript3.prototype.actiongetlocal = function (stack, index) { var _this = this; var value = _this.args[index - 1]; if (value === undefined) { value = _this.register[index]; } stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actiongetlocal0 = function (stack) { stack[stack.length] = this.register[0]; }; /** * @param stack */ actionscript3.prototype.actiongetlocal1 = function (stack) { var _this = this; var value = _this.args[0]; if (value === undefined) { value = _this.register[1]; } stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actiongetlocal2 = function (stack) { var _this = this; var value = _this.args[1]; if (value === undefined) { value = _this.register[2]; } stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actiongetlocal3 = function (stack) { var _this = this; var value = _this.args[2]; if (value === undefined) { value = _this.register[3]; } stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actiongetproperty = function (stack, index) { var _this = this; var prop = _this.names[index]; if (prop === null) { prop = stack.pop(); } var obj = stack.pop(); var value; if (obj && prop) { if (obj instanceof displayobject) { if (prop in _this.methods) { value = obj[prop]; } if (!value && prop === "parent") { value = obj; } if (!value) { value = obj.getproperty(prop); } } else { value = obj[prop]; } if (value === undefined) { value = _this.getproperty(prop); } } stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actiongetscopeobject = function (stack, index) { var activation = this.activation; if (!index) { stack[stack.length] = activation; } else { stack[stack.length] = (index in activation) ? activation : null; } }; /** * @param stack * @param index */ actionscript3.prototype.actiongetslot = function (stack, index) { var obj = stack.pop(); var name = obj[index]; stack[stack.length] = this.activation[name]; }; /** * @param stack * @param index */ actionscript3.prototype.actiongetsuper = function (stack, index) { var prop = this.prop; var obj = stack.pop(); var value; stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actiongreaterequals = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = (value1 >= value2); }; /** * @param stack */ actionscript3.prototype.actiongreaterthan = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = (value1 > value2); }; /** * @param stack */ actionscript3.prototype.actionhasnext = function (stack) { var currentindex = stack.pop(); var obj = stack.pop(); currentindex++; var result = 0; if (obj) { var index = 0; for (var key in obj) { if (!obj.hasownproperty(key)) { continue; } if (index === currentindex) { result = currentindex; break; } index++; } } stack[stack.length] = result; }; /** * @param stack * @param objectreg * @param indexreg */ actionscript3.prototype.actionhasnext2 = function (stack, objectreg, indexreg) { var _this = this; var obj = _this.register[objectreg]; var currentindex = _this.currentindex; var value = false; var index = 0; if (obj) { for (var key in obj) { if (!obj.hasownproperty(key)) { continue; } if (index === currentindex) { value = true; currentindex++; break; } index++; } } if (!value) { currentindex = 0; } _this.currentindex = currentindex; _this.register[indexreg] = index; stack[stack.length] = value; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actioniffalse = function (stack, index) { var value = stack.pop(); return (value === false) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifge = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 < value2) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifgt = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 > value2) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifle = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value2 < value1) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actioniflt = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 < value2) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifnge = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 < value2) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifngt = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value2 < value1) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifnle = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value2 < value1) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifnlt = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 < value2) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifne = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 == value2) ? 0 : index; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifstricteq = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 === value2) ? index : 0; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actionifstrictne = function (stack, index) { var value2 = stack.pop(); var value1 = stack.pop(); return (value1 === value2) ? 0 : index; }; /** * @param stack * @param index * @returns {number} */ actionscript3.prototype.actioniftrue = function (stack, index) { var value = stack.pop(); return (value === true) ? index : 0; }; /** * @param stack */ actionscript3.prototype.actionin = function (stack) { var obj = stack.pop(); var name = stack.pop(); stack[stack.length] = (name in obj); }; /** * @param stack * @param index */ actionscript3.prototype.actioninclocal = function (stack, index) { this.register[index]+=1; }; /** * @param stack * @param index */ actionscript3.prototype.actioninclocali = function (stack, index) { this.register[index]+=1; }; /** * @param stack */ actionscript3.prototype.actionincrement = function (stack) { var value = stack.pop(); value++; stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actionincrementi = function (stack) { var value = stack.pop(); value++; stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actioninitproperty = function (stack, index) { var value = stack.pop(); var prop = this.names[index]; var obj = stack.pop(); if (obj) { if (obj instanceof displayobject) { obj.setproperty(prop, value); } else { obj[prop] = value; } } }; /** * @param stack */ actionscript3.prototype.actioninstanceof = function (stack) { var type = stack.pop(); var value = stack.pop(); stack[stack.length] = (value instanceof type); }; /** * @param stack * @param index */ actionscript3.prototype.actionistype = function (stack, index) { var value = stack.pop(); var type = this.name[index]; stack[stack.length] = (value == type); }; /** * @param stack */ actionscript3.prototype.actionistypelate = function (stack) { var type = stack.pop(); var value = stack.pop(); stack[stack.length] = (value == type); }; /** * @param stack * @param index */ actionscript3.prototype.actionkill = function (stack, index) { delete this.register[index]; }; /** * @param stack */ actionscript3.prototype.actionlabel = function (stack) { }; /** * @param stack */ actionscript3.prototype.actionlessequals = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = (value1 <= value2); }; /** * @param stack */ actionscript3.prototype.actionlessthan = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = (value1 < value2); }; /** * @param stack * @param offset * @param count * @param array */ actionscript3.prototype.actionlookupswitch = function (stack, offset, count, array) { var index = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionlshift = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 << value2; }; /** * @param stack */ actionscript3.prototype.actionmodulo = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 % value2; }; /** * @param stack */ actionscript3.prototype.actionmultiply = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 * value2; }; /** * @param stack */ actionscript3.prototype.actionmultiplyi = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 * value2; }; /** * @param stack */ actionscript3.prototype.actionnegate = function (stack) { var value = stack.pop(); stack[stack.length] = -value; }; /** * @param stack */ actionscript3.prototype.actionnegatei = function (stack) { var value = stack.pop(); stack[stack.length] = -value; }; /** * @param stack */ actionscript3.prototype.actionnewactivation = function (stack) { var _this = this; var trait = _this.body.trait; var length = trait.length; var activation = new activation(); for (var i = 0; i < length; i++) { var obj = trait[i]; var kind = obj.kind; switch (kind) { case 0: activation[i + 1] = _this.names[obj.name]; break; } } _this.activation = activation; stack[stack.length] = activation; }; /** * @param stack * @param argcount */ actionscript3.prototype.actionnewarray = function (stack, argcount) { var array = []; for (var i = argcount; i--;) { array[i] = stack.pop(); } stack[stack.length] = array; }; /** * @param stack * @param index */ actionscript3.prototype.actionnewcatch = function (stack, index) { var catchscope; stack[stack.length] = catchscope; }; /** * @param stack * @param index */ actionscript3.prototype.actionnewclass = function (stack, index) { var basetype = stack.pop(); var data = this.data; var classinfo = data.class[index]; var id = classinfo.cinit; stack[stack.length] = basetype; }; /** * @param stack * @param index */ actionscript3.prototype.actionnewfunction = function (stack, index) { stack[stack.length] = (function (self, id) { return function () { var as3 = new actionscript3(self.data, id, self.ns, self.stage); as3.caller = this; as3.parent = self; as3.args = arguments; return as3.execute(); }; })(this, index); }; /** * @param stack * @param argcount */ actionscript3.prototype.actionnewobject = function (stack, argcount) { var obj = {}; for (var i = argcount; i--;) { var value = stack.pop(); var prop = stack.pop(); obj[prop] = value; } stack[stack.length] = obj; }; /** * @param stack */ actionscript3.prototype.actionnextname = function (stack) { var index = +stack.pop(); var obj = stack.pop(); var name; if (obj) { var count = 0; for (var prop in obj) { if (!obj.hasownproperty(prop)) { continue; } if (count === index) { name = prop; break; } count++; } } stack[stack.length] = name; }; /** * @param stack */ actionscript3.prototype.actionnextvalue = function (stack) { var index = stack.pop(); var obj = stack.pop(); var value; stack[stack.length] = value; }; /** * @param stack */ actionscript3.prototype.actionnop = function (stack) { }; /** * @param stack */ actionscript3.prototype.actionnot = function (stack) { var value = stack.pop(); stack[stack.length] = (!value); }; /** * @param stack */ actionscript3.prototype.actionpop = function (stack) { stack.pop(); }; /** * */ actionscript3.prototype.actionpopscope = function () { this.scopestack.pop(); }; /** * @param stack * @param value */ actionscript3.prototype.actionpushbyte = function (stack, value) { stack[stack.length] = value|0; }; /** * @param stack * @param index */ actionscript3.prototype.actionpushdouble = function (stack, index) { var data = this.data; var double = data.double; var value = double[index]; stack[stack.length] = +value; }; /** * @param stack */ actionscript3.prototype.actionpushfalse = function (stack) { stack[stack.length] = false; }; /** * @param stack * @param index */ actionscript3.prototype.actionpushint = function (stack, index) { var data = this.data; var integer = data.integer; var value = integer[index]; stack[stack.length] = +value; }; /** * @param stack * @param index */ actionscript3.prototype.actionpushnamespace = function (stack, index) { var data = this.data; var names = data.names; var value = names[index]; stack[stack.length] = +value; }; /** * @param stack */ actionscript3.prototype.actionpushnan = function (stack) { stack[stack.length] = nan; }; /** * @param stack */ actionscript3.prototype.actionpushnull = function (stack) { stack[stack.length] = null; }; /** * @param stack */ actionscript3.prototype.actionpushscope = function (stack) { var scope = stack.pop(); if (scope) { var scopestack = this.scopestack; scopestack[scopestack.length] = scope; } }; /** * @param stack * @param value */ actionscript3.prototype.actionpushshort = function (stack, value) { stack[stack.length] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actionpushstring = function (stack, index) { var data = this.data; var string = data.string; stack[stack.length] = ""+string[index]; }; /** * @param stack */ actionscript3.prototype.actionpushtrue = function (stack) { stack[stack.length] = true; }; /** * @param stack * @param index */ actionscript3.prototype.actionpushuint = function (stack, index) { var data = this.data; var uinteger = data.uinteger; stack[stack.length] = uinteger[index]; }; /** * @param stack */ actionscript3.prototype.actionpushundefined = function (stack) { stack[stack.length] = undefined; }; /** * @param stack */ actionscript3.prototype.actionpushwith = function (stack) { var obj = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionrshift = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 >> value2; }; /** * @param stack * @param index */ actionscript3.prototype.actionsetlocal = function (stack, index) { this.register[index] = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionsetlocal0 = function (stack) { this.register[0] = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionsetlocal1 = function (stack) { this.register[1] = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionsetlocal2 = function (stack) { this.register[2] = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionsetlocal3 = function (stack) { this.register[3] = stack.pop(); }; /** * @param stack * @param index */ actionscript3.prototype.actionsetglobalslot = function (stack, index) { var value = stack.pop(); }; /** * @param stack * @param index */ actionscript3.prototype.actionsetproperty = function (stack, index) { var _this = this; var value = stack.pop(); var prop = _this.names[index]; var obj = stack.pop(); if (obj) { if (obj instanceof displayobject) { if (prop in _this.methods) { obj[prop] = value; } else { console.log("actionsetproperty", prop); } } else if (prop in obj) { obj[prop] = value; } else { var builder = _this.getbuilder(); var caller = _this.caller; if (caller instanceof movieclip) { builder = caller; } if (builder instanceof displayobject) { if (prop in _this.methods) { builder[prop] = value; } else { obj[prop] = value; } } } } }; /** * @param stack * @param index */ actionscript3.prototype.actionsetslot = function (stack, index) { var value = stack.pop(); var obj = stack.pop(); var name = obj[index]; this.activation[name] = value; }; /** * @param stack * @param index */ actionscript3.prototype.actionsetsuper = function (stack, index) { var value = stack.pop(); var prop = this.names[index]; var obj = stack.pop(); }; /** * @param stack */ actionscript3.prototype.actionstrictequals = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = (value1 === value2); }; /** * @param stack */ actionscript3.prototype.actionsubtract = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value1 - value2; }; /** * @param stack */ actionscript3.prototype.actionsubtracti = function (stack) { var value2 = +stack.pop(); var value1 = +stack.pop(); stack[stack.length] = value1 - value2; }; /** * @param stack */ actionscript3.prototype.actionswap = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value2; stack[stack.length] = value1; }; /** * @param stack */ actionscript3.prototype.actionthrow = function (stack) { var value = stack.pop(); console.log(value); }; /** * @param stack */ actionscript3.prototype.actiontypeof = function (stack) { var value = stack.pop(); stack[stack.length] = typeof value; }; /** * @param stack */ actionscript3.prototype.actionurshift = function (stack) { var value2 = stack.pop(); var value1 = stack.pop(); stack[stack.length] = value2 >> value1; }; /** * @param data * @param constantpool * @param register * @param initaction * @constructor */ var actionscript = function (data, constantpool, register, initaction) { var _this = this; _this.cache = []; _this.params = []; _this.constantpool = constantpool || []; _this.register = register || []; _this.variables = {}; _this.initaction = (initaction) ? true : false; _this.scope = null; _this.parent = null; _this.arg = null; _this.version = 7; _this.superclass = null; if (data.length) { _this.initialize(data); } _this.initparam(); }; /** * reset */ actionscript.prototype.reset = function () { var _this = this; _this.arg = null; _this.variables = {}; _this.initparam(); }; /** * initparam */ actionscript.prototype.initparam = function () { var _this = this; var register = _this.register; var length = register.length; var params = []; for (var i = 0; i < length; i++) { var obj = register[i]; if (obj.name === null) { params[obj.register] = obj.value; } else { params[obj.register] = obj.name; } } _this.params = params; }; /** * @param values */ actionscript.prototype.initvariable = function (values) { var _this = this; _this.arg = values; var register = _this.register; var length = register.length; var variables = _this.variables; var key = 0; for (var i = 0; i < length; i++) { var obj = register[i]; if (obj.name === null) { continue; } variables[obj.name] = values[key++]; } _this.variables = variables; _this.initparam(); }; /** * @returns {{}} */ actionscript.prototype.getsuperclass = function () { var _this = this; var superclass = _this.superclass; if (!superclass) { var parent = _this.parent; if (parent) { superclass = parent.getsuperclass(); } } return superclass; }; /** * @param name * @param value */ actionscript.prototype.setvariable = function (name, value) { var _this = this; var finish = false; if (name in _this.variables) { _this.variables[name] = value; finish = true; } if (!finish) { var parent = _this.parent; if (parent) { finish = parent.setvariable(name, value); } } return finish; }; /** * @param name * @returns {*} */ actionscript.prototype.getvariable = function (name) { var _this = this; var value, parent; switch (name) { case "this": value = _this.variables["this"]; break; case "arguments": value = _this.arg; break; default: value = _this.variables[name]; if (value === undefined) { parent = _this.parent; if (parent) { value = parent.getvariable(name); } } break; } return value; }; /** * @param value * @returns {string} */ actionscript.prototype.valuetostring = function (value) { if (typeof value !== "string") { value += ""; } return value; }; /** * @param str * @param mc * @returns {*} */ actionscript.prototype.stringtoobject = function(str, mc) { var object = this.getvariable(str); if (object === undefined) { object = mc.getproperty(str); } return object; }; /** * @param data */ actionscript.prototype.initialize = function (data) { var _this = this; var isend = false; var obj = {}; var i = 0; var idx = 0; var cache = []; var indexes = []; var asdata; var register; var values; var numparams; var payloadlength; var withendpoint = 0; var bitio = new bitio(); bitio.setdata(data); var pbitio = new bitio(); var endpoint = data.length; _this.initparam(); while (bitio.byte_offset < endpoint) { var startoffset = bitio.byte_offset; obj = {}; if (withendpoint && withendpoint === bitio.byte_offset) { withendpoint = 0; obj.actioncode = 0x94; obj.size = 0; cache[cache.length] = obj; continue; } var actioncode = bitio.getui8(); obj.actioncode = actioncode; var payload = null; if (actioncode >= 0x80) { payloadlength = bitio.getui16(); payload = bitio.getdata(payloadlength); pbitio.setdata(payload); pbitio.setoffset(0, 0); } switch (actioncode) { // gotoframe case 0x81: obj.frame = (pbitio.getui16()|0) + 1; break; // waitforframe case 0x8a: obj.frame = pbitio.getui16(); obj.skipcount = pbitio.getui8(); break; // settarget case 0x8b: obj.targetname = pbitio.getdatauntil("\0"); break; // gotolabel case 0x8c: obj.label = pbitio.getdatauntil("\0"); break; case 0x83: var len = payload.length - 1; var urls = [[]]; idx = 0; for (i = 0; i < len; i++) { var str = _fromcharcode(payload[i]); if (payload[i] === 0) { idx++; urls[idx] = []; continue; } urls[idx] += str; } var urlstring = urls[0]; if (typeof urlstring === "string") { var spliturl = urlstring.split("?"); if (2 in spliturl) { urlstring = spliturl[0]; urlstring += "?" + spliturl[1]; var paramlength = spliturl.length; for (i = 2; i < paramlength; i++) { urlstring += "&" + spliturl[i]; } } } obj.url = urlstring; obj.target = urls[1]; break; // push case 0x96: values = []; while (pbitio.byte_offset < payloadlength) { var type = pbitio.getui8(); switch (type) { case 0: // string values[values.length] = string(pbitio.getdatauntil("\0")); break; case 1: // float values[values.length] = pbitio.getfloat32(); break; case 2: // null values[values.length] = null; break; case 3: // undefined values[values.length] = undefined; break; case 4: // registernumber values[values.length] = {"key": pbitio.getui8()}; break; case 5: // boolean values[values.length] = (pbitio.getui8()) ? true : false; break; case 6: // double values[values.length] = pbitio.getfloat64(); break; case 7: // integer values[values.length] = pbitio.getui32(); break; case 8: // constant8 values[values.length] = _this.constantpool[pbitio.getui8()]; break; case 9: // constant16 values[values.length] = _this.constantpool[pbitio.getui16()]; break; default: break; } } obj.values = values; break; // if case 0x9d: obj.offset = bitio.byte_offset + bitio.tosi16le(payload); break; // jump case 0x99: obj.offset = bitio.byte_offset + bitio.tosi16le(payload); break; // geturl2 case 0x9a: obj.loadvariablesflag = pbitio.getuibits(1); // 0=none, 1=loadvariables obj.loadtargetflag = pbitio.getuibits(1);// 0=web, 1=sprite pbitio.getuibits(4); // reserved obj.sendvarsmethod = pbitio.getuibits(2);// 0=none, 1=get, 2=post break; // gotoframe2 case 0x9f: pbitio.getuibits(6); // reserved obj.scenebiasflag = pbitio.getuibit(); obj.playflag = pbitio.getuibit();// 0=stop, 1=play if (obj.scenebiasflag === 1) { obj.scenebias = pbitio.getui16(); } break; // waitforframe2 case 0x8d: obj.skipcount = pbitio.getui8(); break; // constantpool case 0x88: var count = pbitio.getui16(); var constantpool = []; if (count > 0) { while (count--) { constantpool[constantpool.length] = pbitio.getdatauntil("\0"); } } obj.constantpool = constantpool; _this.constantpool = constantpool; break; // actiondefinefunction case 0x9b: obj.functionname = pbitio.getdatauntil("\0"); numparams = pbitio.getui16(); register = []; if (numparams > 0) { idx = 1; while (numparams--) { register[register.length] = { register: idx, name: pbitio.getdatauntil("\0"), value: null }; } } asdata = bitio.getdata(pbitio.getui16()); obj.actionscript = new actionscript(asdata, _this.constantpool, register, _this.initaction); break; // actionwith case 0x94: obj.size = pbitio.getui16(); withendpoint = obj.size + bitio.byte_offset; break; // actionstoreregister case 0x87: obj.registernumber = pbitio.getui8(); break; // swf 7 *********************************** // actiondefinefunction2 case 0x8e: register = []; values = []; obj.functionname = pbitio.getdatauntil("\0"); numparams = pbitio.getui16(); var registercount = pbitio.getui8(); obj.preloadparentflag = pbitio.getuibits(1); obj.preloadrootflag = pbitio.getuibits(1); obj.suppresssuperflag = pbitio.getuibits(1); obj.preloadsuperflag = pbitio.getuibits(1); obj.suppressargumentsflag = pbitio.getuibits(1); obj.preloadargumentsflag = pbitio.getuibits(1); obj.suppressthisflag = pbitio.getuibits(1); obj.preloadthisflag = pbitio.getuibits(1); pbitio.getuibits(7); // reserved obj.preloadglobalflag = pbitio.getuibits(1); if (obj.preloadthisflag) { values[values.length] = "this"; } if (obj.preloadargumentsflag) { values[values.length] = "arguments"; } if (obj.preloadsuperflag) { values[values.length] = "super"; } if (obj.preloadrootflag) { values[values.length] = "_root"; } if (obj.preloadparentflag) { values[values.length] = "_parent"; } if (obj.preloadglobalflag) { values[values.length] = "_global"; } for (idx = 1; idx < registercount; idx++) { var ridx = idx - 1; if (!(ridx in values)) { continue; } register[register.length] = { register: idx, name: null, value: values[ridx] }; } if (numparams > 0) { while (numparams--) { var register = pbitio.getui8(); var paramname = pbitio.getdatauntil("\0"); register[register.length] = { register: register, name: paramname, value: null }; } } asdata = bitio.getdata(pbitio.getui16()); obj.actionscript = new actionscript(asdata, _this.constantpool, register, _this.initaction); break; // actiontry case 0x8f: pbitio.getuibits(5); // reserved var catchinregisterflag = pbitio.getuibits(1); obj.finallyblockflag = pbitio.getuibits(1); obj.catchblockflag = pbitio.getuibits(1); var trysize = pbitio.getui16(); var catchsize = pbitio.getui16(); var finallysize = pbitio.getui16(); var catchname; if (!catchinregisterflag) { catchname = pbitio.getdatauntil("\0"); } else { catchname = pbitio.getui8(); } i = 0; var trybody = []; if (trysize) { while (trysize) { trybody[trybody.length] = bitio.getui8(); trysize--; } } obj.try = (function (data) { var as = new actionscript(data); return function () { as.reset(); as.variables["this"] = this; return as.execute(this); }; })(trybody); if (obj.catchblockflag) { var catchbody = []; if (catchsize) { while (catchsize) { catchbody[catchbody.length] = bitio.getui8(); catchsize--; } } obj.catch = (function (data, catchname) { var as = new actionscript(data); return function () { as.reset(); as.variables["this"] = this; as.variables[catchname] = arguments[0]; return as.execute(this); }; })(catchbody, catchname); } if (obj.finallyblockflag) { var finallybody = []; if (finallysize) { while (finallysize) { finallybody[finallybody.length] = bitio.getui8(); finallysize--; } } obj.finally = (function (data) { var as = new actionscript(data); return function () { as.reset(); as.variables["this"] = this; return as.execute(this); }; })(finallybody); } break; case 0x00: isend = true; break; } indexes[startoffset] = cache.length; cache[cache.length] = obj; if (isend) { break; } } // if and jump var length = cache.length; for (i = 0; i < length; i++) { obj = cache[i]; var code = obj.actioncode; if (code === 0x9d || code === 0x99) { var index = indexes[obj.offset]; if (index !== undefined) { obj.offset = index - 1; } else { obj.offset = cache.length - 1; } } } _this.cache = cache; }; /** * @param value * @returns {*} */ actionscript.prototype.calc = function (value) { var calc; switch (typeof value) { case "boolean": calc = (value) ? 1 : 0; break; case "object": if (value === null) { calc = 0; } else if (value instanceof array) { calc = value.length; } else if (value instanceof object) { calc = 1; } break; default: calc = +value; break; } if (_isnan(calc)) { calc = 0; } return calc; }; /** * @param value * @returns {*} */ actionscript.prototype.logicvalue = function (value) { var calc; switch (typeof value) { case "boolean": calc = (value) ? 1 : 0; break; case "object": if (value === null) { calc = 0; } else if (value instanceof array) { calc = value.length; } else if (value instanceof object) { calc = 1; } break; case "string": if (value === "") { calc = 0; } else { calc = 1; } break; case "function": calc = 1; break; default: calc = +value; if (_isnan(calc)) { calc = 0; } break; } return calc; }; /** * @param stack * @returns {number} */ actionscript.prototype.operationvalue = function (stack) { var value = +stack.pop(); if (_isnan(value)) { value = 0; } return value; }; /** * @param mc * @returns {*} */ actionscript.prototype.execute = function (mc) { var _this = this; var scope = _this.scope; var movieclip = (scope instanceof movieclip) ? scope : mc; if (!movieclip.active) { return undefined; } var stage = movieclip.getstage(); if (stage) { _this.version = stage.getversion(); } var stack = []; var cache = _this.cache; var clength = cache.length; var cidx = 0; while(cidx < clength) { if (!(cidx in cache)) { cidx++; continue; } var ascript = cache[cidx]; var actioncode = ascript.actioncode; if (actioncode === 0) { break; } switch (actioncode) { // ******************************************** // swf 3 // ******************************************** case 0x81: _this.actiongotoframe(movieclip, ascript.frame); break; case 0x04: _this.actionnextframe(movieclip); break; case 0x05: _this.actionpreviousframe(movieclip); break; case 0x06: _this.actionplay(movieclip); break; case 0x07: _this.actionstop(movieclip); break; case 0x08: // actiontogglequality case 0x8a: // actionwaitforframe break; case 0x09: _this.actionstopsounds(movieclip); break; case 0x8b: movieclip = _this.actionsettarget(movieclip, mc, ascript.targetname); break; case 0x8c: _this.actiongotolabel(movieclip, ascript.label); break; case 0x83: _this.actiongeturl(movieclip, ascript.url, ascript.target); break; // ******************************************** // swf 4 // ******************************************** case 0x0a: // actionadd _this.actionoperation(stack, 0); break; case 0x0b: // actionsubtract _this.actionoperation(stack, 1); break; case 0x0c: // actionmultiply _this.actionoperation(stack, 2); break; case 0x0d: // actiondivide _this.actionoperation(stack, 3); break; case 0x0e: _this.actionequals(stack); break; case 0x0f: _this.actionless(stack); break; case 0x10: _this.actionand(stack); break; case 0x11: _this.actionor(stack); break; case 0x12: _this.actionnot(stack); break; case 0x13: _this.actionstringequals(stack); break; case 0x14: // actionstringlength case 0x31: // actionmbstringlength _this.actionstringlength(stack); break; case 0x21: _this.actionstringadd(stack); break; case 0x15:// actionstringextract case 0x35:// actionmbstringextract _this.actionstringextract(stack); break; case 0x29: _this.actionstringless(stack); break; case 0x17: // actionpop stack.pop(); break; case 0x96: _this.actionpush(stack, movieclip, ascript.values); break; case 0x33: // actionasciitochar case 0x37: // actionmbasciitochar _this.actionasciitochar(stack); break; case 0x36: // actionmbchartoascii case 0x32: // actionchartoascii _this.actionchartoascii(stack); break; case 0x18: _this.actiontointeger(stack); break; case 0x9e: _this.actioncall(stack, movieclip); break; case 0x9d: cidx = _this.actionif(stack, ascript.offset, cidx); break; case 0x99: // actionjump cidx = ascript.offset; break; case 0x1c: _this.actiongetvariable(stack, movieclip); break; case 0x1d: _this.actionsetvariable(stack, movieclip); break; case 0x9a: _this.actiongeturl2(stack, ascript, movieclip); break; case 0x22: _this.actiongetproperty(stack, movieclip); break; case 0x9f: _this.actiongotoframe2(stack, ascript, movieclip); break; case 0x20: movieclip = _this.actionsettarget2(stack, movieclip, mc); break; case 0x23: _this.actionsetproperty(stack, movieclip); break; case 0x27: _this.actionstartdrag(stack, movieclip); break; case 0x8d: // actionwaitforframe2 stack.pop(); break; case 0x24: _this.actionclonesprite(stack, movieclip); break; case 0x25: _this.actionremovesprite(stack, movieclip); break; case 0x28: _this.actionenddrag(movieclip); break; case 0x34: _this.actiongettime(stack); break; case 0x30: _this.actionrandomnumber(stack); break; case 0x26: _this.actiontrace(stack); break; case 0x00: break; case 0x2d: _this.actionfscommand2(stack, movieclip); break; // ******************************************** // swf 5 // ******************************************** case 0x52: _this.actioncallmethod(stack, movieclip); break; case 0x88: // actionconstantpool _this.constantpool = ascript.constantpool; break; case 0x3d: _this.actioncallfunction(stack, movieclip); break; case 0x9b: _this.actiondefinefunction(stack, ascript, movieclip); break; case 0x3c: _this.actiondefinelocal(stack, movieclip); break; case 0x41: _this.actiondefinelocal2(stack, movieclip); break; case 0x3a: _this.actiondelete(stack, movieclip); break; case 0x3b: _this.actiondelete2(stack, movieclip); break; case 0x46: _this.actionenumerate(stack, movieclip); break; case 0x49: _this.actionequals2(stack); break; case 0x4e: _this.actiongetmember(stack, movieclip); break; case 0x42: _this.actioninitarray(stack); break; case 0x43: _this.actioninitobject(stack); break; case 0x53: _this.actionnewmethod(stack, movieclip); break; case 0x40: _this.actionnewobject(stack, movieclip); break; case 0x4f: _this.actionsetmember(stack, movieclip); break; case 0x45: _this.actiontargetpath(stack); break; case 0x94: movieclip = _this.actionwith(stack, ascript.size, mc); break; case 0x4a: _this.actiontonumber(stack); break; case 0x4b: _this.actiontostring(stack); break; case 0x44: _this.actiontypeof(stack); break; case 0x47: _this.actionadd2(stack); break; case 0x48: _this.actionless2(stack); break; case 0x3f: _this.actionmodulo(stack); break; case 0x60: _this.actionbitand(stack); break; case 0x63: _this.actionbitlshift(stack); break; case 0x61: _this.actionbitor(stack); break; case 0x64: _this.actionbitrshift(stack); break; case 0x65: _this.actionbiturshift(stack); break; case 0x62: _this.actionbitxor(stack); break; case 0x51: _this.actiondecrement(stack); break; case 0x50: _this.actionincrement(stack); break; case 0x4c: _this.actionpushduplicate(stack); break; case 0x3e: // actionreturn return stack.pop(); case 0x4d: _this.actionstackswap(stack); break; case 0x87: _this.actionstoreregister(stack, ascript.registernumber); break; // ******************************************** // swf 6 // ******************************************** case 0x54: _this.actioninstanceof(stack); break; case 0x55: _this.actionenumerate(stack, movieclip); break; case 0x66: _this.actionstrictequals(stack); break; case 0x67: // actiongreater case 0x68: // actionstringgreater _this.actiongreater(stack); break; // ******************************************** // swf 7 // ******************************************** case 0x8e: // actiondefinefunction2 _this.actiondefinefunction(stack, ascript, movieclip); break; case 0x69: _this.actionextends(stack); break; case 0x2b: _this.actioncastop(stack); break; case 0x2c: _this.actionimplementsop(stack); break; case 0x8f: _this.actiontry(ascript, movieclip); break; case 0x2a: _this.actionthrow(stack); break; default: console.log("[actionscript error] code: " + actioncode); break; } cidx++; } }; /** * @type {{}} */ actionscript.prototype.methods = { gotoandstop: "gotoandstop", gotoandplay: "gotoandplay", play: "play", stop: "stop", duplicatemovieclip: "duplicatemovieclip", getproperty: "getproperty", removemovieclip: "removemovieclip", setproperty: "setproperty", startdrag: "startdrag", stopdrag: "stopdrag", targetpath: "targetpath", updateafterevent: "updateafterevent", nextframe: "nextframe", nextscene: "nextscene", prevframe: "prevframe", prevscene: "prevscene", stopallsounds: "stopallsounds", setmask: "setmask", geturl: "geturl", loadmovie: "loadmovie", loadmovienum: "loadmovienum", loadvariables: "loadvariables", loadvariablesnum: "loadvariablesnum", unloadmovie: "unloadmovie", unloadmovienum: "unloadmovienum", swapdepths: "swapdepths", getinstanceatdepth: "getinstanceatdepth", attachmovie: "attachmovie", attachaudio: "attachaudio", attachbitmap: "attachbitmap", getnexthighestdepth: "getnexthighestdepth", getbytesloaded: "getbytesloaded", getbytestotal: "getbytestotal", assetpropflags: "assetpropflags", linestyle: "linestyle", linegradientstyle: "linegradientstyle", beginfill: "beginfill", begingradientfill: "begingradientfill", beginbitmapfill: "beginbitmapfill", clear: "clear", moveto: "moveto", lineto: "lineto", curveto: "curveto", endfill: "endfill", hittest: "hittest", getdepth: "getdepth", createemptymovieclip: "createemptymovieclip", createtextfield: "createtextfield", getbounds: "getbounds", getrect: "getrect", getswfversion: "getswfversion", gettextsnapshot: "gettextsnapshot", globaltolocal: "globaltolocal", localtoglobal: "localtoglobal" }; /** * @param method * @returns {*} */ actionscript.prototype.checkmethod = function (method) { if (!method || typeof method !== "string") { return method; } var lowermethod = method.tolowercase(); return this.methods[lowermethod] || null; }; /** * @param mc * @param frame */ actionscript.prototype.actiongotoframe = function (mc, frame) { if (mc instanceof movieclip) { mc.stop(); mc.setnextframe(frame); } }; /** * @param mc */ actionscript.prototype.actionnextframe = function (mc) { if (mc instanceof movieclip) { mc.nextframe(); } }; /** * @param mc */ actionscript.prototype.actionpreviousframe = function (mc) { if (mc instanceof movieclip) { mc.prevframe(); } }; /** * @param mc */ actionscript.prototype.actionplay = function (mc) { if (mc instanceof movieclip) { mc.play(); } }; /** * @param mc */ actionscript.prototype.actionstop = function (mc) { if (mc instanceof movieclip) { mc.stop(); } }; /** * @param mc */ actionscript.prototype.actionstopsounds = function (mc) { if (mc instanceof movieclip) { mc.stopallsounds(); } }; /** * @param movieclip * @param mc * @param target * @returns {*} */ actionscript.prototype.actionsettarget = function (movieclip, mc, target) { if (target !== "") { var targetmc = movieclip; if (!targetmc) { targetmc = mc; } return targetmc.getdisplayobject(target); } else { if (mc.active) { return mc; } else { return undefined; } } }; /** * @param mc * @param label */ actionscript.prototype.actiongotolabel = function (mc, label) { if (mc instanceof movieclip) { var frame = mc.getlabel(label); mc.stop(); if (typeof frame === "number" && frame) { mc.setnextframe(frame); } } }; /** * @param mc * @param url * @param target */ actionscript.prototype.actiongeturl = function (mc, url, target) { if (mc instanceof movieclip) { mc.geturl(url, target); } }; /** * @param stack * @param operation */ actionscript.prototype.actionoperation = function (stack, operation) { var _this = this; var a = _this.operationvalue(stack); var b = _this.operationvalue(stack); var value; switch (operation) { case 0: value = b + a; break; case 1: value = b - a; break; case 2: value = b * a; break; case 3: value = b / a; break; } stack[stack.length] = value; }; /** * @param stack */ actionscript.prototype.actionequals = function (stack) { var _this = this; var a = _this.calc(stack.pop()); var b = _this.calc(stack.pop()); if (_this.version > 4) { stack[stack.length] = (a === b); } else { stack[stack.length] = (a === b) ? 1 : 0; } }; /** * @param stack */ actionscript.prototype.actionless = function (stack) { var _this = this; var a = _this.calc(stack.pop()); var b = _this.calc(stack.pop()); if (_this.version > 4) { stack[stack.length] = (b < a); } else { stack[stack.length] = (b < a) ? 1 : 0; } }; /** * @param stack */ actionscript.prototype.actionand = function (stack) { var _this = this; var a = stack.pop(); var b = stack.pop(); if (_this.version > 4) { a = _this.logicvalue(a); b = _this.logicvalue(b); stack[stack.length] = (a !== 0 && b !== 0); } else { a = _this.calc(a); b = _this.calc(b); stack[stack.length] = (a !== 0 && b !== 0) ? 1 : 0; } }; /** * @param stack */ actionscript.prototype.actionor = function (stack) { var _this = this; var a = stack.pop(); var b = stack.pop(); if (_this.version > 4) { a = _this.logicvalue(a); b = _this.logicvalue(b); stack[stack.length] = (a !== 0 || b !== 0); } else { a = _this.calc(a); b = _this.calc(b); stack[stack.length] = (a !== 0 || b !== 0) ? 1 : 0; } }; /** * @param stack */ actionscript.prototype.actionnot = function (stack) { var _this = this; var a = stack.pop(); if (_this.version > 4) { a = _this.logicvalue(a); stack[stack.length] = (a === 0); } else { a = _this.calc(a); stack[stack.length] = (a === 0) ? 1 : 0; } }; /** * @param stack */ actionscript.prototype.actionstringequals = function (stack) { var a = stack.pop(); var b = stack.pop(); if (a instanceof movieclip) { a = a.gettarget(); } else { a += ""; } if (b instanceof movieclip) { b = b.gettarget(); } else { b += ""; } if (this.version > 4) { stack[stack.length] = (b === a); } else { stack[stack.length] = (b === a) ? 1 : 0; } }; /** * @param stack */ actionscript.prototype.actionstringlength = function (stack) { var value = stack.pop(); value = this.valuetostring(value); var length = 0; var slen = value.length; for (var i = 0; i < slen; i++, length++) { var code = value.charcodeat(i); if (code < 255) { continue; } length++; } stack[stack.length] = length; }; /** * @param stack */ actionscript.prototype.actionstringadd = function (stack) { var a = stack.pop(); var b = stack.pop(); if (a === null || a === undefined) { a = ""; } if (b === null || b === undefined) { b = ""; } stack[stack.length] = b + "" + a; }; /** * @param stack */ actionscript.prototype.actionstringextract = function (stack) { var count = stack.pop(); var index = stack.pop(); var string = stack.pop(); string = this.valuetostring(string); index--; if (index < 0) { index = 0; } stack[stack.length] = (count < 0) ? string.substr(index) : string.substr(index, count); }; /** * @param stack */ actionscript.prototype.actionstringless = function (stack) { var a = stack.pop(); var b = stack.pop(); if (this.version > 4) { stack[stack.length] = (b < a); } else { stack[stack.length] = (b < a) ? 1 : 0; } }; /** * @param stack * @param mc * @param values */ actionscript.prototype.actionpush = function (stack, mc, values) { var _this = this; var length = values.length; var params = _this.params; for (var i = 0; i < length; i++) { var value = values[i]; if (value instanceof object) { var key = value.key; value = undefined; if (key in params) { var name = params[key]; if (typeof name === "string") { value = _this.getvariable(name); if (value === undefined && !(name in _this.variables)) { value = name; } } else { value = name; } } } stack[stack.length] = value; } }; /** * @param stack */ actionscript.prototype.actionasciitochar = function (stack) { var value = stack.pop(); stack[stack.length] = _fromcharcode(value); }; /** * @param stack */ actionscript.prototype.actionchartoascii = function (stack) { var value = stack.pop(); value = this.valuetostring(value); stack[stack.length] = value.charcodeat(0); }; /** * @param stack */ actionscript.prototype.actiontointeger = function (stack) { var value = stack.pop(); stack[stack.length] = value|0; }; /** * @param stack * @param mc */ actionscript.prototype.actioncall = function (stack, mc) { var value = stack.pop(); if (mc) { value = this.valuetostring(value); var splitdata = value.split(":"); var frame; var label = splitdata[0]; var targetmc = mc; if (splitdata.length > 1) { targetmc = mc.getdisplayobject(splitdata[0]); label = splitdata[1]; } if (targetmc instanceof movieclip) { frame = (typeof label === "number") ? label : targetmc.getlabel(label); targetmc.executeactions(frame); } } }; /** * @param stack * @param offset * @param index * @returns {*} */ actionscript.prototype.actionif = function (stack, offset, index) { var condition = stack.pop(); switch (typeof condition) { case "boolean": break; case "string": if (!_isnan(condition)) { condition = +condition; } break; } if (condition) { return offset; } return index; }; /** * @param stack * @param mc * @returns {undefined} */ actionscript.prototype.actiongetvariable = function (stack, mc) { var _this = this; var name = stack.pop(); var value; if (name instanceof movieclip) { value = name; } else { value = _this.getnativeclass(name); if (value === undefined) { value = _this.getvariable(name); if (value === undefined && mc) { value = mc.getproperty(name); } } } stack[stack.length] = value; }; /** * @param stack * @param mc */ actionscript.prototype.actionsetvariable = function (stack, mc) { var value = stack.pop(); var name = stack.pop(); if (!this.setvariable(name, value)) { mc.setproperty(name, value); } }; /** * @param stack * @param ascript * @param mc */ actionscript.prototype.actiongeturl2 = function (stack, ascript, mc) { var target = stack.pop(); var value = stack.pop(); var loadvariablesflag = ascript.loadvariablesflag; // 0=none, 1=loadvariables var loadtargetflag = ascript.loadtargetflag; // 0=web, 1=sprite var sendvarsmethod = ascript.sendvarsmethod; // 0=none, 1=get, 2=post var method = "get"; if (sendvarsmethod === 2) { method = "post"; } var url; if (mc instanceof movieclip) { if (value) { value = this.valuetostring(value); var urls = value.split("?"); var ulen = urls.length; var query = ""; if (ulen === 1) { query = "?"; } if (ulen > 2) { url = urls[0] + "?"; url = url + urls[1]; for (var u = 2; u < ulen; u++) { var params = urls[u]; url = url + "&" + params; } } else { url = value; } // local variables if (sendvarsmethod) { var variables = mc.variables; var querystring = ""; for (var key in variables) { if (!variables.hasownproperty(key)) { continue; } var val = variables[key]; if (val === null) { val = ""; } if (typeof val !== "string") { var typetext = typeof val; typetext = typetext.replace(/^[a-z]/g, function (str) { return str.touppercase(); }); val = "%5btype+" + typetext + "%5d"; } querystring += "&" + key + "=" + val; } if (query !== "" && querystring !== "") { querystring = query + querystring.slice(1); } url += querystring; } if (loadvariablesflag) { mc.loadvariables(url, target, method); } else if (loadtargetflag) { if (target instanceof movieclip) { target.loadmovie(url, null, sendvarsmethod); } else { mc.loadmovie(url, target, sendvarsmethod); } } else { mc.geturl(url, target, method); } } else { mc.unloadmovie(target); } } }; /** * @param stack * @param mc * @returns {*} */ actionscript.prototype.actiongetproperty = function (stack, mc) { var index = stack.pop(); var target = stack.pop(); if (!_isnan(index)) { index = _floor(index); } var _this = this; var value = _this.getvariable(index); if (value === undefined && mc) { var targetmc = mc; if (target) { if (typeof target !== "string") { target += ""; } targetmc = mc.getdisplayobject(target); } if (targetmc instanceof movieclip) { value = targetmc.getproperty(index); } } stack[stack.length] = value; }; /** * @param stack * @param ascript * @param mc */ actionscript.prototype.actiongotoframe2 = function (stack, ascript, mc) { var scenebiasflag = ascript.scenebiasflag; var playflag = ascript.playflag; // 0=stop, 1=play if (scenebiasflag === 1) { var scenebias = ascript.scenebias; console.log("scenebias", scenebias); } var frame = stack.pop(); if (frame && mc) { if (_isnan(frame)) { var splitdata = frame.split(":"); if (splitdata.length > 1) { var targetmc = mc.getdisplayobject(splitdata[0]); if (targetmc) { frame = targetmc.getlabel(splitdata[1]); } } else { frame = mc.getlabel(splitdata[0]); } } if (typeof frame === "string") { frame |= 0; } if (typeof frame === "number" && frame > 0) { mc.setnextframe(frame); if (playflag) { mc.play(); } else { mc.stop(); } } } }; /** * @param stack * @param movieclip * @param mc * @returns {*} */ actionscript.prototype.actionsettarget2 = function (stack, movieclip, mc) { var target = stack.pop(); if (!movieclip) { movieclip = mc; } return movieclip.getdisplayobject(target); }; /** * @param stack * @param mc */ actionscript.prototype.actionsetproperty = function (stack, mc) { var value = stack.pop(); var index = stack.pop(); var target = stack.pop(); if (!_isnan(index)) { index = _floor(index); } if (mc) { var targetmc = mc; if (target !== undefined) { targetmc = mc.getdisplayobject(target); } if (targetmc instanceof movieclip) { targetmc.setproperty(index, value); } } }; /** * @param stack * @param mc */ actionscript.prototype.actionstartdrag = function (stack, mc) { var target = stack.pop(); var lock = stack.pop(); var constrain = stack.pop(); var y2 = null; var x2 = null; var y1 = null; var x1 = null; if (constrain) { y2 = stack.pop(); x2 = stack.pop(); y1 = stack.pop(); x1 = stack.pop(); } var targetmc = mc; if (target instanceof movieclip) { targetmc = target; } if (typeof target === "string" && target) { targetmc = mc.getdisplayobject(target); } if (targetmc instanceof movieclip) { targetmc.startdrag(lock, x1, y1, x2, y2); } }; /** * @param stack * @param mc */ actionscript.prototype.actionclonesprite = function (stack, mc) { var depth = +stack.pop(); var target = stack.pop(); var source = stack.pop(); if (mc) { mc.duplicatemovieclip(target, source, depth); } }; /** * @param stack * @param mc */ actionscript.prototype.actionremovesprite = function (stack, mc) { var target = stack.pop(); if (mc) { mc.removemovieclip(target); } }; /** * @param mc */ actionscript.prototype.actionenddrag = function (mc) { if (mc) { mc.stopdrag(); } }; /** * @param stack */ actionscript.prototype.actiongettime = function (stack) { var now = new date(); stack[stack.length] = now.gettime() - startdate.gettime(); }; /** * @param stack */ actionscript.prototype.actionrandomnumber = function (stack) { var maximum = stack.pop(); stack[stack.length] = _floor(_random() * maximum); }; /** * @param stack */ actionscript.prototype.actiontrace = function (stack) { var value = stack.pop(); if (value instanceof displayobject && value.removeflag) { value = ""; } if (value && typeof value === "object") { if ("callee" in value) { value = array.prototype.slice.call(value); } value = value.tostring(); } console.log("[trace] " + value); }; /** * @param stack * @param mc */ actionscript.prototype.actionfscommand2 = function (stack, mc) { stack.pop(); // count var method = stack.pop(); var now = new date(); switch (method.tolowercase()) { case "getdateyear": stack[stack.length] = now.getfullyear(); break; case "getdatemonth": stack[stack.length] = now.getmonth() + 1; break; case "getdateday": stack[stack.length] = now.getdate(); break; case "getdateweekday": stack[stack.length] = now.getday(); break; case "gettimehours": stack[stack.length] = now.gethours(); break; case "gettimeminutes": stack[stack.length] = now.getminutes(); break; case "gettimeseconds": stack[stack.length] = now.getseconds(); break; case "startvibrate": stack.pop(); stack.pop(); stack.pop(); stack[stack.length] = -1; break; case "gettimezoneoffset": mc.setvariable(stack.pop(), now.toutcstring()); mc.setvariable(stack.pop(), 0); break; case "getlocalelongdate": mc.setvariable(stack.pop(), now.tolocaledatestring()); mc.setvariable(stack.pop(), 0); break; case "getlocaleshortdate": mc.setvariable(stack.pop(), now.todatestring()); mc.setvariable(stack.pop(), 0); break; case "getlocaletime": mc.setvariable(stack.pop(), now.tolocaletimestring()); mc.setvariable(stack.pop(), 0); break; case "getnetworkname": case "getdevice": case "getdeviceid": mc.setvariable(stack.pop(), ""); mc.setvariable(stack.pop(), -1); break; case "getlanguage": var language = _navigator.userlanguage || _navigator.language || _navigator.browserlanguage || "ja-jp"; mc.setvariable(stack.pop(), language); mc.setvariable(stack.pop(), 0); break; case "setsoftkeys": stack.pop(); stack.pop(); stack[stack.length] = -1; break; case "fullscreen": stack.pop(); // bool stack[stack.length] = -1; break; case "setquality": case "getfreestagememory": case "gettotalstagememory": stack.pop(); stack[stack.length] = -1; break; default: stack[stack.length] = -1; break; } }; /** * @param stack * @param mc */ actionscript.prototype.actioncallmethod = function (stack, mc) { var _this = this; var method = stack.pop(); var object = stack.pop(); var count = +stack.pop(); var params = []; if (count > 0) { while (count) { count--; var param = stack.pop(); if (param && typeof param === "object" && "callee" in param) { param = array.prototype.slice.call(param); } params[params.length] = param; } } if (typeof object === "string" && object[method] === undefined) { var target = _this.stringtoobject(object, mc); if (target) { object = target; } if (object === "super") { var caller = _this.variables["this"]; var superclass = _this.getsuperclass(); if (!method && superclass) { var sc = new superclass(); switch (superclass) { case movieclip: var loadstage = mc.getstage(); sc.setstage(loadstage); sc.setparent(mc); sc._extend = true; break; } var proto = object.getprototypeof(caller); proto.constructor = superclass; object.setprototypeof(proto, sc); object.setprototypeof(caller, proto); } else { object = caller; } } } var value; if (object && method) { var func; if (typeof object === "object") { var variables = object.variables; if (variables) { func = variables[method]; if (!func && variables.registerclass) { func = variables.registerclass[method]; } } } if (!func) { var originmethod = _this.checkmethod(method); if (originmethod) { func = object[originmethod]; } } if (!func) { func = object[method]; } if (!func && object instanceof movieclip) { func = object.getvariable(method); } if (!func && object instanceof global) { func = window[method]; if (func) { params = _this.actionnativefunction(params, mc); object = window; } } if (method === "call" || method === "apply") { func = object; object = params.shift(); if (method === "apply") { var args = params.shift(); params = []; if (args) { params = array.prototype.slice.call(args); } } } if (func && typeof func === "function") { switch (true) { case object instanceof moviecliploader: if (method === "loadclip" && typeof params[1] === "string") { var targetstr = params[1]; params[1] = mc.getdisplayobject(targetstr); } break; } value = func.apply(object, params); } if (!func && object instanceof object && typeof method === "string") { switch (method.tolowercase()) { case "registerclass": value = false; var _root = mc.getdisplayobject("_root"); var stage = _root.getstage(); var characterid = stage.exportassets[params[0]]; if (characterid) { stage.registerclass[characterid] = params[1]; value = true; } break; case "addproperty": _this.addproperty(object, params); break; } } } else { if (!method && typeof object === "function") { value = object.apply(_this.variables["this"], params); } } stack[stack.length] = value; }; /** * @param target * @param params * @returns {boolean} */ actionscript.prototype.addproperty = function (target, params) { var property = params[0]; if (typeof property !== "string" || property === "") { return false; } var getter = params[1]; if (!getter) { getter = function () {}; } var setter = params[2]; if (!setter) { setter = function () {}; } if (typeof getter !== "function" || typeof setter !== "function") { return false; } object.defineproperty(target, property, { get: getter, set: setter }); return true; }; /** * @param args * @param mc * @returns {array} */ actionscript.prototype.actionnativefunction = function (args, mc) { var targetmc = mc; var params = args; if (args[0] instanceof movieclip) { // setinterval, settimeout targetmc = args.shift(); if (args.length > 0) { var obj = args.shift(); var as; if (typeof obj === "string") { as = this.getvariable(obj); if (typeof as !== "function") { as = targetmc.getvariable(obj); } } if (typeof as === "function") { var time = args.shift(); var action = (function (script, mc, args) { return function () { script.apply(mc, args); }; })(as, targetmc, args); params = []; params[params.length] = action; params[params.length] = time; } else { console.log("debug: ", params); args.unshift(obj); params = args; } } } return params; }; /** * @param stack * @param mc */ actionscript.prototype.actioncallfunction = function (stack, mc) { var _this = this; var name = stack.pop(); var count = +stack.pop(); var params = []; if (count > 0) { while (count) { count--; var param = stack.pop(); if (param && typeof param === "object" && "callee" in param) { param = array.prototype.slice.call(param); } params[params.length] = param; } } if (mc) { var caller = mc; var func; var method = _this.checkmethod(name); if (method) { func = mc[method]; } else { func = mc.variables[name]; if (!func) { var registerclass = mc.variables.registerclass; if (registerclass && typeof registerclass === "object") { func = registerclass[name]; } if (!func) { if (window[name]) { caller = window; params = _this.actionnativefunction(params, mc); func = window[name]; } else { func = mc.getvariable(name); } } } } stack[stack.length] = (func) ? func.apply(caller, params) : undefined; } }; /** * @param stack * @param ascript * @param mc */ actionscript.prototype.actiondefinefunction = function (stack, ascript, mc) { var action = mc.createactionscript2(ascript.actionscript, this); var name = ascript.functionname; if (name !== "") { mc.setvariable(name, action); } else { stack[stack.length] = action; } }; /** * @param stack * @param mc */ actionscript.prototype.actiondefinelocal = function (stack, mc) { var _this = this; var value = stack.pop(); var name = stack.pop(); if (_this.parent) { _this.variables[name] = value; } else { mc.setvariable(name, value); } }; /** * @param stack * @param mc */ actionscript.prototype.actiondefinelocal2 = function (stack, mc) { var _this = this; var name = stack.pop(); if (_this.parent) { _this.variables[name] = undefined; } else { mc.setvariable(name, undefined); } }; /** * @param stack * @param mc */ actionscript.prototype.actiondelete = function (stack, mc) { var name = stack.pop(); var object = stack.pop(); if (typeof object === "string") { var target = this.stringtoobject(object, mc); if (target) { object = target; } } if (object instanceof movieclip) { object.setvariable(name, undefined); } }; /** * @param stack * @param mc */ actionscript.prototype.actiondelete2 = function (stack, mc) { var name = stack.pop(); if (mc) { mc.setvariable(name, undefined); } }; /** * @param stack * @param mc */ actionscript.prototype.actionenumerate = function (stack, mc) { var object = stack.pop(); stack[stack.length] = null; if (typeof object === "string") { object = this.stringtoobject(object, mc); } if (object instanceof object) { var name; switch (true) { case object instanceof displayobject: var container = object.gettags(); var stage = object.getstage(); for (name in container) { if (!container.hasownproperty(name)) { continue; } var id = container[name]; var instance = stage.getinstance(id); var prop = "instance" + id; if (instance.getname()) { prop = instance.getname(); } stack[stack.length] = prop; } var variables = object.variables; for (name in variables) { if (!variables.hasownproperty(name)) { continue; } stack[stack.length] = name; } break; default: for (name in object) { if (!object.hasownproperty(name)) { continue; } stack[stack.length] = name; } break; } } }; /** * @param stack */ actionscript.prototype.actionequals2 = function (stack) { var a = stack.pop(); var b = stack.pop(); var a = a; var b = b; if (a instanceof movieclip) { a = a.gettarget(); } if (b instanceof movieclip) { b = b.gettarget(); } stack[stack.length] = (b == a); }; /** * @param stack * @param mc */ actionscript.prototype.actiongetmember = function (stack, mc) { var _this = this; var property; var name = stack.pop(); var object = stack.pop(); if (typeof object === "string") { var target = _this.stringtoobject(object, mc); if (target ) { object = target; } } if (object) { switch (true) { default: property = object[name]; break; case object instanceof displayobject: case object instanceof global: if (!object._extend) { property = object.getproperty(name, false); if (property === undefined && typeof name === "string" && name.substr(0, 8) === "instance" ) { var stage = object.getstage(); var id = name.split("instance")[1]; property = stage.getinstance(id); } if (property === undefined && _this.checkmethod(name)) { property = object[name]; } } else { property = object[name]; } break; case object instanceof element && name === "childnodes": var childnodes = object[name]; var length = childnodes.length; property = []; if (length) { for (var i = 0; i < length; i++) { var node = childnodes[i]; if (node.nodetype !== 1) { continue; } property[property.length] = node; } } break; case object instanceof window.namednodemap: var item = object.getnameditem(name); property = item.value; break; } } stack[stack.length] = property; }; /** * @param stack */ actionscript.prototype.actioninitarray = function (stack) { var number = stack.pop(); var array = []; if (number > 0) { while (number--) { array[array.length] = stack.pop(); } } stack[stack.length] = array; }; /** * @param stack */ actionscript.prototype.actioninitobject = function (stack) { var number = stack.pop(); var object = {}; if (number > 0) { while (number--) { var value = stack.pop(); var property = stack.pop(); object[property] = value; } } stack[stack.length] = object; }; /** * @param stack * @param mc */ actionscript.prototype.actionnewmethod = function (stack, mc) { var method = stack.pop(); var object = stack.pop(); var number = stack.pop(); var params = []; if (number > 0) { while (number--) { var param = stack.pop(); if (param && typeof param === "object" && "callee" in param) { param = array.prototype.slice.call(param); } params[params.length] = param; } } var constructor; if (method === "") { constructor = object.apply(object, params); } if (!constructor && method in object) { constructor = this.createnewactionscript(object[method], mc, params); } if (!constructor && method in window) { if (method === "cssstyledeclaration") { constructor = undefined; } else { constructor = this.createnewactionscript(window[method], mc, params); } } stack[stack.length] = constructor; }; /** * @param stack * @param mc */ actionscript.prototype.actionnewobject = function (stack, mc) { var object = stack.pop(); var numargs = +stack.pop(); var params = []; if (numargs > 0) { while (numargs) { numargs--; var param = stack.pop(); if (param && typeof param === "object" && "callee" in param) { param = array.prototype.slice.call(param); } params[params.length] = param; } } var obj = {}; if (object in window) { params.unshift(window[object]); obj = new (function.prototype.bind.apply(window[object], params))(); } else { switch (object) { case "object": obj = {}; break; case "movieclip": obj = new movieclip(); var stage = mc.getstage(); obj.setstage(stage); obj.setparent(mc); break; case "sound": obj = new sound(mc); obj.movieclip = mc; break; case "xml": obj = new xml(); break; case "loadvars": obj = new loadvars(); break; case "color": obj = new color(params[0]); break; case "textformat": obj = new textformat(); break; case "moviecliploader": obj = new moviecliploader(); break; default: if (mc) { var _this = this; var func = _this.getvariable(object) || mc.getvariable(object); obj = _this.createnewactionscript(func, mc, params); } break; } } stack[stack.length] = obj; }; /** * @param name * @returns {*} */ actionscript.prototype.getnativeclass = function (name) { var value; switch (name) { case "movieclip": value = movieclip; break; case "sprite": value = sprite; break; case "simplebutton": value = simplebutton; break; case "textfield": value = textfield; break; case "shape": value = shape; break; case "sound": value = sound; break; case "xml": value = xml; break; case "loadvars": value = loadvars; break; case "color": value = color; break; case "textformat": value = textformat; break; case "moviecliploader": value = moviecliploader; break; } return value; }; /** * @param constr * @param mc * @param params * @returns {*} */ actionscript.prototype.createnewactionscript = function (constr, mc, params) { if (constr) { params.unshift(constr); return new (function.prototype.bind.apply(constr, params))(); } return undefined; }; /** * @param stack * @param mc */ actionscript.prototype.actionsetmember = function (stack, mc) { var value = stack.pop(); var name = stack.pop(); var object = stack.pop(); if (object) { if (typeof object === "string") { var target = this.stringtoobject(object, mc); if (target) { object = target; } } if (typeof object === "object" || typeof object === "function") { switch (true) { default: case object === movieclip.prototype: case object === textfield.prototype: case object === simplebutton.prototype: case object === sprite.prototype: case object === shape.prototype: object[name] = value; break; case object instanceof displayobject: case object instanceof global: if (!object._extend) { object.setproperty(name, value, false); } else { object[name] = value; } break; } } } }; /** * @param stack */ actionscript.prototype.actiontargetpath = function (stack) { console.log("actiontargetpath"); var object = stack.pop(); var path = null; if (object instanceof movieclip) { path = object.getname(); if (path !== null) { while (true) { var parent = object.getparent(); if (parent === null) { path = "/" + path; break; } var name = parent.getname(); if (name === null) { path = null; break; } path = name + "/" + path; } } } stack[stack.length] = path; }; /** * @param stack * @param size * @param mc * @returns {*} */ actionscript.prototype.actionwith = function (stack, size, mc) { var object = mc; if (size) { object = stack.pop(); } return object; }; /** * @param stack */ actionscript.prototype.actiontonumber = function (stack) { var object = +stack.pop(); stack[stack.length] = object; }; /** * @param stack */ actionscript.prototype.actiontostring = function (stack) { var object = stack.pop(); stack[stack.length] = this.valuetostring(object); }; /** * @param stack */ actionscript.prototype.actiontypeof = function (stack) { var object = stack.pop(); var str = ""; switch (true) { case object instanceof movieclip: str = "movieclip"; break; default: str = typeof object; break; } stack[stack.length] = str; }; /** * @param stack */ actionscript.prototype.actionadd2 = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = b + a; }; /** * @param stack */ actionscript.prototype.actionless2 = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = (b < a); }; /** * @param stack */ actionscript.prototype.actionmodulo = function (stack) { var y = stack.pop(); var x = stack.pop(); stack[stack.length] = x % y; }; /** * @param stack */ actionscript.prototype.actionbitand = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = b & a; }; /** * @param stack */ actionscript.prototype.actionbitlshift = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = b << a; }; /** * @param stack */ actionscript.prototype.actionbitor = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = b | a; }; /** * @param stack */ actionscript.prototype.actionbitrshift = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = b >> a; }; /** * @param stack */ actionscript.prototype.actionbiturshift = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = b >> a; }; /** * @param stack */ actionscript.prototype.actionbitxor = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = a ^ b; }; /** * @param stack */ actionscript.prototype.actiondecrement = function (stack) { var value = +stack.pop(); value--; stack[stack.length] = value; }; /** * @param stack */ actionscript.prototype.actionincrement = function (stack) { var value = +stack.pop(); value++; stack[stack.length] = value; }; /** * @param stack */ actionscript.prototype.actionpushduplicate = function (stack) { var length = stack.length; stack[length] = stack[length - 1]; }; /** * @param stack */ actionscript.prototype.actionstackswap = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = a; stack[stack.length] = b; }; /** * @param stack * @param number */ actionscript.prototype.actionstoreregister = function (stack, number) { this.params[number] = stack[stack.length - 1]; }; /** * @param stack */ actionscript.prototype.actioninstanceof = function (stack) { var constr = stack.pop(); var object = stack.pop(); stack[stack.length] = (object instanceof constr); }; /** * @param stack */ actionscript.prototype.actionstrictequals = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = (b === a); }; /** * @param stack */ actionscript.prototype.actiongreater = function (stack) { var a = stack.pop(); var b = stack.pop(); stack[stack.length] = (b > a); }; /** * @param stack */ actionscript.prototype.actionextends = function (stack) { var superclass = stack.pop(); var subclass = stack.pop(); if (superclass && subclass) { this.superclass = superclass; } }; /** * @param stack */ actionscript.prototype.actioncastop = function (stack) { var object = stack.pop(); var func = stack.pop(); stack[stack.length] = (typeof func === "function" && object instanceof func.prototype.constructor) ? object : null; }; /** * @param stack */ actionscript.prototype.actionimplementsop = function (stack) { console.log("actionimplementsop"); var func = stack.pop(); console.log(func); var count = stack.pop(); var params = []; if (count > 0) { while (count--) { params[params.length] = stack.pop(); } } stack[stack.length] = null; }; /** * @param script * @param mc */ actionscript.prototype.actiontry = function (script, mc) { try { script.try.apply(mc); } catch (e) { if (script.catchblockflag) { script.catch.apply(mc,[e]); } } finally { if (script.finallyblockflag) { script.finally.apply(mc); } } }; /** * actionthrow */ actionscript.prototype.actionthrow = function (stack) { var value = stack.pop(); throw value.message; }; /** * * @constructor */ var bitmapfilter = function () {}; /** * @param color * @param data * @returns {{r: number, g: number, b: number, a: number}} */ bitmapfilter.prototype.generatecolortransform = function (color, data) { return { r: _max(0, _min((color.r * data[0]) + data[4], 255))|0, g: _max(0, _min((color.g * data[1]) + data[5], 255))|0, b: _max(0, _min((color.b * data[2]) + data[6], 255))|0, a: _max(0, _min((color.a * 255 * data[3]) + data[7], 255)) / 255 }; }; /** * @param int * @param alpha * @returns {{r: number, g: number, b: number, a: number}} */ bitmapfilter.prototype.inttorgba = function (int, alpha) { alpha = alpha || 100; return { r: (int & 0xff0000) >> 16, g: (int & 0x00ff00) >> 8, b: (int & 0x0000ff), a: (alpha / 100) }; }; /** * @param inner * @param knockout * @param hideobject * @returns {*} */ bitmapfilter.prototype.filteroperation = function (inner, knockout, hideobject) { var operation = "source-over"; if (knockout === true) { if (inner) { operation = "source-in"; } else { operation = "source-out"; } } else { if (hideobject === true) { if (inner) { operation = "source-in"; } else { operation = "copy"; } } else { if (inner) { operation = "source-atop"; } else { operation = "destination-over"; } } } return operation; }; /** * @param ctx * @param color * @param inner * @param strength * @returns {*} */ bitmapfilter.prototype.coatofcolor = function (ctx, color, inner, strength) { var canvas = ctx.canvas; var imgdata = ctx.getimagedata(0, 0, canvas.width, canvas.height); var i = 0; var pxdata = imgdata.data; var r = color.r; var g = color.g; var b = color.b; var length = pxdata.length; for (; i < length; i += 4) { var akey = i + 3; var alpha = pxdata[akey]; if (!inner) { if (alpha !== 0) { pxdata[i] = r|0; pxdata[i + 1] = g|0; pxdata[i + 2] = b|0; pxdata[akey] = alpha|0; } } else { if (alpha !== 255) { pxdata[i] = r|0; pxdata[i + 1] = g|0; pxdata[i + 2] = b|0; pxdata[akey] = 255 - (alpha|0); } } } ctx.putimagedata(imgdata, 0, 0); if (strength > 0) { for (i = 1; i < strength; i++) { ctx.drawimage(ctx.canvas, 0, 0); } } return ctx; }; /** * clone */ bitmapfilter.prototype.clone = function () { var _this = this; var args = []; for (var prop in _this) { if (!_this.hasownproperty(prop)) { continue; } args[args.length] = _this[prop]; } var type = _this.filterid; var filter = _this; switch (type) { case 0: // dropshadowfilter filter = new (function.prototype.bind.apply(dropshadowfilter, args))(); break; case 1: // blurfilter filter = new (function.prototype.bind.apply(blurfilter, args))(); break; case 2: // glowfilter filter = new (function.prototype.bind.apply(glowfilter, args))(); break; case 3: // bevelfilter filter = new (function.prototype.bind.apply(bevelfilter, args))(); break; case 4: // gradientglowfilter filter = new (function.prototype.bind.apply(gradientglowfilter, args))(); break; case 5: // convolutionfilter filter = new (function.prototype.bind.apply(convolutionfilter, args))(); break; case 6: // colormatrixfilter filter = new (function.prototype.bind.apply(colormatrixfilter, args))(); break; case 7: // gradientbevelfilter filter = new (function.prototype.bind.apply(gradientbevelfilter, args))(); break; } return filter; }; /** * @param rgb * @returns {number} */ bitmapfilter.prototype.tocolorint = function (rgb) { if (typeof rgb === "string") { var canvas = cachestore.getcanvas(); canvas.width = 1; canvas.height = 1; var ctx = canvas.getcontext("2d"); ctx.fillstyle = rgb; rgb = "0x" + ctx.fillstyle.substr(1); cachestore.destroy(ctx); } return rgb; }; /** * @constructor */ var blurfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 1; _this.blurx = 4; _this.blury = 4; _this.quality = 1; var arg = arguments; var blurx = arg[0]|0; if (!_isnan(blurx) && 0 <= blurx && 255 >= blurx) { _this.blurx = blurx; } var blury = arg[1]|0; if (!_isnan(blury) && 0 <= blury && 255 >= blury) { _this.blury = blury; } var quality = arg[2]|0; if (!_isnan(quality) && 1 <= quality && 15 >= quality) { _this.quality = quality; } }; /** * extends * @type {bitmapfilter} */ blurfilter.prototype = object.create(bitmapfilter.prototype); blurfilter.prototype.constructor = blurfilter; /** * @param cache * @param matrix * @param colortransform * @param stage * @returns {*} */ blurfilter.prototype.render = function (cache, matrix, colortransform, stage) { var cachecanvas = cache.canvas; var canvas = cachestore.getcanvas(); canvas.width = cachecanvas.width; canvas.height = cachecanvas.height; var ctx = canvas.getcontext("2d"); ctx.drawimage(cachecanvas, 0, 0); ctx._offsetx = cache._offsetx; ctx._offsety = cache._offsety; return this.executefilter(ctx, stage); }; /** * @param ctx * @param stage * @returns {*} */ blurfilter.prototype.executefilter = function (ctx, stage) { var _this = this; var _blurx = _this.blurx; var _blury = _this.blury; if (_blurx === 0 && _blury === 0) { return ctx; } if (_blurx === 0) { _blurx = 4; } if (_blury === 0) { _blury = 4; } var _quality = _this.quality; var scale = stage.getscale(); var step = [0.5, 1.05, 1.35, 1.55, 1.75, 1.9, 2, 2.1, 2.2, 2.3, 2.5, 3, 3, 3.5, 3.5]; var stepno = step[_quality - 1]; var blurx = _ceil(_blurx * stepno * scale * devicepixelratio); var blury = _ceil(_blury * stepno * scale * devicepixelratio); var canvas = ctx.canvas; var width = _ceil(canvas.width + (blurx * 2) + 1); var height = _ceil(canvas.height + (blury * 2) + 1); var blurcanvas = cachestore.getcanvas(); blurcanvas.width = width; blurcanvas.height = height; var blurctx = blurcanvas.getcontext("2d"); var offsetx = blurx; var offsety = blury; blurctx._offsetx = blurx + ctx._offsetx; blurctx._offsety = blury + ctx._offsety; blurctx.drawimage(canvas, offsetx, offsety); var imgdata = blurctx.getimagedata(0, 0, width, height); var px = imgdata.data; var radiusx = (offsetx) >> 1; var radiusy = (offsety) >> 1; var mul = [1, 171, 205, 293, 57, 373, 79, 137, 241, 27, 391, 357, 41, 19, 283, 265, 497, 469, 443, 421, 25, 191, 365, 349, 335, 161, 155, 149, 9, 278, 269, 261, 505, 245, 475, 231, 449, 437, 213, 415, 405, 395, 193, 377, 369, 361, 353, 345, 169, 331, 325, 319, 313, 307, 301, 37, 145, 285, 281, 69, 271, 267, 263, 259, 509, 501, 493, 243, 479, 118, 465, 459, 113, 446, 55, 435, 429, 423, 209, 413, 51, 403, 199, 393, 97, 3, 379, 375, 371, 367, 363, 359, 355, 351, 347, 43, 85, 337, 333, 165, 327, 323, 5, 317, 157, 311, 77, 305, 303, 75, 297, 294, 73, 289, 287, 71, 141, 279, 277, 275, 68, 135, 67, 133, 33, 262, 260, 129, 511, 507, 503, 499, 495, 491, 61, 121, 481, 477, 237, 235, 467, 232, 115, 457, 227, 451, 7, 445, 221, 439, 218, 433, 215, 427, 425, 211, 419, 417, 207, 411, 409, 203, 202, 401, 399, 396, 197, 49, 389, 387, 385, 383, 95, 189, 47, 187, 93, 185, 23, 183, 91, 181, 45, 179, 89, 177, 11, 175, 87, 173, 345, 343, 341, 339, 337, 21, 167, 83, 331, 329, 327, 163, 81, 323, 321, 319, 159, 79, 315, 313, 39, 155, 309, 307, 153, 305, 303, 151, 75, 299, 149, 37, 295, 147, 73, 291, 145, 289, 287, 143, 285, 71, 141, 281, 35, 279, 139, 69, 275, 137, 273, 17, 271, 135, 269, 267, 133, 265, 33, 263, 131, 261, 130, 259, 129, 257, 1]; var shg = [0, 9, 10, 11, 9, 12, 10, 11, 12, 9, 13, 13, 10, 9, 13, 13, 14, 14, 14, 14, 10, 13, 14, 14, 14, 13, 13, 13, 9, 14, 14, 14, 15, 14, 15, 14, 15, 15, 14, 15, 15, 15, 14, 15, 15, 15, 15, 15, 14, 15, 15, 15, 15, 15, 15, 12, 14, 15, 15, 13, 15, 15, 15, 15, 16, 16, 16, 15, 16, 14, 16, 16, 14, 16, 13, 16, 16, 16, 15, 16, 13, 16, 15, 16, 14, 9, 16, 16, 16, 16, 16, 16, 16, 16, 16, 13, 14, 16, 16, 15, 16, 16, 10, 16, 15, 16, 14, 16, 16, 14, 16, 16, 14, 16, 16, 14, 15, 16, 16, 16, 14, 15, 14, 15, 13, 16, 16, 15, 17, 17, 17, 17, 17, 17, 14, 15, 17, 17, 16, 16, 17, 16, 15, 17, 16, 17, 11, 17, 16, 17, 16, 17, 16, 17, 17, 16, 17, 17, 16, 17, 17, 16, 16, 17, 17, 17, 16, 14, 17, 17, 17, 17, 15, 16, 14, 16, 15, 16, 13, 16, 15, 16, 14, 16, 15, 16, 12, 16, 15, 16, 17, 17, 17, 17, 17, 13, 16, 15, 17, 17, 17, 16, 15, 17, 17, 17, 16, 15, 17, 17, 14, 16, 17, 17, 16, 17, 17, 16, 15, 17, 16, 14, 17, 16, 15, 17, 16, 17, 17, 16, 17, 15, 16, 17, 14, 17, 16, 15, 17, 16, 17, 13, 17, 16, 17, 17, 16, 17, 14, 17, 16, 17, 16, 17, 16, 17, 9]; var mtx = mul[radiusx]; var stx = shg[radiusx]; var mty = mul[radiusy]; var sty = shg[radiusy]; var x = 0; var y = 0; var p = 0; var yp = 0; var yi = 0; var yw = 0; var r = 0; var g = 0; var b = 0; var a = 0; var pr = 0; var pg = 0; var pb = 0; var pa = 0; var divx = radiusx + radiusx + 1; var divy = radiusy + radiusy + 1; var w = imgdata.width; var h = imgdata.height; var w1 = w - 1; var h1 = h - 1; var rxp1 = radiusx + 1; var ryp1 = radiusy + 1; var ssx = {r: 0, b: 0, g: 0, a: 0}; var sx = ssx; for (var i = 1; i < divx; i++) { sx = sx.n = {r: 0, b: 0, g: 0, a: 0}; } sx.n = ssx; var ssy = {r: 0, b: 0, g: 0, a: 0}; var sy = ssy; for (i = 1; i < divy; i++) { sy = sy.n = {r: 0, b: 0, g: 0, a: 0}; } sy.n = ssy; var si = null; while (_quality-- > 0) { yw = yi = 0; var ms = mtx | 0; var ss = stx | 0; for (y = h; --y > -1;) { pr = px[yi]; pg = px[yi + 1]; pb = px[yi + 2]; pa = px[yi + 3]; r = rxp1 * pr; g = rxp1 * pg; b = rxp1 * pb; a = rxp1 * pa; sx = ssx; for (i = rxp1; --i > -1;) { sx.r = pr; sx.g = pg; sx.b = pb; sx.a = pa; sx = sx.n; } for (i = 1; i < rxp1; i++) { p = (yi + ((w1 < i ? w1 : i) << 2)) | 0; r += (sx.r = px[p]); g += (sx.g = px[p + 1]); b += (sx.b = px[p + 2]); a += (sx.a = px[p + 3]); sx = sx.n; } si = ssx; for (x = 0; x < w; x++) { px[yi++] = (r * ms) >>> ss; px[yi++] = (g * ms) >>> ss; px[yi++] = (b * ms) >>> ss; px[yi++] = (a * ms) >>> ss; p = ((yw + ((p = x + radiusx + 1) < w1 ? p : w1)) << 2); r -= si.r - (si.r = px[p]); g -= si.g - (si.g = px[p + 1]); b -= si.b - (si.b = px[p + 2]); a -= si.a - (si.a = px[p + 3]); si = si.n; } yw += w; } ms = mty; ss = sty; for (x = 0; x < w; x++) { yi = (x << 2) | 0; r = (ryp1 * (pr = px[yi])) | 0; g = (ryp1 * (pg = px[(yi + 1) | 0])) | 0; b = (ryp1 * (pb = px[(yi + 2) | 0])) | 0; a = (ryp1 * (pa = px[(yi + 3) | 0])) | 0; sy = ssy; for (i = 0; i < ryp1; i++) { sy.r = pr; sy.g = pg; sy.b = pb; sy.a = pa; sy = sy.n; } yp = w; for (i = 1; i <= radiusy; i++) { yi = (yp + x) << 2; r += (sy.r = px[yi]); g += (sy.g = px[yi + 1]); b += (sy.b = px[yi + 2]); a += (sy.a = px[yi + 3]); sy = sy.n; if (i < h1) { yp += w; } } yi = x; si = ssy; if (_quality > 0) { for (y = 0; y < h; y++) { p = yi << 2; px[p + 3] = pa = (a * ms) >>> ss; if (pa > 0) { px[p] = ((r * ms) >>> ss ); px[p + 1] = ((g * ms) >>> ss); px[p + 2] = ((b * ms) >>> ss); } else { px[p] = px[p + 1] = px[p + 2] = 0; } p = (x + (((p = y + ryp1) < h1 ? p : h1) * w)) << 2; r -= si.r - (si.r = px[p]); g -= si.g - (si.g = px[p + 1]); b -= si.b - (si.b = px[p + 2]); a -= si.a - (si.a = px[p + 3]); si = si.n; yi += w; } } else { for (y = 0; y < h; y++) { p = yi << 2; px[p + 3] = pa = (a * ms) >>> ss; if (pa > 0) { pa = 255 / pa; px[p] = ((r * ms) >>> ss) * pa; px[p + 1] = ((g * ms) >>> ss) * pa; px[p + 2] = ((b * ms) >>> ss) * pa; } else { px[p] = px[p + 1] = px[p + 2] = 0; } p = (x + (((p = y + ryp1) < h1 ? p : h1) * w)) << 2; r -= si.r - (si.r = px[p]); g -= si.g - (si.g = px[p + 1]); b -= si.b - (si.b = px[p + 2]); a -= si.a - (si.a = px[p + 3]); si = si.n; yi += w; } } } } blurctx.putimagedata(imgdata, 0, 0); cachestore.destroy(ctx); return blurctx; }; /** * @constructor */ var dropshadowfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 0; _this.distance = 4; _this.angle = 45; _this.color = 0; _this.alpha = 1; _this.blurx = 4; _this.blury = 4; _this.strength = 1; _this.quality = 1; _this.inner = false; _this.knockout = false; _this.hideobject = false; var arg = arguments; var distance = arg[0]|0; if (!_isnan(distance)) { _this.distance = distance; } var angle = +arg[1]; if (!_isnan(angle) && 0 <= angle && 360 >= angle) { _this.angle = angle; } var color = _this.tocolorint(arg[2]); if (!_isnan(color)) { _this.color = color; } var alpha = +arg[3]; if (!_isnan(alpha) && 0 <= alpha && 1 >= alpha) { _this.alpha = alpha; } var blurx = arg[4]|0; if (!_isnan(blurx) && 0 <= blurx && 255 >= blurx) { _this.blurx = blurx; } var blury = arg[5]|0; if (!_isnan(blury) && 0 <= blury && 255 >= blury) { _this.blury = blury; } var strength = +arg[6]; if (!_isnan(strength) && 0 <= strength && 255 >= strength) { _this.strength = strength; } var quality = arg[7]|0; if (!_isnan(quality) && 1 <= quality && 15 >= quality) { _this.quality = quality; } var inner = arg[8]; if (typeof inner === "boolean") { _this.inner = inner; } var knockout = arg[9]; if (typeof knockout === "boolean") { _this.knockout = knockout; } var hideobject = arg[10]; if (typeof hideobject === "boolean") { _this.hideobject = hideobject; } }; /** * extends * @type {bitmapfilter} */ dropshadowfilter.prototype = object.create(bitmapfilter.prototype); dropshadowfilter.prototype.constructor = dropshadowfilter; /** * @param cache * @param matrix * @param colortransform * @param stage */ dropshadowfilter.prototype.render = function (cache, matrix, colortransform, stage) { var _this = this; var strength = _this.strength; if (strength === 0) { return cache; } var quality = _this.quality; var inner = _this.inner; var r = _this.angle * _pi / 180; var blurx = _this.blurx; var blury = _this.blury; // blur var blurfilter = new blurfilter(blurx, blury, quality); var ctx = blurfilter.render(cache, matrix, colortransform, stage); // dropshadow var intcolor = _this.tocolorint(_this.color); var filtercolor = _this.inttorgba(intcolor); var color = _this.generatecolortransform(filtercolor, colortransform); ctx = _this.coatofcolor(ctx, color, inner, strength); // synthesis var cacheoffsetx = cache._offsetx; var cacheoffsety = cache._offsety; var _offsetx = ctx._offsetx; var _offsety = ctx._offsety; var canvas = ctx.canvas; var syncanvas = cachestore.getcanvas(); var width = canvas.width + cacheoffsetx; var height = canvas.height + cacheoffsety; var ox = 0; var oy = 0; var dx = 0; var dy = 0; var distance = _this.distance; var scale = stage.getscale(); var x = _ceil(_cos(r) * distance * scale); var y = _ceil(_sin(r) * distance * scale); if (x !== 0) { width += _abs(x); if (x < 0) { ox -= x; } else { dx = x; } } if (y !== 0) { height += _abs(y); if (y < 0) { oy -= y; } else { dy = y; } } syncanvas.width = width; syncanvas.height = height; var synctx = syncanvas.getcontext("2d"); synctx.drawimage(cache.canvas, _offsetx + ox, _offsety + oy); synctx.globalalpha = _this.alpha; if (strength < 1) { synctx.globalalpha *= strength; } var knockout = _this.knockout; var hideobject = _this.hideobject; synctx.globalcompositeoperation = _this.filteroperation(inner, knockout, hideobject); synctx.drawimage(canvas, cacheoffsetx + dx, cacheoffsety + dy); synctx._offsetx = cacheoffsetx + _offsetx; synctx._offsety = cacheoffsety + _offsety; cachestore.destroy(ctx); return synctx; }; /** * @constructor */ var glowfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 2; _this.color = 0xff0000; _this.alpha = 1; _this.blurx = 6; _this.blury = 6; _this.strength = 2; _this.quality = 1; _this.inner = false; _this.knockout = false; var arg = arguments; var color = _this.tocolorint(arg[0]); if (!_isnan(color)) { _this.color = color; } var alpha = +arg[1]; if (!_isnan(alpha) && 0 <= alpha && 1 >= alpha) { _this.alpha = alpha; } var blurx = arg[2]|0; if (!_isnan(blurx) && 0 <= blurx && 255 >= blurx) { _this.blurx = blurx; } var blury = arg[3]|0; if (!_isnan(blury) && 0 <= blury && 255 >= blury) { _this.blury = blury; } var strength = +arg[4]; if (!_isnan(strength) && 0 <= strength && 255 >= strength) { _this.strength = strength; } var quality = arg[5]|0; if (!_isnan(quality) && 1 <= quality && 15 >= quality) { _this.quality = quality; } var inner = arg[6]; if (typeof inner === "boolean") { _this.inner = inner; } var knockout = arg[7]; if (typeof knockout === "boolean") { _this.knockout = knockout; } }; /** * extends * @type {bitmapfilter} */ glowfilter.prototype = object.create(bitmapfilter.prototype); glowfilter.prototype.constructor = glowfilter; /** * @param cache * @param matrix * @param colortransform * @param stage * @returns {*} */ glowfilter.prototype.render = function (cache, matrix, colortransform, stage) { var _this = this; var strength = _this.strength; if (strength === 0) { return cache; } var inner = _this.inner; var blurx = _this.blurx; var blury = _this.blury; var blurfilter = new blurfilter(blurx, blury, _this.quality); var ctx = blurfilter.render(cache, matrix, colortransform, stage); var width = ctx.canvas.width + cache._offsetx; var height = ctx.canvas.height + cache._offsety; var intcolor = _this.tocolorint(_this.color); var filtercolor = _this.inttorgba(intcolor); var color = _this.generatecolortransform(filtercolor, colortransform); ctx = _this.coatofcolor(ctx, color, inner, strength); var syncanvas = cachestore.getcanvas(); syncanvas.width = width; syncanvas.height = height; var synctx = syncanvas.getcontext("2d"); synctx.drawimage(cache.canvas, ctx._offsetx, ctx._offsety); synctx.globalalpha = _this.alpha; if (strength < 1) { synctx.globalalpha *= strength; } var operation = "source-over"; if (_this.knockout) { if (inner) { operation = "source-in"; } else { operation = "source-out"; } } else { if (inner) { operation = "source-atop"; } else { operation = "destination-over"; } } synctx.globalcompositeoperation = operation; synctx.drawimage(ctx.canvas, cache._offsetx, cache._offsety); synctx._offsetx = cache._offsetx + ctx._offsetx; synctx._offsety = cache._offsety + ctx._offsety; cachestore.destroy(ctx); return synctx; }; /** * @constructor */ var bevelfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 3; _this.distance = 4; _this.angle = 45; _this.highlightcolor = 0xffffff; _this.highlightalpha = 1; _this.shadowcolor = 0x000000; _this.shadowalpha = 1; _this.blurx = 4; _this.blury = 4; _this.strength = 1; _this.quality = 1; _this.type = "inner"; _this.knockout = false; var arg = arguments; var distance = arg[0]|0; if (!_isnan(distance)) { _this.distance = distance; } var angle = +arg[1]; if (!_isnan(angle) && 0 <= angle && 360 >= angle) { _this.angle = angle; } var highlightcolor = _this.tocolorint(arg[2]); if (!_isnan(highlightcolor)) { _this.highlightcolor = highlightcolor; } var highlightalpha = +arg[3]; if (!_isnan(highlightalpha) && 0 <= highlightalpha && 1 >= highlightalpha) { _this.highlightalpha = highlightalpha; } var shadowcolor = _this.tocolorint(arg[4]); if (!_isnan(shadowcolor)) { _this.shadowcolor = shadowcolor; } var shadowalpha = +arg[5]; if (!_isnan(shadowalpha) && 0 <= shadowalpha && 1 >= shadowalpha) { _this.shadowalpha = shadowalpha; } var blurx = arg[6]|0; if (!_isnan(blurx) && 0 <= blurx && 255 >= blurx) { _this.blurx = blurx; } var blury = arg[7]|0; if (!_isnan(blury) && 0 <= blury && 255 >= blury) { _this.blury = blury; } var strength = +arg[8]; if (!_isnan(strength) && 0 <= strength && 255 >= strength) { _this.strength = strength; } var quality = arg[9]|0; if (!_isnan(quality) && 1 <= quality && 15 >= quality) { _this.quality = quality; } var type = arg[10]; if (typeof type === "string") { _this.type = type; } var knockout = arg[11]; if (typeof knockout === "boolean") { _this.knockout = knockout; } }; /** * extends * @type {bitmapfilter} */ bevelfilter.prototype = object.create(bitmapfilter.prototype); bevelfilter.prototype.constructor = bevelfilter; /** * @param cache * @param matrix * @param colortransform * @param stage * @returns {*} */ bevelfilter.prototype.render = function (cache, matrix, colortransform, stage) { var _this = this; var distance = _this.distance; var angle = _this.angle; var shadowcolor = _this.shadowcolor; var shadowalpha = _this.shadowalpha; var highlightcolor = _this.highlightcolor; var highlightalpha = _this.highlightalpha; var blurx = _this.blurx; var blury = _this.blury; var strength = _this.strength; var quality = _this.quality; var knockout = _this.knockout; var r = angle * _pi / 180; var filtercolor, color; var type = _this.type; // blur var blurfilter = new blurfilter(blurx, blury, quality); var ctx = blurfilter.render(cache, matrix, colortransform, stage); var canvas = ctx.canvas; var _offsetx = ctx._offsetx; var _offsety = ctx._offsety; // shadow var shadowcanvas = cachestore.getcanvas(); shadowcanvas.width = canvas.width; shadowcanvas.height = canvas.height; var shadowctx = shadowcanvas.getcontext("2d"); shadowctx.drawimage(canvas, 0, 0); var intshadowcolor = _this.tocolorint(shadowcolor); filtercolor = _this.inttorgba(intshadowcolor); color = _this.generatecolortransform(filtercolor, colortransform); shadowctx = _this.coatofcolor(shadowctx, color, false, strength); // shadow var highlightcanvas = cachestore.getcanvas(); highlightcanvas.width = canvas.width; highlightcanvas.height = canvas.height; var highlightctx = highlightcanvas.getcontext("2d"); highlightctx.drawimage(canvas, 0, 0); var inthighlightcolor = _this.tocolorint(highlightcolor); filtercolor = _this.inttorgba(inthighlightcolor); color = _this.generatecolortransform(filtercolor, colortransform); highlightctx = _this.coatofcolor(highlightctx, color, false, strength); var isinner = (type === "inner" || type === "full"); var isouter = (type === "outer" || type === "full"); var cacheoffsetx = cache._offsetx; var cacheoffsety = cache._offsety; var syncanvas = cachestore.getcanvas(); var width = canvas.width + cacheoffsetx; var height = canvas.height + cacheoffsety; var ox = 0; var oy = 0; var scale = stage.getscale(); var x = _ceil(_cos(r) * distance * scale); var y = _ceil(_sin(r) * distance * scale); if (x !== 0) { width += _abs(x); if (x < 0) { ox -= x; } } if (y !== 0) { height += _abs(y); if (y < 0) { oy -= y; } } syncanvas.width = width; syncanvas.height = height; var synctx = syncanvas.getcontext("2d"); if (!knockout) { synctx.drawimage(cache.canvas, _offsetx + ox, _offsety + oy); } if (strength < 1) { synctx.globalalpha *= strength; } synctx._offsetx = cacheoffsetx + _offsetx; synctx._offsety = cacheoffsety + _offsety; var xorcanvas = cachestore.getcanvas(); xorcanvas.width = width + _offsetx; xorcanvas.height = height + _offsety; var xorctx = xorcanvas.getcontext("2d"); xorctx.globalcompositeoperation = "xor"; xorctx.globalalpha = highlightalpha; xorctx.drawimage(highlightctx.canvas, -x + ox, -y + oy); xorctx.globalalpha = shadowalpha; xorctx.drawimage(shadowctx.canvas, x, y); var operation; if (isinner && isouter) { operation = "source-over"; } else if (isinner) { synctx.drawimage(cache.canvas, _offsetx + ox, _offsety + oy); operation = _this.filteroperation(true, knockout); } else if (isouter) { operation = "destination-over"; } synctx.globalcompositeoperation = operation; synctx.drawimage(xorctx.canvas, 0, 0); if (!isinner && isouter && knockout) { synctx.globalcompositeoperation = "destination-out"; synctx.drawimage(cache.canvas, _offsetx + ox, _offsety + oy); } cachestore.destroy(ctx); cachestore.destroy(highlightctx); cachestore.destroy(shadowctx); cachestore.destroy(xorctx); return synctx; }; /** * @constructor */ var gradientglowfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 4; _this.distance = 4; _this.angle = 45; _this.colors = null; _this.alphas = null; _this.ratios = null; _this.blurx = 4; _this.blury = 4; _this.strength = 1; _this.quality = 1; _this.type = "inner"; _this.knockout = false; var arg = arguments; var distance = arg[0]|0; if (!_isnan(distance)) { _this.distance = distance; } var angle = +arg[1]; if (!_isnan(angle) && 0 <= angle && 360 >= angle) { _this.angle = angle; } _this.colors = arg[2]; _this.alphas = arg[3]; _this.ratios = arg[4]; var blurx = arg[5]|0; if (!_isnan(blurx) && 0 <= blurx && 255 >= blurx) { _this.blurx = blurx; } var blury = arg[6]|0; if (!_isnan(blury) && 0 <= blury && 255 >= blury) { _this.blury = blury; } var strength = +arg[7]; if (!_isnan(strength) && 0 <= strength && 255 >= strength) { _this.strength = strength; } var quality = arg[8]|0; if (!_isnan(quality) && 1 <= quality && 15 >= quality) { _this.quality = quality; } var type = arg[9]; if (typeof type === "string") { _this.type = type; } var knockout = arg[10]; if (typeof knockout === "boolean") { _this.knockout = knockout; } }; /** * extends * @type {bitmapfilter} */ gradientglowfilter.prototype = object.create(bitmapfilter.prototype); gradientglowfilter.prototype.constructor = gradientglowfilter; /** * @param cache * @param matrix * @param colortransform * @param stage * @returns {*} */ gradientglowfilter.prototype.render = function (cache, matrix, colortransform, stage) { var _this = this; var strength = _this.strength; if (strength === 0) { return cache; } var type = _this.type; var blurx = _this.blurx; var blury = _this.blury; var isinner = (type === "inner" || type === "full"); var isouter = (type === "outer" || type === "full"); var knockout = _this.knockout; var angle = _this.angle; var r = angle * _pi / 180; var blurfilter = new blurfilter(blurx, blury, _this.quality); var ctx = blurfilter.render(cache, matrix, colortransform, stage); // synthesis var cacheoffsetx = cache._offsetx; var cacheoffsety = cache._offsety; var _offsetx = ctx._offsetx; var _offsety = ctx._offsety; var canvas = ctx.canvas; var syncanvas = cachestore.getcanvas(); var width = canvas.width + cacheoffsetx; var height = canvas.height + cacheoffsety; var ox = 0; var oy = 0; var dx = 0; var dy = 0; var distance = _this.distance; var scale = stage.getscale(); var x = _ceil(_cos(r) * distance * scale); var y = _ceil(_sin(r) * distance * scale); if (x !== 0) { width += _abs(x); if (x < 0) { ox -= x; } else { dx = x; } } if (y !== 0) { height += _abs(y); if (y < 0) { oy -= y; } else { dy = y; } } syncanvas.width = width; syncanvas.height = height; var synctx = syncanvas.getcontext("2d"); if (!knockout) { synctx.drawimage(cache.canvas, _offsetx + ox, _offsety + oy); } if (strength < 1) { synctx.globalalpha *= strength; } var operation; if (isinner && isouter) { operation = "source-over"; } else { if (knockout) { synctx.drawimage(cache.canvas, _offsetx + ox, _offsety + oy); } operation = _this.filteroperation(isinner, knockout); } synctx.globalcompositeoperation = operation; synctx.drawimage(canvas, cacheoffsetx + dx, cacheoffsety + dy); synctx._offsetx = cacheoffsetx + _offsetx; synctx._offsety = cacheoffsety + _offsety; cachestore.destroy(ctx); return synctx; }; /** * @constructor */ var convolutionfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 5; }; /** * extends * @type {bitmapfilter} */ convolutionfilter.prototype = object.create(bitmapfilter.prototype); convolutionfilter.prototype.constructor = convolutionfilter; /** * @param cache * @param matrix * @param colortransform * @param stage * @returns {*} */ convolutionfilter.prototype.render = function (cache, matrix, colortransform, stage) { return cache; }; /** * @constructor */ var colormatrixfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 6; }; /** * extends * @type {bitmapfilter} */ colormatrixfilter.prototype = object.create(bitmapfilter.prototype); colormatrixfilter.prototype.constructor = colormatrixfilter; /** * @param cache * @param matrix * @param colortransform * @param stage * @returns {*} */ colormatrixfilter.prototype.render = function (cache, matrix, colortransform, stage) { return cache; }; /** * @constructor */ var gradientbevelfilter = function () { var _this = this; bitmapfilter.call(_this); _this.filterid = 7; }; /** * extends * @type {bitmapfilter} */ gradientbevelfilter.prototype = object.create(bitmapfilter.prototype); gradientbevelfilter.prototype.constructor = gradientbevelfilter; /** * @param cache * @param matrix * @param colortransform * @param stage * @returns {*} */ gradientbevelfilter.prototype.render = function (cache, matrix, colortransform, stage) { return cache; }; /** * @constructor */ var graphics = function () { this.clear(); }; /** * @type {number} */ graphics.prototype.move_to = 0; /** * @type {number} */ graphics.prototype.curve_to = 1; /** * @type {number} */ graphics.prototype.line_to = 2; /** * @type {number} */ graphics.prototype.cubic = 3; /** * @type {number} */ graphics.prototype.arc = 4; /** * @type {number} */ graphics.prototype.fill_style = 5; /** * @type {number} */ graphics.prototype.stroke_style = 6; /** * @type {number} */ graphics.prototype.fill = 7; /** * @type {number} */ graphics.prototype.stroke = 8; /** * @type {number} */ graphics.prototype.line_width = 9; /** * @type {number} */ graphics.prototype.line_cap = 10; /** * @type {number} */ graphics.prototype.line_join = 11; /** * @type {number} */ graphics.prototype.miter_limit = 12; /** * @type {number} */ graphics.prototype.begin_path = 13; /** * @param a * @param b * @returns [] */ graphics.prototype.multiplicationmatrix = function(a, b) { return [ a[0] * b[0] + a[2] * b[1], a[1] * b[0] + a[3] * b[1], a[0] * b[2] + a[2] * b[3], a[1] * b[2] + a[3] * b[3], a[0] * b[4] + a[2] * b[5] + a[4], a[1] * b[4] + a[3] * b[5] + a[5] ]; }; /** * @param color * @param data * @returns {{r: number, g: number, b: number, a: number}} */ graphics.prototype.generatecolortransform = function (color, data) { return { r: _max(0, _min((color.r * data[0]) + data[4], 255))|0, g: _max(0, _min((color.g * data[1]) + data[5], 255))|0, b: _max(0, _min((color.b * data[2]) + data[6], 255))|0, a: _max(0, _min((color.a * 255 * data[3]) + data[7], 255)) / 255 }; }; /** * @param int * @param alpha * @returns {{r: number, g: number, b: number, a: number}} */ graphics.prototype.inttorgba = function (int, alpha) { alpha = alpha || 100; return { r: (int & 0xff0000) >> 16, g: (int & 0x00ff00) >> 8, b: (int & 0x0000ff), a: (alpha / 100) }; }; /** * @returns {graphics} */ graphics.prototype.clear = function () { var _this = this; var no = _number.max_value; _this.bounds = {xmin: no, xmax: -no, ymin: no, ymax: -no}; _this.maxwidth = 0; _this.cmd = null; _this.isdraw = false; _this.isfilldraw = false; _this.islinedraw = false; _this.cachekey = ""; _this.recodes = []; _this.linerecodes = []; return _this; }; /** * @returns {string} */ graphics.prototype.getcachekey = function () { return this.cachekey; }; /** * @returns {string} */ graphics.prototype.addcachekey = function () { var args = arguments; var cachekey = ""; var length = args.length; if (length) { for (var i = 0; i < length; i++) { var value = args[i]; cachekey += "_" + value; } } this.cachekey += cachekey; }; /** * @returns {*} */ graphics.prototype.getbounds = function () { return this.bounds; }; /** * @param x * @param y */ graphics.prototype.setbounds = function (x, y) { var bounds = this.bounds; bounds.xmin = _min(bounds.xmin, x); bounds.xmax = _max(bounds.xmax, x); bounds.ymin = _min(bounds.ymin, y); bounds.ymax = _max(bounds.ymax, y); }; /** * @param str * @returns {string} */ graphics.prototype.colorstringtoint = function(str) { var canvas = cachestore.getcanvas(); var ctx = canvas.getcontext("2d"); ctx.fillstyle = str; var color = "0x" + ctx.fillstyle.substr(1); cachestore.destroy(ctx); return color; }; /** * @param rgb * @param alpha * @returns {graphics} */ graphics.prototype.beginfill = function (rgb, alpha) { var _this = this; if (typeof rgb === "string") { rgb = _this.colorstringtoint(rgb); } rgb |= 0; alpha = +alpha; if (_isnan(alpha)) { alpha = 100; } else { alpha *= 100; } var color = _this.inttorgba(rgb, alpha); var recodes = _this.recodes; if (!_this.isfilldraw) { recodes[recodes.length] = [_this.begin_path]; } recodes[recodes.length] = [_this.fill_style, color.r, color.g, color.b, color.a]; _this.addcachekey(rgb, alpha); _this.isfilldraw = true; _this.isdraw = true; return _this; }; /** * @param width * @param rgb * @param alpha * @param pixelhinting * @param noscale * @param capsstyle * @param jointstyle * @param miterlimit * @returns {graphics} */ graphics.prototype.linestyle = function (width, rgb, alpha, pixelhinting, noscale, capsstyle, jointstyle, miterlimit) { var _this = this; var linerecodes = _this.linerecodes; width = +width; if (!_isnan(width)) { if (rgb === undefined) { rgb = 0; } if (typeof rgb === "string") { rgb = _this.colorstringtoint(rgb); } if (!capsstyle) { capsstyle = "round"; } if (!jointstyle) { jointstyle = "round"; } rgb |= 0; alpha = +alpha; if (_isnan(alpha)) { alpha = 100; } else { alpha *= 100; } var color = _this.inttorgba(rgb, alpha); if (width < 0.5) { width += 0.2; } width *= 20; _this.maxwidth = _max(_this.maxwidth, width); if (_this.islinedraw) { linerecodes[linerecodes.length] = [_this.stroke]; } linerecodes[linerecodes.length] = [_this.begin_path]; linerecodes[linerecodes.length] = [_this.stroke_style, color.r, color.g, color.b, color.a]; linerecodes[linerecodes.length] = [_this.line_width, width]; linerecodes[linerecodes.length] = [_this.line_cap, capsstyle]; linerecodes[linerecodes.length] = [_this.line_join, jointstyle]; _this.addcachekey(rgb, alpha); _this.islinedraw = true; _this.isdraw = true; } else if (_this.islinedraw) { _this.islinedraw = false; linerecodes[linerecodes.length] = [_this.stroke]; var length = linerecodes.length; var recodes = _this.recodes; for (var i = 0; i < length; i++) { recodes[recodes.length] = linerecodes[i]; } _this.linerecodes = []; } return _this; }; /** * @param x * @param y * @returns {graphics} */ graphics.prototype.moveto = function (x, y) { var _this = this; var recodes = _this.recodes; x *= 20; y *= 20; if (_this.isfilldraw) { recodes[recodes.length] = [_this.move_to, x, y]; } if (_this.islinedraw) { var linerecodes = _this.linerecodes; linerecodes[linerecodes.length] = [_this.move_to, x, y]; } if (_this.isfilldraw || _this.islinedraw) { _this.setbounds(x, y); _this.addcachekey(x, y); } return _this; }; /** * @param x * @param y * @returns {graphics} */ graphics.prototype.lineto = function (x, y) { var _this = this; var recodes = _this.recodes; x *= 20; y *= 20; if (_this.isfilldraw) { recodes[recodes.length] = [_this.line_to, x, y]; } if (_this.islinedraw) { var linerecodes = _this.linerecodes; linerecodes[linerecodes.length] = [_this.line_to, x, y]; } if (_this.isfilldraw || _this.islinedraw) { _this.setbounds(x, y); _this.addcachekey(x, y); } return _this; }; /** * @param cx * @param cy * @param dx * @param dy * @returns {graphics} */ graphics.prototype.curveto = function (cx, cy, dx, dy) { var _this = this; var recodes = _this.recodes; cx *= 20; cy *= 20; dx *= 20; dy *= 20; if (_this.isfilldraw) { recodes[recodes.length] = [_this.curve_to, cx, cy, dx, dy]; } if (_this.islinedraw) { var linerecodes = _this.linerecodes; linerecodes[linerecodes.length] = [_this.curve_to, cx, cy, dx, dy]; } if (_this.isfilldraw || _this.islinedraw) { _this.setbounds(cx, cy); _this.setbounds(dx, dy); _this.addcachekey(cx, cy, dx, dy); } return _this; }; /** * @param cp1x * @param cp1y * @param cp2x * @param cp2y * @param x * @param y * @returns {graphics} */ graphics.prototype.cubiccurveto = function (cp1x, cp1y, cp2x, cp2y, x, y) { var _this = this; var recodes = _this.recodes; cp1x *= 20; cp1y *= 20; cp2x *= 20; cp2y *= 20; x *= 20; y *= 20; if (_this.isfilldraw) { recodes[recodes.length] = [_this.cubic, cp1x, cp1y, cp2x, cp2y, x, y]; } if (_this.islinedraw) { var linerecodes = _this.linerecodes; linerecodes[linerecodes.length] = [_this.cubic, cp1x, cp1y, cp2x, cp2y, x, y]; } if (_this.isfilldraw || _this.islinedraw) { _this.setbounds(x, y); _this.setbounds(cp1x, cp1y); _this.setbounds(cp2x, cp2y); _this.addcachekey(cp1x, cp1y, cp2x, cp2y, x, y); } return _this; }; /** * @param x * @param y * @param radius * @returns {graphics} */ graphics.prototype.drawcircle = function (x, y, radius) { var _this = this; var recodes = _this.recodes; x *= 20; y *= 20; radius *= 20; if (_this.isfilldraw) { recodes[recodes.length] = [_this.arc, x, y, radius]; } if (_this.islinedraw) { var linerecodes = _this.linerecodes; linerecodes[linerecodes.length] = [_this.arc, x, y, radius]; } if (_this.isfilldraw || _this.islinedraw) { _this.setbounds(x - radius, y - radius); _this.setbounds(x + radius, y + radius); _this.addcachekey(x, y, radius); } return _this; }; /** * @param x * @param y * @param width * @param height * @returns {graphics} */ graphics.prototype.drawellipse = function (x, y, width, height) { var _this = this; var hw = width / 2; var hh = height / 2; var x0 = x + hw; var x1 = x + width; var y0 = y + hh; var y1 = y + height; var cw = 4 / 3 * (_sqrt2 - 1) * hw; var ch = 4 / 3 * (_sqrt2 - 1) * hh; _this.moveto(x0, y); _this.cubiccurveto(x0 + cw, y, x1, y0 - ch, x1, y0); _this.cubiccurveto(x1, y0 + ch, x0 + cw, y1, x0, y1); _this.cubiccurveto(x0 - cw, y1, x, y0 + ch, x, y0); _this.cubiccurveto(x, y0 - ch, x0 - cw, y, x0, y); return _this; }; /** * @param x * @param y * @param width * @param height * @returns {graphics} */ graphics.prototype.drawrect = function (x, y, width, height) { var _this = this; _this.moveto(x, y); _this.lineto(x + width, y); _this.lineto(x + width, y + height); _this.lineto(x, y + height); _this.lineto(x, y); return _this; }; /** * @param x * @param y * @param width * @param height * @param ellipsewidth * @param ellipseheight * @returns {graphics} */ graphics.prototype.drawroundrect = function (x, y, width, height, ellipsewidth, ellipseheight) { var _this = this; var hew = ellipsewidth / 2; var heh = ellipseheight / 2; var cw = 4 / 3 * (_sqrt2 - 1) * hew; var ch = 4 / 3 * (_sqrt2 - 1) * heh; var dx0 = x + hew; var dx1 = x + width; var dx2 = dx1 - hew; var dy0 = y + heh; var dy1 = y + height; var dy2 = dy1 - heh; _this.moveto(dx0, y); _this.lineto(dx2, y); _this.cubiccurveto(dx2 + cw, y, dx1, dy0 - ch, dx1, dy0); _this.lineto(dx1, dy2); _this.cubiccurveto(dx1, dy2 + ch, dx2 + cw, dy1, dx2, dy1); _this.lineto(dx0, dy1); _this.cubiccurveto(dx0 - cw, dy1, x, dy2 + ch, x, dy2); _this.lineto(x, dy0); _this.cubiccurveto(x, dy0 - ch, dx0 - cw, y, dx0, y); return _this; }; /** * @param vertices * @param indices * @param uvtdata * @param culling * @returns {graphics} */ graphics.prototype.drawtriangles = function (vertices, indices, uvtdata, culling) { var _this = this; var length = vertices.length; if (length && length % 3 === 0) { var i = 0; var count = 0; if (indices) { length = indices.length; if (length && length % 3 === 0) { for (i = 0; i < length; i++) { var idx = indices[i]; if (count === 0) { _this.moveto(vertices[idx], vertices[idx + 1]); } else { _this.lineto(vertices[idx], vertices[idx + 1]); } count++; if (count % 3 === 0) { count = 0; } } } } else { for (i = 0; i < length; i++) { if (count === 0) { _this.moveto(vertices[i++], vertices[i]); } else { _this.lineto(vertices[i++], vertices[i]); } count++; if (count % 3 === 0) { count = 0; } } } } return _this; }; /** * @returns {graphics} */ graphics.prototype.endfill = function () { var _this = this; if (_this.isfilldraw) { var recodes = _this.recodes; recodes[recodes.length] = [_this.fill]; } _this.isfilldraw = false; return _this; }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @returns {*} */ graphics.prototype.render = function (ctx, matrix, colortransform, stage) { var _this = this; var cachekey = ""; var alpha = colortransform[3] + (colortransform[7] / 255); if (!alpha) { return cachekey; } var rmatrix = _this.multiplicationmatrix(stage.getmatrix(), matrix); var xscale = _sqrt(rmatrix[0] * rmatrix[0] + rmatrix[1] * rmatrix[1]); var yscale = _sqrt(rmatrix[2] * rmatrix[2] + rmatrix[3] * rmatrix[3]); xscale = _pow(_sqrt2, _ceil(_log(xscale) / _ln2_2 - _log1p)); yscale = _pow(_sqrt2, _ceil(_log(yscale) / _ln2_2 - _log1p)); var maxwidth = _this.maxwidth; var halfwidth = maxwidth / 2; var bounds = _this.getbounds(); var xmax = bounds.xmax; var xmin = bounds.xmin; var ymax = bounds.ymax; var ymin = bounds.ymin; var w = _abs(_ceil((xmax - xmin + maxwidth) * xscale)); var h = _abs(_ceil((ymax - ymin + maxwidth) * yscale)); if (w <= 0 || h <= 0) { return cachekey; } var cache; var canvas; var isclipdepth = stage.clipmc || _this.isclipdepth; if (!isclipdepth) { cachekey = cachestore.generatekey("graphics", 0, [xscale, yscale], colortransform); cachekey += _this.getcachekey(); cache = cachestore.getcache(cachekey); if (!cache && stage.getwidth() > w && stage.getheight() > h && cachestore.size > (w * h)) { canvas = cachestore.getcanvas(); canvas.width = w; canvas.height = h; cache = canvas.getcontext("2d"); var cmatrix = [xscale, 0, 0, yscale, (-xmin + halfwidth) * xscale, (-ymin + halfwidth) * yscale]; cache.settransform(cmatrix[0], cmatrix[1], cmatrix[2], cmatrix[3], cmatrix[4], cmatrix[5]); cache = _this.executerender(cache, _min(xscale, yscale), colortransform, false); cachestore.setcache(cachekey, cache); } } if (cache) { canvas = cache.canvas; var smatrix = [1 / xscale, 0, 0, 1 / yscale, xmin - halfwidth, ymin - halfwidth]; var m2 = _this.multiplicationmatrix(rmatrix, smatrix); ctx.settransform(m2[0],m2[1],m2[2],m2[3],m2[4],m2[5]); if (isandroid4x && !ischrome) { ctx.fillstyle = stage.context.createpattern(cache.canvas, "no-repeat"); ctx.fillrect(0, 0, w, h); } else { ctx.drawimage(canvas, 0, 0, w, h); } } else { ctx.settransform(rmatrix[0],rmatrix[1],rmatrix[2],rmatrix[3],rmatrix[4],rmatrix[5]); _this.executerender(ctx, _min(rmatrix[0], rmatrix[3]), colortransform, isclipdepth); } return cachekey + "_" + rmatrix[4] + "_" + rmatrix[5]; }; /** * @param ctx * @param minscale * @param colortransform * @param isclip */ graphics.prototype.executerender = function (ctx, minscale, colortransform, isclip) { var _this = this; var recodes = _this.recodes; var length = recodes.length; var linerecodes = _this.linerecodes; if (length || linerecodes) { var cmd = _this.cmd; if (!cmd) { var llen = linerecodes.length; if (llen) { for (var i = 0; i < llen; i++) { recodes[recodes.length] = linerecodes[i]; } _this.linerecodes = []; } cmd = vtc.buildcommand(recodes); _this.cmd = cmd; } ctx.beginpath(); cmd(ctx, colortransform, isclip); if (isclip) { ctx.clip(); } else { if (_this.isfilldraw) { ctx.fill(); } if (_this.islinedraw) { ctx.stroke(); } } } var resetcss = "rgba(0,0,0,1)"; ctx.strokestyle = resetcss; ctx.fillstyle = resetcss; ctx.globalalpha = 1; return ctx; }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {boolean} */ graphics.prototype.renderhittest = function (ctx, matrix, stage, x, y) { var _this = this; var cmd = _this.cmd; if (!cmd) { var recodes = _this.recodes; cmd = vtc.buildcommand(recodes); _this.cmd = cmd; } var rmatrix = _this.multiplicationmatrix(stage.getmatrix(), matrix); ctx.settransform(rmatrix[0],rmatrix[1],rmatrix[2],rmatrix[3],rmatrix[4],rmatrix[5]); ctx.beginpath(); cmd(ctx, [1,1,1,1,0,0,0,0], true); var hit = ctx.ispointinpath(x, y); if (hit) { return hit; } if ("ispointinstroke" in ctx) { hit = ctx.ispointinstroke(x, y); if (hit) { return hit; } } return hit; }; /** * @constructor */ var soundtransform = function () { var _this = this; _this._lefttoleft = 0; _this._lefttoright = 1; _this._pan = 0; _this._righttoleft = 0; _this._righttoright = 1; _this._volume = 1; }; /** * properties */ object.defineproperties(soundtransform.prototype, { lefttoleft: { get: function () { return this.getlefttoleft(); }, set: function (lefttoleft) { this.setlefttoleft(lefttoleft); } }, lefttoright: { get: function () { return this.getlefttoright(); }, set: function (lefttoright) { this.setlefttoright(lefttoright); } }, pan: { get: function () { return this.getpan(); }, set: function (pan) { this.setpan(pan); } }, righttoleft: { get: function () { return this.getrighttoleft(); }, set: function (righttoleft) { this.setrighttoleft(righttoleft); } }, righttoright: { get: function () { return this.getrighttoright(); }, set: function (righttoright) { this.setrighttoright(righttoright); } }, volume: { get: function () { return this.getvolume(); }, set: function (volume) { this.setvolume(volume); } } }); /** * @returns {number} */ soundtransform.prototype.getlefttoleft = function () { return this._lefttoleft; }; /** * @param lefttoleft */ soundtransform.prototype.setlefttoleft = function (lefttoleft) { this._lefttoleft = lefttoleft | 0; }; /** * @returns {number} */ soundtransform.prototype.getlefttoright = function () { return this._lefttoright; }; /** * @param lefttoright */ soundtransform.prototype.setlefttoright = function (lefttoright) { this._lefttoright = lefttoright | 0; }; /** * @returns {number} */ soundtransform.prototype.getpan = function () { return this._pan; }; /** * @param pan */ soundtransform.prototype.setpan = function (pan) { this._pan = pan | 0; }; /** * @returns {number} */ soundtransform.prototype.getrighttoleft = function () { return this._righttoleft; }; /** * @param righttoleft */ soundtransform.prototype.setrighttoleft = function (righttoleft) { this._righttoleft = righttoleft | 0; }; /** * @returns {number} */ soundtransform.prototype.getrighttoright = function () { return this._righttoright; }; /** * @param righttoright */ soundtransform.prototype.setrighttoright = function (righttoright) { this._righttoright = righttoright | 0; }; /** * @returns {number} */ soundtransform.prototype.getvolume = function () { return this._volume; }; /** * @param volume */ soundtransform.prototype.setvolume = function (volume) { this._volume = volume | 0; }; /** * @param vol * @param panning */ soundtransform.prototype.soundtransform = function (vol, panning) { var _this = this; _this.volume = vol | 0; _this.pan = panning | 0; }; /** * @constructor */ var swf2jsevent = function () { var _this = this; _this.target = {}; _this.bubbles = true; _this.cancelable = true; _this.currenttarget = {}; _this.eventphase = 0; }; /** * @type {string} */ swf2jsevent.prototype.activate = "activate"; swf2jsevent.prototype.click = "press"; swf2jsevent.prototype.context_menu = "contextmenu"; swf2jsevent.prototype.double_click = "doubleclick"; swf2jsevent.prototype.middle_click = "middleclick"; swf2jsevent.prototype.middle_mouse_down = "middlemousedown"; swf2jsevent.prototype.middle_mouse_up = "middlemouseup"; swf2jsevent.prototype.mouse_down = "mousedown"; swf2jsevent.prototype.mouse_move = "mousemove"; swf2jsevent.prototype.mouse_out = "rollout"; // mouseout swf2jsevent.prototype.mouse_over = "rollover"; // mouseover swf2jsevent.prototype.mouse_up = "mouseup"; swf2jsevent.prototype.mouse_wheel = "mousewheel"; swf2jsevent.prototype.right_click = "rightclick"; swf2jsevent.prototype.right_mouse_down = "rightmousedown"; swf2jsevent.prototype.right_mouse_up = "rightmouseup"; swf2jsevent.prototype.roll_out = "rollout"; swf2jsevent.prototype.roll_over = "rollover"; /** * @param type * @param target * @constructor */ var clipevent = function (type) { var _this = this; _this.type = type; _this.target = null; swf2jsevent.call(this); }; /** * extends * @type {eventdispatcher} */ clipevent.prototype = object.create(swf2jsevent.prototype); clipevent.prototype.constructor = clipevent; var clipevent = new clipevent(); /** * @constructor */ var eventdispatcher = function () { var _this = this; _this.events = {}; _this.isload = false; _this.active = false; }; /** * properties */ object.defineproperties(eventdispatcher.prototype, { onenterframe: { get: function () { return this.getonevent("onenterframe"); }, set: function (onenterframe) { this.setonevent("onenterframe", onenterframe); } }, onpress: { get: function () { return this.getonevent("onpress"); }, set: function (onpress) { this.setonevent("onpress", onpress); } }, onrelease: { get: function () { return this.getonevent("onrelease"); }, set: function (onrelease) { this.setonevent("onrelease", onrelease); } }, onreleaseoutside: { get: function () { return this.getonevent("onreleaseoutside"); }, set: function (onreleaseoutside) { this.setonevent("onreleaseoutside", onreleaseoutside); } }, onrollover: { get: function () { return this.getonevent("onrollover"); }, set: function (onrollover) { this.setonevent("onrollover", onrollover); } }, onrollout: { get: function () { return this.getonevent("onrollout"); }, set: function (onrollout) { this.setonevent("onrollout", onrollout); } }, ondata: { get: function () { return this.getonevent("ondata"); }, set: function (ondata) { this.setonevent("ondata", ondata); } }, onmousedown: { get: function () { return this.getonevent("onmousedown"); }, set: function (onmousedown) { this.setonevent("onmousedown", onmousedown); } }, onmouseup: { get: function () { return this.getonevent("onmouseup"); }, set: function (onmouseup) { this.setonevent("onmouseup", onmouseup); } }, onmousemove: { get: function () { return this.getonevent("onmousemove"); }, set: function (onmousemove) { this.setonevent("onmousemove", onmousemove); } }, ondragout: { get: function () { return this.getonevent("ondragout"); }, set: function (ondragout) { this.setonevent("ondragout", ondragout); } }, ondragover: { get: function () { return this.getonevent("ondragover"); }, set: function (ondragover) { this.setonevent("ondragover", ondragover); } }, onkeydown: { get: function () { return this.getonevent("onkeydown"); }, set: function (onkeydown) { this.setonevent("onkeydown", onkeydown); } }, onkeyup: { get: function () { return this.getonevent("onkeyup"); }, set: function (onkeyup) { this.setonevent("onkeyup", onkeyup); } }, onload: { get: function () { return this.getonevent("onload"); }, set: function (onload) { this.setonevent("onload", onload); } }, onunload: { get: function () { return this.getonevent("onunload"); }, set: function (onunload) { this.setonevent("onunload", onunload); } } }); /** * @param type * @returns {*} */ eventdispatcher.prototype.getonevent = function (type) { return this.variables[type]; }; /** * @param type * @param as */ eventdispatcher.prototype.setonevent = function (type, as) { this.variables[type] = as; }; /** * @param type * @param listener * @param usecapture * @param priority * @param useweakreference */ eventdispatcher.prototype.addeventlistener = function (type, listener, usecapture, priority, useweakreference) { var events = this.events; if (!(type in events)) { events[type] = []; } var event = events[type]; event[event.length] = listener; }; /** * @param event * @param stage */ eventdispatcher.prototype.dispatchevent = function (event, stage) { var _this = this; var type = event.type; if (_this.haseventlistener(type)) { var events = _this.events[type]; var cevent = new clipevent(); cevent.type = type; cevent.target = this; var args = [cevent]; _this.setactionqueue(events, stage, args); } }; /** * @param type * @returns {boolean} */ eventdispatcher.prototype.haseventlistener = function (type) { return (type in this.events); }; /** * @param type * @param listener * @param usecapture */ eventdispatcher.prototype.removeeventlistener = function (type, listener, usecapture) { var _this = this; if (_this.haseventlistener(type)) { var events = _this.events; var listeners = events[type]; var length = listeners.length; for (var i = 0; i < length; i++) { if (listeners[i] !== listener) { continue; } listeners.slice(i, 0); break; } } }; /** * @param type */ eventdispatcher.prototype.willtrigger = function (type) { return this.haseventlistener(type); }; /** * @param as * @param stage * @param args */ eventdispatcher.prototype.setactionqueue = function (as, stage, args) { var actions = stage.actions; actions[actions.length] = {as: as, mc: this, args: args}; }; /** * @constructor */ var accessibilityproperties = function () {}; /** * @constructor */ var displayobject = function () { var _this = this; eventdispatcher.call(_this); _this.initialize(); }; /** * extends * @type {eventdispatcher} */ displayobject.prototype = object.create(eventdispatcher.prototype); displayobject.prototype.constructor = displayobject; /** * properties */ object.defineproperties(displayobject.prototype, { accessibilityproperties: { value: new accessibilityproperties() }, alpha: { get: function () { return this.getalpha() / 100; }, set: function (alpha) { this.setalpha(alpha * 100); } }, _alpha: { get: function () { return this.getalpha(); }, set: function (alpha) { this.setalpha(alpha); } }, name: { get: function () { return this.getname(); }, set: function (name) { this.setname(name); } }, _name: { get: function () { return this.getname(); }, set: function (name) { this.setname(name); } }, blendmode: { get: function () { return this.getblendmode(); }, set: function (blendmode) { this.setblendmode(blendmode); } }, filters: { get: function () { return this.getfilters(); }, set: function (filters) { this.setfilters(filters); } }, _visible: { get: function () { return this.getvisible(); }, set: function (visible) { this.setvisible(visible); } }, visible: { get: function () { return this.getvisible(); }, set: function (visible) { this.setvisible(visible); } }, _rotation: { get: function () { return this.getrotation(); }, set: function (rotation) { this.setrotation(rotation); } }, rotation: { get: function () { return this.getrotation(); }, set: function (rotation) { this.setrotation(rotation); } }, _height: { get: function () { return this.getheight(); }, set: function (height) { this.setheight(height); } }, height: { get: function () { return this.getheight(); }, set: function (height) { this.setheight(height); } }, _width: { get: function () { return this.getwidth(); }, set: function (width) { this.setwidth(width); } }, width: { get: function () { return this.getwidth(); }, set: function (width) { this.setwidth(width); } }, _x: { get: function () { return this.getx(); }, set: function (x) { this.setx(x); } }, x: { get: function () { return this.getx(); }, set: function (x) { this.setx(x); } }, _y: { get: function () { return this.gety(); }, set: function (y) { this.sety(y); } }, y: { get: function () { return this.gety(); }, set: function (y) { this.sety(y); } }, _xscale: { get: function () { return this.getxscale(); }, set: function (xscale) { this.setxscale(xscale); } }, scalex: { get: function () { return this.getxscale(); }, set: function (xscale) { this.setxscale(xscale); } }, _yscale: { get: function () { return this.getyscale(); }, set: function (yscale) { this.setyscale(yscale); } }, scaley: { get: function () { return this.getyscale(); }, set: function (yscale) { this.setyscale(yscale); } }, _xmouse: { get: function () { return this.getxmouse(); }, set: function () { } }, mousex: { get: function () { return this.getxmouse(); }, set: function () { } }, _ymouse: { get: function () { return this.getymouse(); }, set: function () { } }, mousey: { get: function () { return this.getymouse(); }, set: function () { } }, mask: { get: function () { return this.getmask(); }, set: function (obj) { this.setmask(obj); } }, enabled: { get: function () { return this.getenabled(); }, set: function (enabled) { this.setenabled(enabled); } }, _parent: { get: function () { return this.getparent(); }, set: function (parent) { this.setparent(parent); } }, parent: { get: function () { return this.getparent(); }, set: function (parent) { this.setparent(parent); } } }); /** * initialize */ displayobject.prototype.initialize = function () { var _this = this; // common _this.instanceid = instanceid++; _this.characterid = 0; _this.tagtype = 0; _this.ratio = 0; _this.ismask = false; _this.clipdepth = 0; _this.isclipdepth = false; _this.stageid = null; _this.loadstageid = null; _this.variables = {}; _this.buttonstatus = "up"; _this.removeflag = false; _this.parentid = null; // properties _this.__visible = true; _this.__name = null; _this._url = null; _this._highquality = 1; _this._focusrect = 1; _this._soundbuftime = null; _this._totalframes = 1; _this._level = 0; _this._depth = null; _this._framesloaded = 0; _this._target = ""; _this._lockroot = undefined; _this._enabled = true; _this._blendmode = null; _this._filters = null; _this._filtercachekey = null; _this._parentplace = null; _this._mask = null; _this._matrix = null; _this._colortransform = null; _this._extend = false; // avm2 _this.avm2 = null; }; // filters displayobject.prototype.flash = { filters: { dropshadowfilter: dropshadowfilter, blurfilter: blurfilter, glowfilter: glowfilter, bevelfilter: bevelfilter, gradientglowfilter: gradientglowfilter, convolutionfilter: convolutionfilter, colormatrixfilter: colormatrixfilter, gradientbevelfilter: gradientbevelfilter, bitmapfilter: bitmapfilter } }; /** * @returns {string} */ displayobject.prototype.tostring = function () { var target = this.gettarget(); var str = "_level0"; var array = target.split("/"); str += array.join("."); return str; }; /** * @param a * @param b * @returns [] */ displayobject.prototype.multiplicationmatrix = function(a, b) { return [ a[0] * b[0] + a[2] * b[1], a[1] * b[0] + a[3] * b[1], a[0] * b[2] + a[2] * b[3], a[1] * b[2] + a[3] * b[3], a[0] * b[4] + a[2] * b[5] + a[4], a[1] * b[4] + a[3] * b[5] + a[5] ]; }; /** * @param a * @param b * @returns [] */ displayobject.prototype.multiplicationcolor = function(a, b) { return [ a[0] * b[0], a[1] * b[1], a[2] * b[2], a[3] * b[3], a[0] * b[4] + a[4], a[1] * b[5] + a[5], a[2] * b[6] + a[6], a[3] * b[7] + a[7] ]; }; /** * @param bounds * @param matrix * @param object * @returns {{xmin: number, xmax: number, ymin: number, ymax: number}} */ displayobject.prototype.boundsmatrix = function (bounds, matrix, object) { var no = _number.max_value; var xmax = -no; var ymax = -no; var xmin = no; var ymin = no; if (object) { xmin = object.xmin; xmax = object.xmax; ymin = object.ymin; ymax = object.ymax; } var x0 = bounds.xmax * matrix[0] + bounds.ymax * matrix[2] + matrix[4]; var x1 = bounds.xmax * matrix[0] + bounds.ymin * matrix[2] + matrix[4]; var x2 = bounds.xmin * matrix[0] + bounds.ymax * matrix[2] + matrix[4]; var x3 = bounds.xmin * matrix[0] + bounds.ymin * matrix[2] + matrix[4]; var y0 = bounds.xmax * matrix[1] + bounds.ymax * matrix[3] + matrix[5]; var y1 = bounds.xmax * matrix[1] + bounds.ymin * matrix[3] + matrix[5]; var y2 = bounds.xmin * matrix[1] + bounds.ymax * matrix[3] + matrix[5]; var y3 = bounds.xmin * matrix[1] + bounds.ymin * matrix[3] + matrix[5]; xmax = _max(_max(_max(_max(xmax, x0), x1), x2), x3); xmin = _min(_min(_min(_min(xmin, x0), x1), x2), x3); ymax = _max(_max(_max(_max(ymax, y0), y1), y2), y3); ymin = _min(_min(_min(_min(ymin, y0), y1), y2), y3); return {xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax}; }; /** * @param color * @param data * @returns {{r: number, g: number, b: number, a: number}} */ displayobject.prototype.generatecolortransform = function (color, data) { return { r: _max(0, _min((color.r * data[0]) + data[4], 255))|0, g: _max(0, _min((color.g * data[1]) + data[5], 255))|0, b: _max(0, _min((color.b * data[2]) + data[6], 255))|0, a: _max(0, _min((color.a * 255 * data[3]) + data[7], 255)) / 255 }; }; /** * @param src * @returns {array} */ displayobject.prototype.clonearray = function(src) { var arr = []; var length = src.length; for (var i = 0; i < length; i++) { arr[i] = src[i]; } return arr; }; /** * @param blendmode * @returns {string} */ displayobject.prototype.getblendname = function (blendmode) { var mode = null; switch (blendmode) { case 1: case "normal": mode = "normal"; break; case 2: case "layer": mode = "layer"; break; case 3: case "multiply": mode = "multiply"; break; case 4: case "screen": mode = "screen"; break; case 5: case "lighten": mode = "lighten"; break; case 6: case "darken": mode = "darken"; break; case 7: case "difference": mode = "difference"; break; case 8: case "add": mode = "add"; break; case 9: case "subtract": mode = "subtract"; break; case 10: case "invert": mode = "invert"; break; case 11: case "alpha": mode = "alpha"; break; case 12: case "erase": mode = "erase"; break; case 13: case "overlay": mode = "overlay"; break; case 14: case "hardlight": mode = "hardlight"; break; } return mode; }; /** * @param stage */ displayobject.prototype.setstage = function (stage) { var _this = this; _this.stageid = stage.getid(); if (_this instanceof simplebutton) { var upstate = _this.getsprite("up"); upstate.setstage(stage); var downstate = _this.getsprite("down"); downstate.setstage(stage); var hitstate = _this.getsprite("hit"); hitstate.setstage(stage); var overstate = _this.getsprite("over"); overstate.setstage(stage); } stage.setinstance(_this); }; /** * @returns {*} */ displayobject.prototype.getstage = function () { var _this = this; var stage = _this.getloadstage(); if (!stage) { stage = _this.getparentstage(); } return stage; }; /** * @returns {*} */ displayobject.prototype.getparentstage = function () { var stageid = this.stageid; if (stageid !== null) { if (stageid in stages) { return stages[stageid]; } else { return loadstages[stageid]; } } }; /** * @returns {*} */ displayobject.prototype.getloadstage = function () { var loadstageid = this.loadstageid; if (loadstageid !== null) { if (loadstageid in stages) { return stages[loadstageid]; } else { return loadstages[loadstageid]; } } }; /** * @param stage */ displayobject.prototype.setloadstage = function (stage) { var _this = this; _this.loadstageid = null; if (stage !== null) { stage.setinstance(_this); _this.loadstageid = stage.getid(); } }; /** * @returns {number} */ displayobject.prototype.getcharacterid = function () { return this.characterid; }; /** * @param characterid */ displayobject.prototype.setcharacterid = function (characterid) { this.characterid = characterid; }; /** * @returns {number} */ displayobject.prototype.gettagtype = function () { return this.tagtype; }; /** * @param tagtype */ displayobject.prototype.settagtype = function (tagtype) { this.tagtype = tagtype; }; /** * @returns {number} */ displayobject.prototype.getratio = function () { return this.ratio; }; /** * @param ratio */ displayobject.prototype.setratio = function (ratio) { this.ratio = ratio; }; /** * @returns {*} */ displayobject.prototype.getparent = function () { var _this = this; var stage = _this.getloadstage(); var parent; var pid = _this.parentid; if (stage) { parent = stage.getinstance(pid); } if (!parent) { stage = _this.getparentstage(); parent = stage.getinstance(pid); } return parent; }; /** * @param parent */ displayobject.prototype.setparent = function (parent) { var _this = this; if (parent instanceof displayobjectcontainer) { parent.setinstance(_this); } _this.parentid = parent.instanceid; }; /** * @returns {*} */ displayobject.prototype.getparentsprite = function () { var _this = this; var stage = _this.getstage(); return stage.getinstance(_this._sprite); }; /** * @param sprite */ displayobject.prototype.setparentsprite = function (sprite) { this._sprite = sprite.instanceid; }; /** * @returns {*} */ displayobject.prototype.getbuttonstatus = function () { return this.buttonstatus; }; /** * @param status */ displayobject.prototype.setbuttonstatus = function (status) { this.buttonstatus = status; }; /** * @returns {*} */ displayobject.prototype.getmask = function () { return this._mask; }; /** * @param obj */ displayobject.prototype.setmask = function (obj) { var _this = this; var maskmc = _this._mask; if (maskmc) { maskmc.ismask = false; } obj.ismask = true; _this._mask = obj; }; /** * @returns {*} */ displayobject.prototype.getenabled = function () { return this._enabled; }; /** * @param enabled */ displayobject.prototype.setenabled = function (enabled) { this._enabled = enabled; }; /** * @returns {boolean} */ displayobject.prototype.getbuttonmode = function () { return this._buttonmode; }; /** * @param buttonmode */ displayobject.prototype.setbuttonmode = function (buttonmode) { this._buttonmode = buttonmode; }; /** * @returns {string} */ displayobject.prototype.gettarget = function () { return this._target; }; /** * @param target */ displayobject.prototype.settarget = function (target) { this._target = target; }; /** * @param path * @returns {{scope: displayobject, target: *}} */ displayobject.prototype.splitpath = function (path) { var _this = this; var scope = _this; var target = path; var split; var targetpath = ""; if (typeof path === "string") { if (path.indexof("::") !== -1) { scope = _this; target = path; } else if (path.indexof(":") !== -1) { split = path.split(":"); targetpath = split[0]; target = split[1]; } else if (path.indexof(".") !== -1) { split = path.split("."); target = split.pop(); targetpath += split.join("."); } if (targetpath !== "") { var mc = _this.getdisplayobject(targetpath); if (mc) { scope = mc; } } } return { "scope": scope, "target": target }; }; /** * @param name * @param parse * @returns {undefined} */ displayobject.prototype.getproperty = function (name, parse) { var _this = this; var target = name; if (parse !== false) { var obj = _this.splitpath(name); _this = obj.scope; target = obj.target; } if (_this.removeflag) { return undefined; } var value; var prop = (typeof target === "string") ? target.tolowercase() : target; switch (prop) { case 0: case "_x": value = _this.getx(); break; case 1: case "_y": value = _this.gety(); break; case 2: case "_xscale": value = _this.getxscale(); break; case 3: case "_yscale": value = _this.getyscale(); break; case 4: case "_currentframe": if (_this instanceof movieclip) { value = _this.getcurrentframe(); } break; case 5: case "_totalframes": if (_this instanceof movieclip) { value = _this.gettotalframes(); } break; case 6: case "_alpha": value = _this.getalpha(); break; case 7: case "_visible": value = _this.getvisible(); break; case 8: case "_width": value = _this.getwidth(); break; case 9: case "_height": value = _this.getheight(); break; case 10: case "_rotation": value = _this.getrotation(); break; case 11: case "_target": value = _this.gettarget(); break; case 12: case "_framesloaded": value = _this._framesloaded; break; case 13: case "_name": value = _this.getname(); break; case 14: case "_droptarget": if (_this instanceof movieclip) { value = _this.getdroptarget(); } break; case 15: case "_url": value = _this._url; break; case 16: case "_highquality": value = _this._highquality; break; case 17: case "_focusrect": value = _this._focusrect; break; case 18: case "_soundbuftime": value = _this._soundbuftime; break; case 19: case "_quality": value = _this._quality; break; case 20: case "_xmouse": value = _this.getxmouse(); break; case 21: case "_ymouse": value = _this.getymouse(); break; case "text": case "htmltext": if (_this instanceof textfield) { var variable = _this.getvariable("variable"); if (variable) { var mc = _this.getparent(); value = mc.getproperty(variable); } else { value = _this.getvariable("text"); } } else { value = _this.getvariable(target); } break; case "$version": value = "swf2js 8,0,0"; break; case "enabled": value = _this.getenabled(); break; case "blendmode": value = _this.getblendmode(); break; case "sharedobject": value = new sharedobject(); break; case "key": value = keyclass; break; case "mouse": var _root = _this.getdisplayobject("_root"); var rootstage = _root.getstage(); value = rootstage.mouse; break; default: value = _this.getvariable(target, parse); if (value === undefined && target !== name) { value = _this.getglobalvariable(name); } break; } return value; }; /** * @param name * @param value * @param parse */ displayobject.prototype.setproperty = function (name, value, parse) { var _this = this; var target = name; if (parse !== false) { var obj = _this.splitpath(name); _this = obj.scope; target = obj.target; } var prop = (typeof target === "string") ? target.tolowercase() : target; switch (prop) { case 0: case "_x": _this.setx(value); break; case 1: case "_y": _this.sety(value); break; case 2: case "_xscale": _this.setxscale(value); break; case 3: case "_yscale": _this.setyscale(value); break; case 4: case "_currentframe": case 5: case "_totalframes": case 15: case "_url": case 20: case "_xmouse": case 21: case "_ymouse": case 11: case "_target": case 12: case "_framesloaded": case 14: case "_droptarget": // readonly break; case 6: case "_alpha": _this.setalpha(value); break; case 7: case "_visible": _this.setvisible(value); break; case 8: case "_width": _this.setwidth(value); break; case 9: case "_height": _this.setheight(value); break; case 10: case "_rotation": _this.setrotation(value); break; case 13: case "_name": _this.setname(value); break; case 16: case "_highquality": _this._highquality = value; break; case 17: case "_focusrect": _this._focusrect = value; break; case 18: case "_soundbuftime": _this._soundbuftime = value; break; case 19: case "_quality": _this._quality = value; break; case "text": case "htmltext": if (_this instanceof textfield) { var variable = _this.getvariable("variable"); if (variable) { var mc = _this.getparent(); mc.setproperty(variable, value); } else { _this.setvariable("text", value); } var input = _this.input; if (input) { input.value = value; } } else { _this.setvariable(target, value); } break; case "blendmode": _this.setblendmode(value); break; case "enabled": _this.setenabled(value); break; case "filters": _this.setfilters(value); break; default: _this.setvariable(target, value); break; } }; /** * @returns {number} */ displayobject.prototype.getdepth = function () { var _this = this; var _depth = _this._depth; var depth = (_depth !== null) ? _depth : _this.getlevel(); return depth - 16384; }; /** * @param depth * @param swapdepth * @param swapmc */ displayobject.prototype.setdepth = function (depth, swapdepth, swapmc) { var _this = this; var parent = _this.getparent(); var _depth = _this._depth; var level = (_depth !== null) ? _depth : _this.getlevel(); var totalframe = parent.gettotalframes() + 1; if (!swapmc) { _this._depth = depth; } else { _this._depth = swapdepth; swapmc._depth = depth; } var container = parent.container; var instanceid = _this.instanceid; for (var frame = 1; frame < totalframe; frame++) { if (!(frame in container)) { container[frame] = []; } var tags = container[frame]; if (swapmc) { if (level in tags && tags[level] === instanceid) { tags[depth] = swapmc.instanceid; } if (swapdepth in tags && tags[swapdepth] === swapmc.instanceid) { tags[swapdepth] = instanceid; } } else { if (!(level in tags) || level in tags && tags[level] === instanceid) { delete tags[level]; tags[depth] = instanceid; } } container[frame] = tags; } _this.setcontroller(false, false, false, false); if (swapmc) { swapmc.setcontroller(false, false, false, false); } }; /** * @returns {number} */ displayobject.prototype.getx = function () { var matrix = this.getmatrix(); return (matrix) ? matrix[4] / 20 : undefined; }; /** * @param x */ displayobject.prototype.setx = function (x) { x = +x; if (!_isnan(x)) { var _this = this; var _matrix = _this.getmatrix(); var matrix = _this.clonearray(_matrix); matrix[4] = x * 20; _this.setmatrix(matrix); } }; /** * @returns {*} */ displayobject.prototype.gety = function () { var matrix = this.getmatrix(); return (matrix) ? matrix[5] / 20 : undefined; }; /** * @param y */ displayobject.prototype.sety = function (y) { y = +y; if (!_isnan(y)) { var _this = this; var _matrix = _this.getmatrix(); var matrix = _this.clonearray(_matrix); matrix[5] = y * 20; _this.setmatrix(matrix); } }; /** * @returns {*} */ displayobject.prototype.getxscale = function () { var matrix = this.getmatrix(); var xscale = _sqrt(matrix[0] * matrix[0] + matrix[1] * matrix[1]) * 100; if (0 > matrix[0]) { xscale *= -1; } return xscale; }; /** * @param xscale */ displayobject.prototype.setxscale = function (xscale) { xscale = +xscale; if (!_isnan(xscale)) { var _this = this; var _matrix = _this.getmatrix(); var matrix = _this.clonearray(_matrix); var adjustment = 1; if (0 > matrix[0]) { adjustment = -1; } var radianx = _atan2(matrix[1], matrix[0]); xscale /= 100; matrix[0] = xscale * _cos(radianx) * adjustment; matrix[1] = xscale * _sin(radianx) * adjustment; _this.setmatrix(matrix); } }; /** * @returns {*} */ displayobject.prototype.getyscale = function () { var matrix = this.getmatrix(); var yscale = _sqrt(matrix[2] * matrix[2] + matrix[3] * matrix[3]) * 100; if (0 > matrix[3]) { yscale *= -1; } return yscale; }; /** * @param yscale */ displayobject.prototype.setyscale = function (yscale) { yscale = +yscale; if (!_isnan(yscale)) { var _this = this; var _matrix = _this.getmatrix(); var matrix = _this.clonearray(_matrix); var adjustment = 1; if (0 > matrix[3]) { adjustment = -1; } var radiany = _atan2(-matrix[2], matrix[3]); yscale /= 100; matrix[2] = -yscale * _sin(radiany) * adjustment; matrix[3] = yscale * _cos(radiany) * adjustment; _this.setmatrix(matrix); } }; /** * @returns {number} */ displayobject.prototype.getalpha = function () { var colortransform = this.getcolortransform(); var alpha = colortransform[3] + (colortransform[7] / 255); return alpha * 100; }; /** * @param alpha */ displayobject.prototype.setalpha = function (alpha) { alpha = +alpha; if (!_isnan(alpha)) { var _this = this; var _colortransform = _this.getcolortransform(); var colortransform = _this.clonearray(_colortransform); colortransform[3] = alpha / 100; colortransform[7] = 0; _this.setcolortransform(colortransform); } }; /** * @returns {number} */ displayobject.prototype.getvisible = function () { var _this = this; var stage = _this.getstage(); var version = stage.getversion(); if (version > 4) { return _this.__visible; } return (_this.__visible) ? 1 : 0; }; /** * @param visible */ displayobject.prototype.setvisible = function (visible) { var _this = this; if (typeof visible === "boolean") { _this.__visible = visible; } else { visible = +visible; if (!_isnan(visible)) { _this.__visible = (visible) ? true : false; } } }; /** * @returns {number} */ displayobject.prototype.getlevel = function () { return this._level; }; /** * @param level */ displayobject.prototype.setlevel = function (level) { this._level = level; }; /** * @returns {null} */ displayobject.prototype.getname = function () { return this.__name; }; /** * @param name */ displayobject.prototype.setname = function (name) { this.__name = name; }; /** * @returns {number} */ displayobject.prototype.getrotation = function () { var matrix = this.getmatrix(); var rotation = _atan2(matrix[1], matrix[0]) * 180 / _pi; switch (rotation) { case -90.00000000000001: rotation = -90; break; case 90.00000000000001: rotation = 90; break; } return rotation; }; /** * @param rotation */ displayobject.prototype.setrotation = function (rotation) { rotation = +rotation; if (!_isnan(rotation)) { var _this = this; var _matrix = _this.getmatrix(); var matrix = _this.clonearray(_matrix); var radianx = _atan2(matrix[1], matrix[0]); var radiany = _atan2(-matrix[2], matrix[3]); var scalex = _sqrt(matrix[0] * matrix[0] + matrix[1] * matrix[1]); var scaley = _sqrt(matrix[2] * matrix[2] + matrix[3] * matrix[3]); rotation *= _pi / 180; radiany += rotation - radianx; radianx = rotation; matrix[0] = scalex * _cos(radianx); matrix[1] = scalex * _sin(radianx); matrix[2] = -scaley * _sin(radiany); matrix[3] = scaley * _cos(radiany); _this.setmatrix(matrix); } }; /** * @returns {number} */ displayobject.prototype.getwidth = function () { var _this = this; var matrix = _this.getmatrix(); var bounds = _this.getbounds(matrix); return _abs(bounds.xmax - bounds.xmin); }; /** * @param width */ displayobject.prototype.setwidth = function (width) { width = +width; if (!_isnan(width)) { var _this = this; var _matrix = _this.getoriginmatrix(); var bounds = _this.getbounds(_matrix); var _width = _abs(bounds.xmax - bounds.xmin); var xscale = width * _matrix[0] / _width; if (_isnan(xscale)) { xscale = 0; } _matrix = _this.getmatrix(); var matrix = _this.clonearray(_matrix); matrix[0] = xscale; _this.setmatrix(matrix); } }; /** * @returns {number} */ displayobject.prototype.getheight = function () { var _this = this; var matrix = _this.getmatrix(); var bounds = _this.getbounds(matrix); return _abs(bounds.ymax - bounds.ymin); }; /** * @param height */ displayobject.prototype.setheight = function (height) { height = +height; if (!_isnan(height)) { var _this = this; var _matrix = _this.getoriginmatrix(); var bounds = _this.getbounds(_matrix); var _height = _abs(bounds.ymax - bounds.ymin); var yscale = height * _matrix[3] / _height; if (_isnan(yscale)) { yscale = 0; } _matrix = _this.getmatrix(); var matrix = _this.clonearray(_matrix); matrix[3] = yscale; _this.setmatrix(matrix); } }; /** * @returns {*} */ displayobject.prototype.getxmouse = function () { if (!_event) { return null; } var _this = this; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); var div = _document.getelementbyid(stage.getname()); var bounds = div.getboundingclientrect(); var docbody = _document.body; var x = docbody.scrollleft + bounds.left; var touchx = 0; if (istouch) { var changedtouche = _event.changedtouches[0]; touchx = changedtouche.pagex; } else { touchx = _event.pagex; } var mc = _this; var matrix = _this.getmatrix(); while (true) { var parent = mc.getparent(); if (!parent) { break; } matrix = _this.multiplicationmatrix(parent.getmatrix(), matrix); mc = parent; } var scale = stage.getscale(); touchx -= x; touchx /= scale; touchx -= matrix[4] / 20; return touchx; }; /** * @returns {*} */ displayobject.prototype.getymouse = function () { if (!_event) { return null; } var _this = this; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); var div = _document.getelementbyid(stage.getname()); var bounds = div.getboundingclientrect(); var docbody = _document.body; var y = docbody.scrolltop + bounds.top; var touchy = 0; if (istouch) { var changedtouche = _event.changedtouches[0]; touchy = changedtouche.pagey; } else { touchy = _event.pagey; } var mc = _this; var matrix = _this.getmatrix(); while (true) { var parent = mc.getparent(); if (!parent) { break; } matrix = _this.multiplicationmatrix(parent.getmatrix(), matrix); mc = parent; } var scale = stage.getscale(); touchy -= y; touchy /= scale; touchy -= matrix[5] / 20; return touchy; }; /** * @param name * @param parse * @returns {*} */ displayobject.prototype.getvariable = function (name, parse) { var _this = this; if (name === undefined) { return name; } var variables = _this.variables; if (!variables) { return undefined; } if (name in variables) { return variables[name]; } var stage = _this.getstage(); var version = stage.getversion(); if (version < 7) { for (var key in variables) { if (!variables.hasownproperty(key)) { continue; } if (key.tolowercase() === name.tolowercase()) { return variables[key]; } } } var value; if (version > 4) { var registerclass = variables.registerclass; if (registerclass && typeof registerclass === "object" && name in registerclass ) { return registerclass[name]; } if (_this instanceof movieclip) { value = _this.getdisplayobject(name, parse); if (value) { return value; } } // avm2 var cid = _this.getcharacterid(); var symbol = stage.symbols[cid]; if (symbol) { var symbols = symbol.split("."); var classmethod = symbols.pop(); var slen = symbols.length; var classobj = stage.avm2; for (var sidx = 0; sidx < slen; sidx++) { classobj = classobj[symbols[sidx]]; } var avm2 = classobj[classmethod]; value = avm2[name]; if (value) { return value; } } var _global = stage.getglobal(); value = _global.getvariable(name); if (value) { return value; } if (_this instanceof movieclip && name === "flash") { return _this.flash; } if (name in window) { return window[name]; } } return undefined; }; /** * @param name * @param value */ displayobject.prototype.setvariable = function (name, value) { var _this = this; var variables = _this.variables; var stage = _this.getstage(); if (typeof name !== "string") { name += ""; } if (stage.getversion() < 7) { for (var key in variables) { if (!variables.hasownproperty(key)) { continue; } if (key.tolowercase() !== name.tolowercase()) { continue; } _this.variables[key] = value; return 0; } } _this.variables[name] = value; }; /** * @param path * @returns {*} */ displayobject.prototype.getglobalvariable = function (path) { var _this = this; var stage = _this.getstage(); var version = stage.getversion(); if (version < 5) { return undefined; } var splitdata = null; if (path.indexof(".") !== -1) { splitdata = path.split("."); } var value; if (splitdata) { var _global = stage.getglobal(); var variables = _global.variables; var length = splitdata.length; for (var i = 0; i < length; i++) { var name = splitdata[i]; if (version < 7) { for (var key in variables) { if (!variables.hasownproperty(key)) { continue; } if (key.tolowercase() === name.tolowercase()) { value = variables[key]; break; } } } else { value = variables[name]; } if (!value) { break; } variables = value; } } return value; }; /** * @param path * @param parse * @returns {*} */ displayobject.prototype.getdisplayobject = function (path, parse) { var _this = this; var mc = _this; var _root = mc; var tags, tag, stage, parent; if (!_this._lockroot) { while (true) { parent = _root.getparent(); if (!parent) { break; } _root = parent; } } else { stage = _this.getstage(); _root = stage.getparent(); } if (typeof path !== "string") { path += ""; } if (path === "_root") { return _root; } if (path === "this") { return this; } stage = _root.getstage(); if (path === "_global") { return stage.getglobal(); } parent = mc.getparent(); if (path === "_parent") { return (parent !== null) ? parent : undefined; } var len = 1; var splitdata = [path]; if (parse !== false) { if (path.indexof("/") !== -1) { splitdata = path.split("/"); len = splitdata.length; if (splitdata[0] === "") { mc = _root; } } else if (path.indexof(".") !== -1) { splitdata = path.split("."); len = splitdata.length; if (splitdata[0] === "_root") { mc = _root; } } else if (path.substr(0, 6) === "_level") { var level = path.substr(6); level = +level; if (level === 0) { return _root; } if (!parent) { parent = stage.getparent(); } tags = parent.gettags(); if (level in tags) { var tid = tags[level]; tag = stage.getinstance(tid); if (tag instanceof movieclip) { return tag; } } return undefined; } } var version = stage.getversion(); for (var i = 0; i < len; i++) { var name = splitdata[i]; if (name === "") { continue; } if (name === "_root") { mc = _root; continue; } if (name === "this") { mc = _this; continue; } if (name === "_parent") { parent = mc.getparent(); if (!parent) { return undefined; } mc = parent; continue; } if (name === "..") { mc = mc.getparent(); if (!mc) { return undefined; } continue; } tags = mc.gettags(); if (tags === undefined) { return undefined; } var taglength = tags.length; var settarget = false; if (taglength > 0) { for (var idx in tags) { if (!tags.hasownproperty(idx)) { continue; } var instanceid = tags[idx]; var loadstage = mc.getstage(); tag = loadstage.getinstance(instanceid); if (!tag || tag.removeflag) { continue; } var tagname = tag.getname(); if (!tagname) { continue; } if (version < 7) { if (tagname.tolowercase() === name.tolowercase()) { mc = tag; settarget = true; break; } } else { if (tagname === name) { mc = tag; settarget = true; break; } } } } if (!settarget) { return undefined; } } return mc; }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param visible */ displayobject.prototype.prerender = function (ctx, matrix, colortransform, stage, visible) { var _this = this; _this.isload = true; var cachekey = ""; var prectx = ctx; var prematrix = matrix; var isfilter = false; var isblend = false; var cache, rmatrix, xscale, yscale, xmin, ymin, xmax, ymax; // mask var maskobj = _this.getmask(); if (maskobj) { _this.rendermask(ctx, stage); } // filter if (visible && !stage.clipmc) { var filters = _this.getfilters(); if (filters !== null && filters.length) { isfilter = true; } // blend var blendmode = _this.getblendmode(); if (blendmode !== null && blendmode !== "normal") { isblend = true; } } // filter or blend if (isfilter || isblend) { rmatrix = _this.multiplicationmatrix(stage.getmatrix(), matrix); var bounds; var twips = 1; if (_this instanceof shape || _this instanceof statictext) { bounds = _this.getbounds(); xscale = _sqrt(rmatrix[0] * rmatrix[0] + rmatrix[1] * rmatrix[1]); yscale = _sqrt(rmatrix[2] * rmatrix[2] + rmatrix[3] * rmatrix[3]); } else { twips = 20; bounds = _this.getbounds(matrix); xscale = stage.getscale() * _devicepixelratio; yscale = stage.getscale() * _devicepixelratio; } xmin = bounds.xmin; ymin = bounds.ymin; xmax = bounds.xmax; ymax = bounds.ymax; var width = _abs(_ceil((xmax - xmin) * xscale)); var height = _abs(_ceil((ymax - ymin) * yscale)); var canvas = cachestore.getcanvas(); canvas.width = width; canvas.height = height; cache = canvas.getcontext("2d"); cache._offsetx = 0; cache._offsety = 0; var m2 = [1, 0, 0, 1, -xmin * twips, -ymin * twips]; var m3 = [matrix[0], matrix[1], matrix[2], matrix[3], matrix[4], matrix[5]]; if (_this instanceof shape) { m3[4] = 0; m3[5] = 0; } prectx = cache; prematrix = _this.multiplicationmatrix(m2, m3); } // graphics if (visible) { cachekey += _this.rendergraphics(prectx, prematrix, colortransform, stage); } return { prectx: prectx, prematrix: prematrix, isfilter: isfilter, isblend: isblend, rmatrix: rmatrix, cachekey: cachekey, xmin: xmin * xscale, ymin: ymin * yscale }; }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param obj */ displayobject.prototype.postrender = function(ctx, matrix, colortransform, stage, obj) { var _this = this; var cache = obj.prectx; var isfilter = obj.isfilter; var cachekey = obj.cachekey; if (isfilter && cachekey !== "") { cache = _this.renderfilter(cache, matrix, colortransform, stage, cachekey); } var xmin = obj.xmin; var ymin = obj.ymin; if (_this instanceof shape) { xmin += obj.rmatrix[4]; ymin += obj.rmatrix[5]; } if (cache) { xmin -= cache._offsetx; ymin -= cache._offsety; } _this.renderblend(ctx, cache, xmin, ymin, isfilter); }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @returns {string} */ displayobject.prototype.rendergraphics = function (ctx, matrix, colortransform, stage) { var graphics = this.graphics; var cachekey = ""; if (graphics && graphics.isdraw) { cachekey = graphics.render(ctx, matrix, colortransform, stage); } return cachekey; }; /** * @param ctx * @param stage */ displayobject.prototype.rendermask = function (ctx, stage) { var _this = this; var maskobj = _this.getmask(); if (maskobj) { ctx.save(); ctx.beginpath(); stage.clipmc = true; var mc = maskobj; var matrix = [1,0,0,1,0,0]; var _multiplicationmatrix = _this.multiplicationmatrix; while (true) { var parent = mc.getparent(); if (!parent.getparent()) { break; } matrix = _multiplicationmatrix(parent.getmatrix(), matrix); mc = parent; } maskobj.render(ctx, matrix, [1,1,1,1,0,0,0,0], stage, true); ctx.clip(); stage.clipmc = false; } }; /** * @param filters * @returns {string} */ displayobject.prototype.getfilterkey = function (filters) { var keys = []; var length = filters.length; for (var i = 0; i < length; i++) { var filter = filters[i]; for (var prop in filter) { if (!filter.hasownproperty(prop)) { continue; } keys[keys.length] = filter[prop]; } } return keys.join("_"); }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param cachekey * @returns {*} */ displayobject.prototype.renderfilter = function (ctx, matrix, colortransform, stage, cachekey) { var _this = this; var filters = _this.getfilters(); if (stage.clipmc || !filters || !filters.length) { return ctx; } cachekey += "_" + _this.getfilterkey(filters); var cachestorekey = "filter_" + _this.instanceid; var cache; if (_this._filtercachekey === cachekey) { cache = cachestore.getcache(cachestorekey); } if (!cache) { var flength = filters.length; for (var i = 0; i < flength; i++) { var filter = filters[i]; cache = filter.render(ctx, matrix, colortransform, stage); } _this._filtercachekey = cachekey; cachestore.setcache(cachestorekey, cache); } cachestore.destroy(ctx); return cache; }; /** * @param ctx * @param cache * @param xmin * @param ymin * @param isfilter */ displayobject.prototype.renderblend = function (ctx, cache, xmin, ymin, isfilter) { var _this = this; var mode = _this.getblendmode(); var operation = "source-over"; var canvas = cache.canvas; var width = canvas.width; var height = canvas.height; cache.settransform(1, 0, 0, 1, 0, 0); switch (mode) { case "multiply": operation = "multiply"; break; case "screen": operation = "screen"; break; case "lighten": operation = "lighten"; break; case "darken": operation = "darken"; break; case "difference": operation = "difference"; break; case "add": operation = "lighter"; break; case "subtract": cache.globalcompositeoperation = "difference"; cache.fillstyle = "rgb(255,255,255)"; cache.fillrect(0, 0, width, height); cache.globalcompositeoperation = "darken"; cache.fillstyle = "rgb(255,255,255)"; cache.fillrect(0, 0, width, height); operation = "color-burn"; break; case "invert": cache.globalcompositeoperation = "difference"; cache.fillstyle = "rgb(255,255,255)"; cache.fillrect(0, 0, width, height); cache.globalcompositeoperation = "lighter"; cache.fillstyle = "rgb(255,255,255)"; cache.fillrect(0, 0, width, height); operation = "difference"; break; case "alpha": operation = "source-over"; break; case "erase": operation = "destination-out"; break; case "overlay": operation = "overlay"; break; case "hardlight": operation = "hard-light"; break; } ctx.globalalpha = 1; ctx.globalcompositeoperation = operation; ctx.settransform(1, 0, 0, 1, 0, 0); ctx.drawimage(canvas, xmin, ymin, canvas.width, canvas.height); ctx.globalcompositeoperation = "source-over"; if (!isfilter) { cachestore.destroy(cache); } }; /** * @returns {*} */ displayobject.prototype.getoriginmatrix = function () { var _this = this; var controller = _this.getcontroller(); return controller.getmatrix(); }; /** * @returns [] */ displayobject.prototype.getmatrix = function () { return this._matrix || this.getoriginmatrix(); }; /** * @param matrix */ displayobject.prototype.setmatrix = function (matrix) { var _this = this; _this._matrix = matrix; _this.setcontroller(true, false, false, false); }; /** * @returns {*} */ displayobject.prototype.getorigincolortransform = function () { var _this = this; var controller = _this.getcontroller(); return controller.getcolortransform(); }; /** * @returns [] */ displayobject.prototype.getcolortransform = function () { return this._colortransform || this.getorigincolortransform(); }; /** * @param colortransform */ displayobject.prototype.setcolortransform = function (colortransform) { var _this = this; _this._colortransform = colortransform; _this.setcontroller(false, true, false, false); }; /** * @returns {string} */ displayobject.prototype.getoriginblendmode = function () { var _this = this; var controller = _this.getcontroller(); return controller.getblendmode(); }; /** * @returns {string} */ displayobject.prototype.getblendmode = function () { return this._blendmode || this.getoriginblendmode(); }; /** * @param blendmode */ displayobject.prototype.setblendmode = function (blendmode) { var _this = this; var mode = _this.getblendname(blendmode); if (mode !== null) { _this._blendmode = mode; _this.setcontroller(false, false, false, true); } }; /** * @returns {array} */ displayobject.prototype.getoriginfilters = function () { var _this = this; var controller = _this.getcontroller(); return controller.getfilters(); }; /** * @returns {array} */ displayobject.prototype.getfilters = function () { return this._filters || this.getoriginfilters(); }; /** * @param filters */ displayobject.prototype.setfilters = function (filters) { var _this = this; _this._filtercachekey = null; _this._filters = filters; _this.setcontroller(false, false, true, false); }; /** * @param ismatrix * @param iscolortransform * @param isfilters * @param isblend */ displayobject.prototype.setcontroller = function (ismatrix, iscolortransform, isfilters, isblend) { var _this = this; if (!ismatrix) { var _matrix = _this._matrix; if (_matrix === null) { _matrix = _this.getmatrix(); _this._matrix = _this.clonearray(_matrix); } } if (!iscolortransform) { var _colortransform = _this._colortransform; if (_colortransform === null) { _colortransform = _this.getcolortransform(); _this._colortransform = _this.clonearray(_colortransform); } } if (!isfilters) { var _filters = _this._filters; if (_filters === null) { _filters = _this.getfilters(); if (_filters === null) { _filters = []; } _this._filters = _filters; } } if (!isblend) { var _blendmode = _this._blendmode; if (_blendmode === null) { _blendmode = _this.getblendmode(); _this._blendmode = _blendmode; } } }; /** * @returns {placeobject} */ displayobject.prototype.getcontroller = function () { var _this = this; var frame = 0; var depth = _this.getlevel(); var stage = _this.getparentstage(); if (!stage) { return new placeobject(); } var parent = _this.getparentsprite(); if (!parent) { parent = _this.getparent(); } if (!parent) { return new placeobject(); } if (parent instanceof movieclip) { frame = parent.getcurrentframe(); } var placeobject = stage.getplaceobject(parent.instanceid, depth, frame); if (!placeobject) { stage = _this.getloadstage(); if (stage) { placeobject = stage.getplaceobject(parent.instanceid, depth, frame); } } return placeobject || new placeobject(); }; /** * reset */ displayobject.prototype.reset = function () { var _this = this; _this.active = false; _this.ismask = false; _this._matrix = null; _this._colortransform = null; _this._filters = null; _this._blendmode = null; _this._depth = null; _this.setvisible(true); _this.setenabled(true); _this.setbuttonstatus("up"); if (_this instanceof textfield) { var input = _this.input; if (_this.inputactive) { _this.inputactive = false; input.onchange = null; var stage = _this.getstage(); var div = _document.getelementbyid(stage.getname()); if (div) { var el = _document.getelementbyid(_this.gettagname()); if (el) { try { div.removechild(el); } catch (e) { } } } } _this.variables.text = _this.initialtext; } }; /** * trace */ displayobject.prototype.trace = function () { var params = ["[trace]"]; var length = arguments.length; for (var i = 0; i < length; i++) { params[params.length] = arguments[i]; } console.log.apply(window, params); }; /** * @constructor */ var interactiveobject = function () { var _this = this; _this._mouseenabled = true; displayobject.call(_this); }; /** * extends * @type {displayobject} */ interactiveobject.prototype = object.create(displayobject.prototype); interactiveobject.prototype.constructor = interactiveobject; /** * properties */ object.defineproperties(displayobject.prototype, { mouseenabled: { get: function () { return this.getmouseenabled(); }, set: function (mouseenabled) { this.setmouseenabled(mouseenabled); } } }); /** * @returns {boolean} */ interactiveobject.prototype.getmouseenabled = function () { return this._mouseenabled; }; /** * @param mouseenabled */ interactiveobject.prototype.setmouseenabled = function (mouseenabled) { this._mouseenabled = mouseenabled; }; /** * @constructor */ var textsnapshot = function () { this.charcount = 0; }; /** * @param beginindex * @param texttofind * @param casesensitive */ textsnapshot.prototype.findtext = function (beginindex, texttofind, casesensitive) { }; /** * @param beginindex * @param endindex */ textsnapshot.prototype.getselected = function (beginindex, endindex) { }; /** * @param includelineendings */ textsnapshot.prototype.getselectedtext = function (includelineendings) { }; textsnapshot.prototype.gettext = function (beginindex, endindex, includelineendings) { }; /** * @param beginindex * @param endindex */ textsnapshot.prototype.gettextruninfo = function (beginindex, endindex) { }; /** * @param x * @param y * @param maxdistance */ textsnapshot.prototype.hittesttextnearpos = function (x, y, maxdistance) { }; /** * @param hexcolor */ textsnapshot.prototype.setselectcolor = function (hexcolor) { }; /** * @param beginindex * @param endindex * @param select */ textsnapshot.prototype.setselected = function (beginindex, endindex, select) { }; /** * @constructor */ var displayobjectcontainer = function () { var _this = this; interactiveobject.call(_this); _this._mousechildren = true; _this._tabchildren = true; _this._textsnapshot = new textsnapshot(); _this._numchildren = 0; _this.soundid = null; _this.soundinfo = null; _this.container = []; if (_this instanceof movieclip) { var totalframes = _this.gettotalframes() + 1; var frame = 1; while (frame < totalframes) { _this.container[frame++] = []; } } _this.instances = []; _this.isswap = false; }; /** * extends * @type {interactiveobject} */ displayobjectcontainer.prototype = object.create(interactiveobject.prototype); displayobjectcontainer.prototype.constructor = displayobjectcontainer; /** * properties */ object.defineproperties(displayobjectcontainer.prototype, { mousechildren: { get: function () { return this.getmousechildren(); }, set: function (mousechildren) { this.setmousechildren(mousechildren); } }, textsnapshot: { get: function () { return this.gettextsnapshot(); }, set: function () { } }, numchildren: { get: function () { return this.getnumchildren(); }, set: function () { } }, tabchildren: { get: function () { return this.gettabchildren(); }, set: function (tabchildren) { this.settabchildren(tabchildren); } } }); /** * @returns {boolean} */ displayobjectcontainer.prototype.getmousechildren = function () { return this._mousechildren; }; /** * @param mousechildren */ displayobjectcontainer.prototype.setmousechildren = function (mousechildren) { this._mousechildren = mousechildren; }; /** * @returns {textsnapshot} */ displayobjectcontainer.prototype.gettextsnapshot = function () { return this._textsnapshot; }; /** * @returns {number} */ displayobjectcontainer.prototype.getnumchildren = function () { return this._numchildren; }; /** * @returns {boolean} */ displayobjectcontainer.prototype.gettabchildren = function () { return this._tabchildren; }; /** * @param tabchildren */ displayobjectcontainer.prototype.settabchildren = function (tabchildren) { this._tabchildren = tabchildren; }; /** * @returns {array} */ displayobjectcontainer.prototype.getcontainer = function () { return this.container; }; /** * @returns {array} */ displayobjectcontainer.prototype.getinstances = function () { return this.instances; }; /** * @param instance */ displayobjectcontainer.prototype.setinstance = function (instance) { var instances = this.instances; var instanceid = instance.instanceid; if (!(instanceid in instances)) { instances[instanceid] = 1; } }; /** * @param instance */ displayobjectcontainer.prototype.deleteinstance = function (instance) { delete this.instances[instance.instanceid]; }; /** * @param child * @param depth * @returns {displayobject} */ displayobjectcontainer.prototype.addchild = function (child, depth) { if (child instanceof displayobject) { var _this = this; if (depth === undefined) { depth = _this._numchildren; } var stage = _this.getstage(); child.setparent(_this); child.setstage(stage); child.setlevel(depth); var container = _this.getcontainer(); var frame = 1; var placeobject = new placeobject(); var instanceid = _this.instanceid; if (_this instanceof movieclip) { var totalframes = _this.gettotalframes() + 1; for (; frame < totalframes; frame++) { if (!(frame in container)) { container[frame] = []; } stage.setplaceobject(placeobject, instanceid, depth, frame); container[frame][depth] = child.instanceid; } } else { stage.setplaceobject(placeobject, instanceid, depth, frame); container[depth] = child.instanceid; } _this._numchildren++; } return child; }; /** * @param child * @param depth * @returns {displayobject} */ displayobjectcontainer.prototype.addchildat = function (child, depth) { return this.addchild(child, depth); }; /** * * @param depth * @returns {displayobject} */ displayobjectcontainer.prototype.getchildat = function (depth) { var _this = this; var container = _this.getcontainer(); var children = container; if (16384 > depth) { depth += 16384; } if (_this instanceof movieclip) { var frame = _this.getcurrentframe(); children = container[frame]; } return children[depth]; }; /** * @param name * @return {displayobject} */ displayobjectcontainer.prototype.getchildbyname = function (name) { var _this = this; var container = _this.getcontainer(); var children = container; if (_this instanceof movieclip) { var frame = _this.getcurrentframe(); children = container[frame]; } var obj; for (var depth in children) { if (!children.hasownproperty(depth)) { continue; } var child = children[depth]; if (child.getname() !== name) { continue; } obj = child; break; } return obj; }; /** * @param child * @returns {number} */ displayobjectcontainer.prototype.getchildindex = function (child) { var index; if (child instanceof displayobject) { index = child.getlevel() - 16384; } return index; }; /** * @param child * @return {displayobject} */ displayobjectcontainer.prototype.removechild = function (child) { var _this = this; var container = _this.getcontainer(); var depth, obj; if (_this instanceof movieclip) { var totalframes = _this.gettotalframes() + 1; for (var frame = 1; frame < totalframes; frame++) { if (!(frame in container)) { continue; } var children = container[frame]; for (depth in children) { if (!children.hasownproperty(depth)) { continue; } var instanceid = children[depth]; if (instanceid !== child.instanceid) { continue; } delete container[frame][depth]; break; } } } else { for (depth in container) { if (!container.hasownproperty(depth)) { continue; } obj = container[depth]; if (obj.instanceid !== child.instanceid) { continue; } delete container[depth]; break; } } if (child) { _this.deleteinstance(child); _this._numchildren--; } return child; }; /** * @param depth * @returns {*} */ displayobjectcontainer.prototype.removechildat = function (depth) { var _this = this; var container = _this.getcontainer(); var children = container; if (16384 > depth) { depth += 16384; } var child; if (_this instanceof movieclip) { var totalframes = _this.gettotalframes(); for (var frame = 1; frame < totalframes; frame++) { if (!(frame in container)) { continue; } children = container[frame]; if (!(depth in children)) { continue; } child = children[depth]; delete container[frame][depth]; } } else { child = children[depth]; delete children[depth]; } if (child) { _this._numchildren--; } return child; }; /** * @param depth * @param obj */ displayobjectcontainer.prototype.addtag = function (depth, obj) { var _this = this; _this.container[depth] = obj.instanceid; _this._numchildren++; }; /** * startsound */ displayobjectcontainer.prototype.startsound = function () { var _this = this; var soundid = _this.soundid; if (soundid) { var stage = _this.getstage(); var sound = stage.sounds[soundid]; if (sound) { var audio = _document.createelement("audio"); audio.onload = function () { this.load(); this.preload = "auto"; this.autoplay = false; this.loop = false; }; audio.src = sound.base64; startsound(audio, _this.soundinfo); } } }; /** * reset */ displayobjectcontainer.prototype.reset = function () { var _this = this; var container = _this.container; var length = container.length; if (length) { var stage = _this.getstage(); for (var depth in container) { if (!container.hasownproperty(depth)) { continue; } var instanceid = container[depth]; var obj = stage.getinstance(instanceid); obj.reset(); } } _this.ismask = false; _this._depth = null; _this._matrix = null; _this._colortransform = null; _this._filters = null; _this._blendmode = null; _this.mouseenabled = true; }; /** * @param matrix * @param stage * @param visible * @param mask */ displayobjectcontainer.prototype.sethitrange = function (matrix, stage, visible, mask) { var _this = this; var isvisible = _min(_this.getvisible(), visible); if (_this.getenabled() && isvisible) { var buttonhits = stage.buttonhits; var variables = _this.variables; var events = _this.events; if (events.press !== undefined || events.release !== undefined || events.releaseoutside !== undefined || events.rollover !== undefined || events.rollout !== undefined || events.dragover !== undefined || events.dragout !== undefined || variables.onpress !== undefined || variables.onrelease !== undefined || variables.onrollover !== undefined || variables.onreleaseoutside !== undefined || variables.onrollout !== undefined || variables.ondragover !== undefined || variables.ondragout !== undefined ) { var rmatrix = _this.multiplicationmatrix(matrix, _this.getmatrix()); var bounds = _this.getbounds(rmatrix); buttonhits[buttonhits.length] = { xmax: bounds.xmax, xmin: bounds.xmin, ymax: bounds.ymax, ymin: bounds.ymin, parent: _this, matrix: _this.clonearray(matrix) }; } } }; /** * * @param name * @param depth * @returns {movieclip} */ displayobjectcontainer.prototype.createmovieclip = function (name, depth) { var movieclip = new movieclip(); movieclip = this.addchild(movieclip, depth); if (name) { movieclip.setname(name); } return movieclip; }; /** * @param name * @param depth * @returns {sprite} */ displayobjectcontainer.prototype.createsprite = function (name, depth) { var sprite = new sprite(); sprite = this.addchild(sprite, depth); if (name) { sprite.setname(name); } return sprite; }; /** * @param name * @param depth * @returns {simplebutton} */ displayobjectcontainer.prototype.createbutton = function (name, depth) { var button = new simplebutton(); button = this.addchild(button, depth); if (name) { button.setname(name); } return button; }; /** * @param name * @param width * @param height * @param depth * @returns {textfield} */ displayobjectcontainer.prototype.createtext = function (name, width, height, depth) { var textfield = new textfield(name, depth, width, height); textfield = this.addchild(textfield, depth); textfield.setinitparams(); if (name) { textfield.setname(name); } textfield.size = 12; return textfield; }; /** * @returns {shape} */ displayobjectcontainer.prototype.createshape = function (depth) { var shape = new shape(); this.addchild(shape, depth); return shape; }; /** * @constructor */ var sprite = function () { var _this = this; displayobjectcontainer.call(_this); _this.touchpointid = 0; _this._buttonmode = false; _this._usehandcursor = false; _this._droptarget = null; _this._hitarea = null; _this._graphics = new graphics(); _this._soundtransform = new soundtransform(); }; /** * extends * @type {displayobjectcontainer} */ sprite.prototype = object.create(displayobjectcontainer.prototype); sprite.prototype.constructor = sprite; /** * properties */ object.defineproperties(sprite.prototype, { graphics: { get: function () { return this.getgraphics(); }, set: function () { } }, hitarea: { get: function () { return this.gethitarea(); }, set: function (sprite) { this.sethitarea(sprite); } }, buttonmode: { get: function () { return this.getbuttonmode(); }, set: function (buttonmode) { this.setbuttonmode(buttonmode); } }, soundtransform: { get: function () { return this._soundtransform; }, set: function () { } }, usehandcursor: { get: function () { return this.getusehandcursor(); }, set: function (usehandcursor) { this.setusehandcursor(usehandcursor); } }, droptarget: { get: function () { return this.getdroptarget(); }, set: function () { this.setdroptarget(); } } }); /** * @returns {graphics} */ sprite.prototype.getgraphics = function () { return this._graphics; }; /** * @returns {displayobject} */ sprite.prototype.gethitarea = function () { return this._hitarea; }; /** * @param displayobject */ sprite.prototype.sethitarea = function (displayobject) { this._hitarea = displayobject; }; /** * @returns {boolean} */ sprite.prototype.getusehandcursor = function () { return this._usehandcursor; }; /** * @param usehandcursor */ sprite.prototype.setusehandcursor = function (usehandcursor) { this._usehandcursor = usehandcursor; }; /** * starttouchdrag */ sprite.prototype.starttouchdrag = function (touchpointid, lock, bounds) { this.startdrag(lock); }; /** * @param touchpointid */ sprite.prototype.stoptouchdrag = function (touchpointid) { this.stopdrag(); }; /** * startdrag */ sprite.prototype.startdrag = function () { var args = arguments; var lock = args[0]; var left = args[1]; var top = args[2]; var right = args[3]; var bottom = args[4]; var _this = this; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); var startx = 0; var starty = 0; if (!lock) { startx = _this.getxmouse(); starty = _this.getymouse(); } stage.dragmc = _this; stage.dragrules = { startx: startx, starty: starty, left: left, top: top, right: right, bottom: bottom }; _this.setdroptarget(); }; /** * stopdrag */ sprite.prototype.stopdrag = function () { var _this = this; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); stage.dragmc = null; stage.dragrules = null; _this.setdroptarget(); }; /** * executedrag */ sprite.prototype.executedrag = function () { var _this = this; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); var dragrules = stage.dragrules; var startx = dragrules.startx; var starty = dragrules.starty; var left = dragrules.left; var top = dragrules.top; var right = dragrules.right; var bottom = dragrules.bottom; var x = _this.getx(); var y = _this.gety(); var xmouse = _this.getxmouse(); var ymouse = _this.getymouse(); xmouse -= startx; ymouse -= starty; var movex = x + xmouse; var movey = y + ymouse; if (left === null || left === undefined) { _this.setx(movex); _this.sety(movey); } else { left = +left; top = +top; right = +right; bottom = +bottom; // x if (right < movex) { _this.setx(right); } else if (movex < left) { _this.setx(left); } else { _this.setx(movex); } // y if (bottom < movey) { _this.sety(bottom); } else if (movey < top) { _this.sety(top); } else { _this.sety(movey); } } }; /** * * @returns {null|*} */ sprite.prototype.getdroptarget = function () { return this._droptarget; }; /** * setdroptarget */ sprite.prototype.setdroptarget = function () { var _this = this; _this._droptarget = null; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); var parent = _this.getparent(); if (!parent) { parent = stage.getparent(); } var x = _root.getxmouse(); var y = _root.getymouse(); var tags = parent.gettags(); for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var id = tags[depth]; if (id === _this.instanceid) { continue; } var instance = stage.getinstance(id); if (!(instance instanceof movieclip)) { continue; } var hit = instance.hittest(x, y); if (hit) { _this._droptarget = instance; break; } } }; /** * @returns {array} */ sprite.prototype.gettags = function () { return this.getcontainer(); }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param visible */ sprite.prototype.render = function (ctx, matrix, colortransform, stage, visible) { var _this = this; if (_this.removeflag) { return ""; } _this.isload = true; stage.donetags.unshift(_this); // sound if (_this instanceof movieclip && !_this.soundstopflag) { var sounds = _this.getsounds(); if (sounds !== undefined) { var slen = sounds.length; for (var idx = 0; idx < slen; idx++) { if (!(idx in sounds)) { continue; } var sound = sounds[idx]; _this.startsound(sound); } } } // matrix & colortransform var _multiplicationmatrix = _this.multiplicationmatrix; var rmatrix = _multiplicationmatrix(matrix, _this.getmatrix()); var _multiplicationcolor = _this.multiplicationcolor; var rcolortransform = _multiplicationcolor(colortransform, _this.getcolortransform()); var isvisible = _min(_this.getvisible(), visible); // pre render var obj = _this.prerender(ctx, rmatrix, rcolortransform, stage, visible); var cachekey = obj.cachekey; var prectx = obj.prectx; var prematrix = obj.prematrix; // render var clips = []; var container = _this.gettags(); var length = container.length; var maskobj = _this.getmask(); if (length) { var mystage = _this.getstage(); for (var depth in container) { if (!container.hasownproperty(depth)) { continue; } var instanceid = container[depth]; var instance = mystage.getinstance(instanceid); if (!instance) { continue; } // mask end var clen = clips.length; for (var cidx = 0; cidx < clen; cidx++) { var cdepth = clips[cidx]; if (depth > cdepth) { clips.splice(cidx, 1); ctx.restore(); break; } } // mask start if (instance.isclipdepth) { ctx.save(); ctx.beginpath(); clips[clips.length] = instance.clipdepth; if (instance instanceof movieclip) { stage.isclipdepth = true; } } if (isvisible) { switch (true) { case instance instanceof textfield: case instance instanceof displayobjectcontainer: instance.sethitrange(rmatrix, stage, visible, clen); break; case instance instanceof simplebutton: if (!instance.clipdepth) { instance.sethitrange(rmatrix, stage, visible, clen); } break; default: break; } } // mask if (instance.ismask) { continue; } if (instance.isclipdepth) { if (prematrix[0] === 0) { prematrix[0] = 0.00000000000001; } if (prematrix[3] === 0) { prematrix[3] = 0.00000000000001; } } cachekey += instance.render(prectx, prematrix, rcolortransform, stage, isvisible); if (stage.isclipdepth) { prectx.clip(); stage.isclipdepth = false; } } } if (clips.length || maskobj) { ctx.restore(); } // post render if (obj.isfilter || obj.isblend) { obj.cachekey = cachekey; _this.postrender(ctx, rmatrix, rcolortransform, stage, obj); } return cachekey; }; /** * initframe */ sprite.prototype.initframe = function () {}; /** * @param stage * @param clipevent */ sprite.prototype.putframe = function (stage, clipevent) { var _this = this; _this.active = true; _this.dispatchevent(clipevent, stage); }; /** * @param stage */ sprite.prototype.addactions = function (stage) { var _this = this; var mystage = _this.getstage(); var tags = _this.gettags(); var length = tags.length; if (length) { for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var instance = mystage.getinstance(instanceid); if (!instance) { continue; } instance.addactions(stage); } } }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {boolean} */ sprite.prototype.renderhittest = function (ctx, matrix, stage, x, y) { var _this = this; var loadstage = _this.getstage(); var tags = _this.gettags(); var length = tags.length; var hit = false; var rmatrix = _this.multiplicationmatrix(matrix, _this.getmatrix()); if (length) { for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var obj = loadstage.getinstance(instanceid); hit = obj.renderhittest(ctx, rmatrix, stage, x, y); if (hit) { return hit; } } } var graphics = _this.graphics; if (graphics.isdraw) { return graphics.renderhittest(ctx, rmatrix, stage, x, y); } return hit; }; /** * @param mc * @returns {{xmin: *, xmax: number, ymin: *, ymax: number}} */ sprite.prototype.getrect = function (mc) { var _this = this; if (!mc) { mc = _this; } var bounds = mc.getbounds(mc.getoriginmatrix()); var graphics = _this.graphics; var twips = 20; var maxwidth = graphics.maxwidth / twips; var halfwidth = maxwidth / 2; var xmin = bounds.xmin + halfwidth; var xmax = bounds.xmax - halfwidth; var ymin = bounds.ymin + halfwidth; var ymax = bounds.ymax - halfwidth; return {xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax}; }; /** * @param matrix * @returns {{}} */ sprite.prototype.getbounds = function (matrix) { if (matrix instanceof movieclip) { return matrix.getbounds(matrix.getoriginmatrix()); } var _this = this; var tags = _this.gettags(); var xmax = 0; var ymax = 0; var xmin = 0; var ymin = 0; var graphics = _this.graphics; var isdraw = graphics.isdraw; if (isdraw) { var maxwidth = graphics.maxwidth; var halfwidth = maxwidth / 2; var gbounds = _this.boundsmatrix(graphics.bounds, matrix); var twips = (matrix) ? 20 : 1; xmin = (gbounds.xmin - halfwidth) / twips; xmax = (gbounds.xmax + halfwidth) / twips; ymin = (gbounds.ymin - halfwidth) / twips; ymax = (gbounds.ymax + halfwidth) / twips; } var length = tags.length; var stage = _this.getstage(); if (length) { if (!isdraw) { var no = _number.max_value; xmax = -no; ymax = -no; xmin = no; ymin = no; } var _multiplicationmatrix = _this.multiplicationmatrix; for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var tag = stage.getinstance(instanceid); if (!tag || tag.isclipdepth) { continue; } var matrix2 = (matrix) ? _multiplicationmatrix(matrix, tag.getmatrix()) : tag.getmatrix(); var bounds = tag.getbounds(matrix2); if (!bounds) { continue; } xmin = _min(xmin, bounds.xmin); xmax = _max(xmax, bounds.xmax); ymin = _min(ymin, bounds.ymin); ymax = _max(ymax, bounds.ymax); } } return {xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax}; }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {*} */ sprite.prototype.hitcheck = function (ctx, matrix, stage, x, y) { var _this = this; if (!_this.getenabled() || !_this.getvisible() || !_this.getmouseenabled() ) { return false; } var hitobj; var hit = false; var tags = _this.gettags(); var length = tags.length; var matrix2 = _this.multiplicationmatrix(matrix, _this.getmatrix()); if (length) { var loadstage = _this.getstage(); tags.reverse(); for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var tagid = tags[depth]; var instance = loadstage.getinstance(tagid); if (instance instanceof shape || instance instanceof statictext || instance instanceof textfield ) { hit = instance.renderhittest(ctx, matrix2, stage, x, y); } else { hit = instance.hitcheck(ctx, matrix2, stage, x, y); } if (hit) { hitobj = hit; if (typeof hit !== "object") { var events = _this.events; if (events.press !== undefined || events.release !== undefined || events.releaseoutside !== undefined || events.rollover !== undefined || events.rollout !== undefined || events.dragover !== undefined || events.dragout !== undefined ) { stage.ishit = hit; hitobj = {parent : _this}; } } tags.reverse(); return hitobj; } } tags.reverse(); } var graphics = _this.graphics; if (graphics.isdraw) { hit = graphics.renderhittest(ctx, matrix2, stage, x, y); if (hit) { hitobj = {parent : _this}; } } return hitobj; }; /** * @constructor */ var shape = function () { var _this = this; displayobject.call(_this); _this.data = null; _this._graphics = new graphics(); var no = _number.max_value; _this.setbounds({xmin: no, xmax: -no, ymin: no, ymax: -no}); }; /** * extends * @type {displayobject} */ shape.prototype = object.create(displayobject.prototype); shape.prototype.constructor = shape; /** * properties */ object.defineproperties(shape.prototype, { graphics: { get: function () { return this.getgraphics(); }, set: function () { } } }); /** * dummy */ shape.prototype.addactions = function () {}; shape.prototype.initframe = function () {}; /** * @param stage * @param clipevent */ shape.prototype.putframe = function (stage, clipevent) { var _this = this; _this.active = true; _this.dispatchevent(clipevent, stage); }; /** * @returns {graphics} */ shape.prototype.getgraphics = function () { return this._graphics; }; /** * @returns [] */ shape.prototype.getdata = function () { return this.data; }; /** * @param data */ shape.prototype.setdata = function (data) { this.data = data; }; /** * @returns {{}} */ shape.prototype.getbounds = function (matrix) { var _this = this; var bounds, gbounds; var graphics = _this.graphics; var isdraw = graphics.isdraw; if (matrix) { bounds = _this.boundsmatrix(_this.bounds, matrix); if (isdraw) { gbounds = _this.boundsmatrix(graphics.getbounds(), matrix); bounds.xmin = _min(gbounds.xmin, bounds.xmin); bounds.xmax = _max(gbounds.xmax, bounds.xmax); bounds.ymin = _min(gbounds.ymin, bounds.ymin); bounds.ymax = _max(gbounds.ymax, bounds.ymax); } for (var name in bounds) { if (!bounds.hasownproperty(name)) { continue; } bounds[name] /= 20; } return bounds; } else { bounds = _this.bounds; if (isdraw) { gbounds = graphics.getbounds(); bounds.xmin = _min(gbounds.xmin, bounds.xmin); bounds.xmax = _max(gbounds.xmax, bounds.xmax); bounds.ymin = _min(gbounds.ymin, bounds.ymin); bounds.ymax = _max(gbounds.ymax, bounds.ymax); } return this.bounds; } }; /** * @param bounds */ shape.prototype.setbounds = function (bounds) { this.bounds = bounds; }; /** * @returns {boolean} */ shape.prototype.ismorphing = function () { var tagtype = this.gettagtype(); return (tagtype === 46 || tagtype === 84); }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param visible * @returns {*} */ shape.prototype.render = function (ctx, matrix, colortransform, stage, visible) { var _this = this; stage.donetags.unshift(_this); // colortransform var _multiplicationcolor = _this.multiplicationcolor; var rcolortransform = _multiplicationcolor(colortransform, _this.getcolortransform()); var isvisible = _min(_this.getvisible(), visible); var alpha = rcolortransform[3] + (rcolortransform[7] / 255); var stageclip = stage.clipmc || stage.isclipdepth; if (!stageclip && (!alpha || !isvisible)) { return ""; } // matrix var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); // pre render var obj = _this.prerender(ctx, m2, rcolortransform, stage, isvisible); var cachekey = obj.cachekey; var cache = null; // render var m3 = _multiplicationmatrix(stage.getmatrix(), obj.prematrix); var isclipdepth = _this.isclipdepth || stageclip; if (isclipdepth) { if (m3[0]===0) { m3[0] = 0.00000000000001; } if (m3[3]===0) { m3[3] = 0.00000000000001; } ctx.settransform(m3[0],m3[1],m3[2],m3[3],m3[4],m3[5]); _this.executerender(ctx, _min(m3[0], m3[3]), rcolortransform, isclipdepth, stage); } else { var xscale = _sqrt(m3[0] * m3[0] + m3[1] * m3[1]); var yscale = _sqrt(m3[2] * m3[2] + m3[3] * m3[3]); xscale = _pow(_sqrt2, _ceil(_log(xscale) / _ln2_2 - _log1p)); yscale = _pow(_sqrt2, _ceil(_log(yscale) / _ln2_2 - _log1p)); var bounds = _this.getbounds(); var xmax = bounds.xmax; var xmin = bounds.xmin; var ymax = bounds.ymax; var ymin = bounds.ymin; var w = _abs(_ceil((xmax - xmin) * xscale)); var h = _abs(_ceil((ymax - ymin) * yscale)); if (w <= 0 || h <= 0) { return cachekey; } var canvas; var loadstage = _this.getstage(); var cacheid = _this.getcharacterid() + "_" + loadstage.getid(); if (_this.ismorphing()) { cacheid += "_" + _this.getratio(); } cachekey = cachestore.generatekey("shape", cacheid, [xscale, yscale], rcolortransform); cache = cachestore.getcache(cachekey); if (!cache && stage.getwidth() > w && stage.getheight() > h && cachestore.size > (w * h) ) { canvas = cachestore.getcanvas(); canvas.width = w; canvas.height = h; cache = canvas.getcontext("2d"); var cmatrix = [xscale, 0, 0, yscale, -xmin * xscale, -ymin * yscale]; cache.settransform(cmatrix[0],cmatrix[1],cmatrix[2],cmatrix[3],cmatrix[4],cmatrix[5]); cache = _this.executerender( cache, _min(xscale, yscale), rcolortransform, isclipdepth, stage ); cachestore.setcache(cachekey, cache); } var prectx = obj.prectx; if (cache) { canvas = cache.canvas; var smatrix = [1 / xscale, 0, 0, 1 / yscale, xmin, ymin]; var m4 = _multiplicationmatrix(m3, smatrix); prectx.settransform(m4[0],m4[1],m4[2],m4[3],m4[4],m4[5]); if (isandroid4x && !ischrome) { prectx.fillstyle = stage.context.createpattern(cache.canvas, "no-repeat"); prectx.fillrect(0, 0, w, h); } else { prectx.drawimage(canvas, 0, 0, w, h); } } else { prectx.settransform(m3[0],m3[1],m3[2],m3[3],m3[4],m3[5]); _this.executerender(prectx, _min(m3[0], m3[3]), rcolortransform, isclipdepth, stage); } } // post render cachekey += "_" + m3[4] + "_" + m3[5]; if (obj.isfilter || obj.isblend) { obj.cachekey = cachekey; _this.postrender(ctx, matrix, rcolortransform, stage, obj); } return cachekey; }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {boolean} */ shape.prototype.renderhittest = function (ctx, matrix, stage, x, y) { var _this = this; var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); var graphics = _this.graphics; if (graphics.isdraw) { return graphics.renderhittest(ctx, m2, stage, x, y); } if (!_this.getdata()) { return false; } var m3 = _multiplicationmatrix(stage.getmatrix(), m2); ctx.settransform(m3[0],m3[1],m3[2],m3[3],m3[4],m3[5]); var minscale = _min(m3[0], m3[3]); var shapes = _this.getdata(); var length = shapes.length; var hit = false; for (var idx = 0; idx < length; idx++) { var data = shapes[idx]; var obj = data.obj; var isstroke = (obj.width !== undefined); ctx.beginpath(); var cmd = data.cmd; cmd(ctx); if (isstroke) { ctx.linewidth = _max(obj.width, 1 / minscale); ctx.linecap = "round"; ctx.linejoin = "round"; } hit = ctx.ispointinpath(x, y); if (hit) { return hit; } if ("ispointinstroke" in ctx) { hit = ctx.ispointinstroke(x, y); if (hit) { return hit; } } } return hit; }; /** * @param ctx * @param minscale * @param colortransform * @param isclipdepth * @param stage * @returns {*} */ shape.prototype.executerender = function (ctx, minscale, colortransform, isclipdepth, stage) { var _this = this; var shapes = _this.getdata(); if (!shapes) { return ctx; } var stageclip = stage.clipmc || stage.isclipdepth; var length = shapes.length; var color; var css; var canvas; for (var idx = 0; idx < length; idx++) { var data = shapes[idx]; var obj = data.obj; var styleobj = (!obj.hasfillflag) ? obj : obj.filltype; var cmd = data.cmd; var isstroke = (obj.width !== undefined); if (isclipdepth) { if (isstroke) { continue; } cmd(ctx); continue; } ctx.beginpath(); cmd(ctx); var styletype = styleobj.fillstyletype; switch (styletype) { case 0x00: color = styleobj.color; color = _this.generatecolortransform(color, colortransform); css = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; if (isstroke) { ctx.strokestyle = css; ctx.linewidth = _max(obj.width, 1 / minscale); ctx.linecap = "round"; ctx.linejoin = "round"; ctx.stroke(); } else { ctx.fillstyle = css; ctx.fill(); } break; // gradient case 0x10: case 0x12: case 0x13: var m = styleobj.gradientmatrix; var type = styleobj.fillstyletype; if (type !== 16) { ctx.save(); ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]); css = ctx.createradialgradient(0, 0, 0, 0, 0, 16384); } else { var xy = _this.lineargradientxy(m); css = ctx.createlineargradient(xy[0], xy[1], xy[2], xy[3]); } var records = styleobj.gradient.gradientrecords; var rlength = records.length; for (var ridx = 0; ridx < rlength; ridx++) { var record = records[ridx]; color = record.color; color = _this.generatecolortransform(color, colortransform); var rgba = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; css.addcolorstop(record.ratio, rgba); } if (isstroke) { ctx.strokestyle = css; ctx.linewidth = _max(obj.width, 1 / minscale); ctx.linecap = "round"; ctx.linejoin = "round"; ctx.stroke(); } else { ctx.fillstyle = css; ctx.fill(); } if (type !== 16) { ctx.restore(); } break; // bitmap case 0x40: case 0x41: case 0x42: case 0x43: var width; var height; var loadstage = _this.getstage(); var bitmapid = styleobj.bitmapid; var bmatrix = styleobj.bitmapmatrix; var repeat = (styletype === 0x40 || styletype === 0x42) ? "repeat" : "no-repeat"; var bitmapcachekey = cachestore.generatekey( "bitmap", bitmapid + "_" + loadstage.getid() + "_" + repeat, undefined, colortransform ); var image = cachestore.getcache(bitmapcachekey); if (image === undefined) { image = loadstage.getcharacter(bitmapid); if (!image) { break; } if (colortransform[0] !== 1 || colortransform[1] !== 1 || colortransform[2] !== 1 || colortransform[4] || colortransform[5] || colortransform[6] ) { var imgcanvas = image.canvas; width = imgcanvas.width; height = imgcanvas.height; if (width > 0 && height > 0) { canvas = cachestore.getcanvas(); canvas.width = width; canvas.height = height; var imagecontext = canvas.getcontext("2d"); imagecontext.drawimage(image.canvas, 0, 0, width, height); image = _this.generateimagetransform.call(_this, imagecontext, colortransform); cachestore.setcache(bitmapcachekey, image); } } else { ctx.globalalpha = _max(0, _min((255 * colortransform[3]) + colortransform[7], 255)) / 255; } } if (image) { ctx.save(); canvas = image.canvas; width = canvas.width; height = canvas.height; if (width > 0 && height > 0) { if (styletype === 0x41 || styletype === 0x43) { ctx.clip(); ctx.transform(bmatrix[0], bmatrix[1], bmatrix[2], bmatrix[3], bmatrix[4], bmatrix[5]); ctx.drawimage(canvas, 0, 0, width, height); } else { ctx.fillstyle = stage.context.createpattern(canvas, repeat); ctx.transform(bmatrix[0], bmatrix[1], bmatrix[2], bmatrix[3], bmatrix[4], bmatrix[5]); ctx.fill(); } } ctx.restore(); } break; } } if (isclipdepth && !stageclip) { ctx.clip(); if (isandroid && ischrome) { if (!canvas) { canvas = ctx.canvas; } var cwidth = canvas.width; var cheight = canvas.height; var tmpcanvas = tmpcontext.canvas; canvas = ctx.canvas; tmpcanvas.width = cwidth; tmpcanvas.height = cheight; tmpcontext.drawimage(canvas, 0, 0); ctx.save(); ctx.settransform(1, 0, 0, 1, 0, 0); ctx.beginpath(); ctx.clearrect(0, 0, cwidth + 1, cheight + 1); ctx.drawimage(tmpcanvas, 0, 0); ctx.restore(); tmpcontext.settransform(1,0,0,1,0,0); tmpcontext.clearrect(0, 0, cwidth + 1, cheight + 1); } } var resetcss = "rgba(0,0,0,1)"; ctx.strokestyle = resetcss; ctx.fillstyle = resetcss; ctx.globalalpha = 1; return ctx; }; /** * @param ctx * @param color * @returns {*} */ shape.prototype.generateimagetransform = function (ctx, color) { var canvas = ctx.canvas; var width = canvas.width; var height = canvas.height; var imgdata = ctx.getimagedata(0, 0, width, height); var pxdata = imgdata.data; var idx = 0; var redmultiterm = color[0]; var greenmultiterm = color[1]; var bluemultiterm = color[2]; var alphamultiterm = color[3]; var redaddterm = color[4]; var greenaddterm = color[5]; var blueaddterm = color[6]; var alphaaddterm = color[7]; var length = width * height; if (length > 0) { while (length--) { var r = pxdata[idx++]; var g = pxdata[idx++]; var b = pxdata[idx++]; var a = pxdata[idx++]; pxdata[idx - 4] = _max(0, _min((r * redmultiterm) + redaddterm, 255))|0; pxdata[idx - 3] = _max(0, _min((g * greenmultiterm) + greenaddterm, 255))|0; pxdata[idx - 2] = _max(0, _min((b * bluemultiterm) + blueaddterm, 255))|0; pxdata[idx - 1] = _max(0, _min((a * alphamultiterm) + alphaaddterm, 255)); } } ctx.putimagedata(imgdata, 0, 0); return ctx; }; /** * @param m * @returns {*[]} */ shape.prototype.lineargradientxy = function (m) { var x0 = -16384 * m[0] - 16384 * m[2] + m[4]; var x1 = 16384 * m[0] - 16384 * m[2] + m[4]; var x2 = -16384 * m[0] + 16384 * m[2] + m[4]; var y0 = -16384 * m[1] - 16384 * m[3] + m[5]; var y1 = 16384 * m[1] - 16384 * m[3] + m[5]; var y2 = -16384 * m[1] + 16384 * m[3] + m[5]; var vx2 = x2 - x0; var vy2 = y2 - y0; var r1 = _sqrt(vx2 * vx2 + vy2 * vy2); vx2 /= r1; vy2 /= r1; var r2 = (x1 - x0) * vx2 + (y1 - y0) * vy2; return [x0 + r2 * vx2, y0 + r2 * vy2, x1, y1]; }; /** * @constructor */ var textrecord = function () { var _this = this; _this.color = null; _this.matrix = null; }; /** * @returns {*} */ textrecord.prototype.getcolor = function () { return this.color; }; /** * @param color */ textrecord.prototype.setcolor = function (color) { this.color = color; }; /** * @returns {*} */ textrecord.prototype.getmatrix = function () { return this.matrix; }; /** * @param matrix */ textrecord.prototype.setmatrix = function (matrix) { this.matrix = matrix; }; /** * @returns {array} */ textrecord.prototype.getdata = function () { return this.data; }; /** * @param data */ textrecord.prototype.setdata = function (data) { this.data = data; }; /** * @constructor */ var statictext = function () { var _this = this; displayobject.call(_this); _this.data = null; _this.records = []; }; /** * extends * @type {displayobject} */ statictext.prototype = object.create(displayobject.prototype); statictext.prototype.constructor = statictext; /** * dummy */ statictext.prototype.initframe = function () {}; statictext.prototype.addactions = function () {}; /** * @returns {{}} */ statictext.prototype.getbounds = function (matrix) { var _this = this; if (matrix) { var bounds = _this.boundsmatrix(_this.bounds, matrix); for (var name in bounds) { if (!bounds.hasownproperty(name)) { continue; } bounds[name] /= 20; } return bounds; } else { return _this.bounds; } }; /** * @param bounds */ statictext.prototype.setbounds = function (bounds) { this.bounds = bounds; }; /** * @returns {array|*} */ statictext.prototype.getrecords = function () { return this.records; }; /** * @param record */ statictext.prototype.addrecord = function (record) { var records = this.getrecords(); records[records.length] = record; }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param visible * @return {*} */ statictext.prototype.render = function (ctx, matrix, colortransform, stage, visible) { var _this = this; // colortransform var _multiplicationcolor = _this.multiplicationcolor; var rcolortransform = _multiplicationcolor(colortransform, _this.getcolortransform()); var isvisible = _min(_this.getvisible(), visible); var alpha = rcolortransform[3] + (rcolortransform[7] / 255); var stageclip = stage.clipmc || stage.isclipdepth; if (!stageclip && (!alpha || !isvisible)) { return 0; } // matrix var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); // pre render var obj = _this.prerender(ctx, m2, rcolortransform, stage, visible); var m3 = _multiplicationmatrix(stage.getmatrix(), obj.prematrix); var xscale = _sqrt(m3[0] * m3[0] + m3[1] * m3[1]); var yscale = _sqrt(m3[2] * m3[2] + m3[3] * m3[3]); xscale = _pow(_sqrt2, _ceil(_log(xscale) / _ln2_2 - _log1p)); yscale = _pow(_sqrt2, _ceil(_log(yscale) / _ln2_2 - _log1p)); // render var bounds = _this.getbounds(); var xmax = bounds.xmax; var xmin = bounds.xmin; var ymax = bounds.ymax; var ymin = bounds.ymin; var w = _abs(_ceil((xmax - xmin) * xscale)); var h = _abs(_ceil((ymax - ymin) * yscale)); var isclipdepth = _this.isclipdepth || stageclip; if (w > 0 && h > 0) { var cacheid = _this.getcharacterid() + "_" + _this.getstage().getid(); var cachekey = cachestore.generatekey("text", cacheid, [xscale, yscale], rcolortransform); var cache = cachestore.getcache(cachekey); var canvas; if (!cache && !isclipdepth) { if (stage.getwidth() > w && stage.getheight() > h && cachestore.size > w * h) { canvas = cachestore.getcanvas(); canvas.width = w; canvas.height = h; cache = canvas.getcontext("2d"); var cmatrix = [xscale, 0, 0, yscale, -xmin * xscale, -ymin * yscale]; cache.settransform(cmatrix[0],cmatrix[1],cmatrix[2],cmatrix[3],cmatrix[4],cmatrix[5]); cache = _this.executerender(cache, cmatrix, rcolortransform, false, false); cachestore.setcache(cachekey, cache); } } if (cache) { canvas = cache.canvas; var m4 = _multiplicationmatrix(m3, [1 / xscale, 0, 0, 1 / yscale, xmin, ymin]); ctx.settransform(m4[0],m4[1],m4[2],m4[3],m4[4],m4[5]); if (isandroid4x && !ischrome) { ctx.fillstyle = stage.context.createpattern(cache.canvas, "no-repeat"); ctx.fillrect(0, 0, w, h); } else { ctx.drawimage(canvas, 0, 0, w, h); } } else { ctx.settransform(m3[0],m3[1],m3[2],m3[3],m3[4],m3[5]); _this.executerender(ctx, m3, rcolortransform, isclipdepth, stageclip); } cachekey += "_" + m3[4] + "_" + m3[5]; if (obj.isfilter || obj.isblend) { obj.cachekey = cachekey; _this.postrender(ctx, matrix, rcolortransform, stage, obj); } return cachekey; } return null; }; /** * @param ctx * @param matrix * @param colortransform * @param isclipdepth * @param stageclip * @returns {*} */ statictext.prototype.executerender = function (ctx, matrix, colortransform, isclipdepth, stageclip) { var _this = this; var records = _this.getrecords(); var length = records.length; if (!length) { return ctx; } var _multiplicationmatrix = _this.multiplicationmatrix; var _generatecolortransform = _this.generatecolortransform; for (var i = 0; i < length; i++) { var record = records[i]; var shapes = record.getdata(); var shapelength = shapes.length; if (!shapelength) { continue; } var m2 = _multiplicationmatrix(matrix, record.getmatrix()); ctx.settransform(m2[0],m2[1],m2[2],m2[3],m2[4],m2[5]); var color = record.getcolor(); color = _generatecolortransform(color, colortransform); ctx.fillstyle = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; for (var idx = 0; idx < shapelength; idx++) { var styleobj = shapes[idx]; var cmd = styleobj.cmd; if (!isclipdepth) { ctx.beginpath(); cmd(ctx); ctx.fill(); } else { cmd(ctx); } } } if (isclipdepth && !stageclip) { ctx.clip(); } ctx.globalalpha = 1; return ctx; }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {boolean} */ statictext.prototype.renderhittest = function (ctx, matrix, stage, x, y) { var _this = this; var records = _this.getrecords(); var length = records.length; if (!length) { return false; } var hit = false; var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); var m3 = _multiplicationmatrix(stage.getmatrix(), m2); for (var i = 0; i < length; i++) { var record = records[i]; var shapes = record.getdata(); var shapelength = shapes.length; if (!shapelength) { continue; } var m4 = _multiplicationmatrix(m3, record.getmatrix()); ctx.settransform(m4[0],m4[1],m4[2],m4[3],m4[4],m4[5]); for (var idx = 0; idx < shapelength; idx++) { var styleobj = shapes[idx]; var cmd = styleobj.cmd; ctx.beginpath(); cmd(ctx); hit = ctx.ispointinpath(x, y); if (hit) { return hit; } } } return hit; }; /** * @constructor */ var textformat = function () { var _this = this; _this.align = "left"; _this.font = "'hirakakupron-w3', 'sans-serif'"; _this.size = 8; _this.color = {r: 0, g: 0, b: 0, a: 1}; _this.bold = 0; _this.italic = 0; _this.underline = 0; _this.bullet = 0; _this.kerning = 0; _this.blockindent = 0; _this.indent = 0; _this.leading = 80; _this.leftmargin = 0; _this.rightmargin = 0; _this.letterspacing = 0; _this.tabstops = []; _this.url = null; _this.target = null; }; /** * @param name * @param depth * @param width * @param height * @constructor */ var textfield = function (name, depth, width, height) { var _this = this; interactiveobject.call(_this); if (name) { _this.setname(name); } if (depth) { _this.setlevel(depth); } if (!width) { width = 0; } width *= 20; if (!height) { height = 0; } height *= 20; _this.fontid = 0; _this.bounds = {xmin: 0, xmax: width, ymin: 0, ymax: height}; _this.input = null; _this.inputactive = false; _this.span = null; }; /** * extends * @type {interactiveobject} */ textfield.prototype = object.create(interactiveobject.prototype); textfield.prototype.constructor = textfield; /** * properties */ object.defineproperties(textfield.prototype, { text: { get: function () { return this.variables.text; }, set: function (text) { this.variables.text = text; } }, htmltext: { get: function () { return this.variables.text; }, set: function (text) { this.variables.text = text; } }, size: { get: function () { return this.variables.size; }, set: function (size) { this.variables.size = size; } }, font: { get: function () { return this.variables.font; }, set: function (font) { this.variables.font = font; } }, type: { get: function () { return this.variables.type; }, set: function (type) { this.variables.type = type; if (type === "input") { this.setinputelement(); } } }, multiline: { get: function () { return this.variables.multiline; }, set: function (multiline) { this.variables.multiline = multiline; if (multiline) { this.wordwrap = multiline; } if (this.type === "input") { this.setinputelement(); } } }, wordwrap: { get: function () { return this.variables.wordwrap; }, set: function (wordwrap) { this.variables.wordwrap = wordwrap; if (this.type === "input") { this.setinputelement(); } } }, border: { get: function () { return this.variables.border; }, set: function (border) { this.variables.border = border; } }, bordercolor: { get: function () { return this.variables.bordercolor; }, set: function (color) { if (typeof color === "string") { color = this.colorstringtoint(color); } color = this.inttorgba(color); this.variables.bordercolor = color; } }, background: { get: function () { return this.variables.background; }, set: function (background) { this.variables.background = background; } }, backgroundcolor: { get: function () { return this.variables.backgroundcolor; }, set: function (color) { if (typeof color === "string") { color = this.colorstringtoint(color); } color = this.inttorgba(color); this.variables.backgroundcolor = color; } }, textcolor: { get: function () { return this.variables.textcolor; }, set: function (color) { if (typeof color === "string") { color = this.colorstringtoint(color); } color = this.inttorgba(color); this.variables.textcolor = color; } }, align: { get: function () { return this.variables.align; }, set: function (align) { this.variables.align = align; } }, autosize: { get: function () { return this.variables.autosize; }, set: function (autosize) { this.variables.autosize = autosize; } }, onchanged: { get: function () { return this.variables.onchanged; }, set: function (onchanged) { this.variables.onchanged = onchanged; } } }); /** * @param int * @param alpha * @returns {{r: number, g: number, b: number, a: number}} */ textfield.prototype.inttorgba = function (int, alpha) { alpha = alpha || 100; return { r: (int & 0xff0000) >> 16, g: (int & 0x00ff00) >> 8, b: (int & 0x0000ff), a: (alpha / 100) }; }; /** * @param str * @returns {string} */ textfield.prototype.colorstringtoint = function (str) { var canvas = cachestore.getcanvas(); var ctx = canvas.getcontext("2d"); ctx.fillstyle = str; var color = "0x" + ctx.fillstyle.substr(1); cachestore.destroy(ctx); return color; }; /** * setinitparams */ textfield.prototype.setinitparams = function () { var _this = this; var obj = {}; obj.antialiastype = null; obj.autosize = "none"; obj.background = 0; obj.backgroundcolor = {r: 255, g: 255, b: 255, a: 1}; obj.border = 0; obj.bordercolor = {r: 0, g: 0, b: 0, a: 1}; obj.condensewhite = 0; obj.html = 0; obj.password = 0; obj.embedfonts = 0; obj.gridfittype = "none"; obj.maxchars = null; obj.mousewheelenabled = 0; obj.multiline = 0; obj.selectable = 0; obj.sharpness = 0; obj.textcolor = 0; obj.thickness = 0; obj.type = "dynamic"; obj.wordwrap = 0; obj.text = ""; for (var key in obj) { if (!obj.hasownproperty(key)) { continue; } _this.setproperty(key, obj[key]); } _this.settextformat(new textformat()); }; /** * @returns {string} */ textfield.prototype.gettagname = function () { return "__swf2js_input_element_" + this.instanceid; }; /** * @param format */ textfield.prototype.settextformat = function (format) { var _this = this; for (var name in format) { if (!format.hasownproperty(name)) { continue; } _this.setproperty(name, format[name]); } }; /** * @returns {*} */ textfield.prototype.getbounds = function (matrix) { var _this = this; if (matrix) { var bounds = _this.boundsmatrix(_this.bounds, matrix); for (var name in bounds) { if (!bounds.hasownproperty(name)) { continue; } bounds[name] /= 20; } return bounds; } else { return _this.bounds; } }; /** * @param bounds */ textfield.prototype.setbounds = function (bounds) { this.bounds = bounds; }; /** * inputelemen */ textfield.prototype.setinputelement = function () { var _this = this; var variables = _this.variables; var _root = _this.getdisplayobject("_root"); var stage = _root.getparentstage(); var element = _document.createelement("textarea"); var multiline = variables.multiline; var align = variables.align; var text = _this.initialtext; if (!text) { text = variables.text; } element.onkeypress = null; if (!multiline) { element.onkeypress = function (e) { if (e.keycode === 13) { return false; } }; } element.style.position = "absolute"; element.style.webkitborderradius = "0px"; element.style.padding = "1px"; element.style.margin = "0px"; element.style.webkitappearance = "none"; element.style.resize = "none"; element.style.border = "none"; element.style.overflow = "hidden"; element.style.backgroundcolor = "transparent"; element.style.zindex = 0x7fffffff; element.style.textalign = align; element.value = text; if (typeof text !== "string") { var str = ""; var length = text.length; for (var i = 0; i < length; i++) { var txt = text[i]; str += txt.innertext; if ((i + 1) !== length) { str += "\n"; } } element.value = str; } element.id = _this.gettagname(); var onblur = function (stage, textfield, el) { return function () { textfield.setproperty("text", el.value); textfield.inputactive = false; var div = _document.getelementbyid(stage.getname()); if (div) { var element = _document.getelementbyid(textfield.gettagname()); if (element) { try { div.removechild(element); } catch (e) {} } } }; }; element.onblur = onblur(stage, _this, element); _this.input = element; }; /** * @param matrix * @param stage * @param visible * @param mask */ textfield.prototype.sethitrange = function (matrix, stage, visible, mask) { var _this = this; var type = _this.variables.type; var isvisible = _min(_this.getvisible(), visible); if (type === "input" && isvisible) { var buttonhits = stage.buttonhits; var m2 = _this.multiplicationmatrix(matrix, _this.getmatrix()); var bounds = _this.getbounds(m2); buttonhits[buttonhits.length] = { xmax: bounds.xmax, xmin: bounds.xmin, ymax: bounds.ymax, ymin: bounds.ymin, parent: _this }; } }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param visible */ textfield.prototype.render = function (ctx, matrix, colortransform, stage, visible) { var _this = this; stage.donetags.unshift(_this); // colortransform var _multiplicationcolor = _this.multiplicationcolor; var rcolortransform = _multiplicationcolor(colortransform, _this.getcolortransform()); var isvisible = _min(_this.getvisible(), visible); var stageclip = stage.clipmc || stage.isclipdepth; var alpha = rcolortransform[3] + (rcolortransform[7] / 255); if (!stageclip && (!alpha || !isvisible)) { return 0; } // matrix var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); // pre render var obj = _this.prerender(ctx, m2, rcolortransform, stage, visible); var prectx = obj.prectx; var prematrix = obj.prematrix; var m3 = _multiplicationmatrix(stage.getmatrix(), prematrix); prectx.settransform(m3[0],m3[1],m3[2],m3[3],m3[4],m3[5]); var textcachekey = ["textfield"]; var variables = _this.variables; var text = variables.text; var variable = variables.variable; if (variable) { var parent = _this.getparent(); text = parent.getproperty(variable); if (text === undefined) { text = variables.text; } } if (typeof text === "number") { text += ""; } var html = variables.html; if (html && typeof text === "string") { if (text.indexof("") !== -1) { text = text.replace(new regexp("", "gi"), "\n"); } if (text.indexof("") !== -1) { text = text.replace(new regexp("", "gi"), ""); text = text.replace(new regexp("", "gi"), ""); } var span = _document.createelement("span"); span.innerhtml = text; var tags = span.getelementsbytagname("p"); var domlength = tags.length; if (domlength) { var tagdata = []; for (var d = 0; d < domlength; d++) { tagdata[d] = tags[d]; } text = tagdata; } else { text = span.innertext; } } prectx.textbaseline = "top"; if (text === undefined) { text = ""; } var bounds = _this.getbounds(); var xmax = bounds.xmax; var xmin = bounds.xmin; var ymax = bounds.ymax; var ymin = bounds.ymin; var w = _abs(_ceil(xmax - xmin)); var h = _abs(_ceil(ymax - ymin)); // auto size var scale = stage.getscale(); var autosize = variables.autosize; var wordwrap = variables.wordwrap; var splitdata = (typeof text === "string") ? text.split("\n") : text; var length = splitdata.length; var i, txtobj, measuretext; var txttotalwidth = 0; var txttotalheight = 0; var isautosize = false; var automode = (typeof autosize === "string") ? autosize.tolowercase() : autosize; switch (automode) { default: case "none": case false: case 0: txttotalwidth = w; txttotalheight = h; break; case true: case 1: case "left": case "center": case "right": isautosize = true; break; } var fontdata = _this.getstage().getcharacter(_this.fontid); if (isautosize) { if (variables.embedfonts) { var codetable = fontdata.codetable; var fontadvancetable = fontdata.fontadvancetable; var fontscale = _this.fontscale; txttotalwidth = 0; txttotalheight = (fontdata.fontascent * fontscale) + variables.leading; for (i = 0; i < length; i++) { txtobj = splitdata[i]; if (typeof txtobj !== "string") { var firstchild = txtobj.firstchild; txttotalwidth = _this.getdomwidth(firstchild, codetable, fontadvancetable); } else { var txtlength = txtobj.length; for (var idx = 0; idx < txtlength; idx++) { var index = codetable.indexof(txtobj[idx].charcodeat(0)); if (index === -1) { continue; } txttotalwidth += (fontadvancetable[index] * fontscale); } } } } else { var addh = (variables.size * 20) + variables.leading; txttotalheight = (bounds.ymin + 80); if (wordwrap) { txttotalwidth = w; for (i = 0; i < length; i++) { txtobj = splitdata[i]; if (typeof txtobj === "string") { measuretext = prectx.measuretext(txtobj); var checkw = _ceil(measuretext.width * 20); if (checkw > w) { txttotalheight += _ceil(_ceil(checkw / w) * addh); } } } } else { for (i = 0; i < length; i++) { txtobj = splitdata[i]; if (typeof txtobj === "string") { measuretext = prectx.measuretext(txtobj); txttotalwidth = _max(txttotalwidth, _ceil(measuretext.width * 20)); txttotalheight += addh; } } } txttotalwidth += 80; } } var offsetx = 40; switch (automode) { case "center": offsetx = _ceil((_max(txttotalwidth, w) - _min(txttotalwidth, w)) / 2); break; case "right": offsetx = _ceil(_max(txttotalwidth, w) - _min(txttotalwidth, w)); break; } w = txttotalwidth; h = txttotalheight; if (w > 0 && h > 0) { var isclipdepth = _this.isclipdepth || stageclip; var color; var rx = xmin; var ry = ymin; var m = _this._matrix; if (m) { rx = -xmin; ry = -ymin; var m4 = _multiplicationmatrix(prematrix, [1, 0, 0, 1, xmin, ymin]); m3 = _multiplicationmatrix(stage.getmatrix(), m4); prectx.settransform(m3[0],m3[1],m3[2],m3[3],m3[4],m3[5]); } // border var border = variables.border; if (border && !isclipdepth) { prectx.beginpath(); prectx.rect(rx - offsetx, ry, w, h); color = _this.generatecolortransform(variables.bordercolor, rcolortransform); textcachekey[textcachekey.length] = color; prectx.strokestyle = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; prectx.linewidth = _min(20, 1 / _min(m3[0], m3[3])); prectx.globalalpha = 1; prectx.fillstyle = "rgba(0,0,0,0)"; if (variables.background) { color = _this.generatecolortransform(variables.backgroundcolor, rcolortransform); textcachekey[textcachekey.length] = color; prectx.fillstyle = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; } prectx.fill(); prectx.stroke(); } var textcolor = variables.textcolor; var objrgba = textcolor; if (typeof textcolor === "number") { objrgba = _this.inttorgba(textcolor, 100); } color = _this.generatecolortransform(objrgba, rcolortransform); var fillstyle = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; textcachekey[textcachekey.length] = fillstyle; prectx.fillstyle = fillstyle; // font type var fonttype = ""; if (variables.italic) { fonttype += "italic "; } if (variables.bold) { fonttype += "bold "; } var fontstyle = fonttype + variables.size + "px " + variables.font; textcachekey[textcachekey.length] = fontstyle; prectx.font = fontstyle; if (_this.input !== null) { var input = _this.input; var fontsize = _ceil(variables.size * scale * _min(prematrix[0], prematrix[3])); input.style.font = fonttype + fontsize + "px " + variables.font; input.style.color = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; var as = variables.onchanged; if (as && !input.onchange) { var onchanged = function (stage, origin, clip, el) { return function () { if (clip.active) { clip.setproperty("text", el.value); origin.apply(clip, arguments); stage.executeaction(); } }; }; input.onchange = onchanged(stage, as, _this, input); } } if (text && !isclipdepth) { prectx.save(); prectx.beginpath(); prectx.rect(rx - offsetx, ry, w, (h-40)); prectx.clip(); if (_this.inputactive === false) { if (variables.embedfonts) { _this.renderoutline(prectx, fontdata, splitdata, m3, rx - offsetx, w, fillstyle); } else { _this.rendertext(prectx, splitdata, m3, fonttype, fillstyle); } } prectx.restore(); prectx.globalalpha = 1; } textcachekey[textcachekey.length] = text; var cachekey = cachestore.generatekey( textcachekey.join("_"), _this.getcharacterid(), m3, rcolortransform); obj.cachekey = cachekey; if (obj.isfilter || obj.isblend) { _this.postrender(ctx, matrix, rcolortransform, stage, obj); } return cachekey; } return null; }; /** * @param ctx * @param fontdata * @param splitdata * @param matrix * @param offset * @param width * @param fillstyle */ textfield.prototype.renderoutline = function (ctx, fontdata, splitdata, matrix, offset, width, fillstyle) { var _this = this; var variables = _this.variables; var fontscale = _this.fontscale; var leading = (fontdata.fontascent + fontdata.fontdescent) * fontscale; var rightmargin = variables.rightmargin * fontscale; var leftmargin = variables.leftmargin * fontscale; var indent = variables.indent * fontscale; var align = variables.align; var txt = ""; var codetable = fontdata.codetable; var glyphshapetable = fontdata.glyphshapetable; var fontadvancetable = fontdata.fontadvancetable; var yoffset = (fontdata.fontascent * fontscale); var cacheyoffset = yoffset; var wordwrap = variables.wordwrap; var multiline = variables.multiline; var bounds = _this.getbounds(); var areawidth = (_ceil((bounds.xmax) - (bounds.xmin)) - leftmargin - rightmargin); var idx; var index; var length = splitdata.length; var _multiplicationmatrix = _this.multiplicationmatrix; for (var i = 0; i < length; i++) { var xoffset = offset; var textwidth = 0; var txtlength = 0; var obj = splitdata[i]; var firstchild; if (typeof obj !== "string") { firstchild = obj.firstchild; if (!firstchild) { continue; } textwidth = _this.getdomwidth(firstchild, codetable, fontadvancetable); txt = obj.innertext; align = variables.align; if (obj.align) { align = obj.align; } } else { txt = obj; txtlength = txt.length; for (idx = 0; idx < txtlength; idx++) { index = codetable.indexof(txt[idx].charcodeat(0)); if (index === -1) { continue; } textwidth += (fontadvancetable[index] * fontscale); } } if (align === "right") { xoffset += width - rightmargin - textwidth - 40; } else if (align === "center") { xoffset += indent + leftmargin + 40 + ((width - indent - leftmargin - rightmargin - textwidth) / 2); } else { xoffset += indent + leftmargin + 40; } var cachexoffset = xoffset; var wordwidth = 0; if (typeof obj !== "string") { var griddata = { xoffset: xoffset, yoffset: yoffset, cachexoffset: cachexoffset, cacheyoffset: cacheyoffset, wordwidth: wordwidth, addxoffset: 0, size: firstchild.size, areawidth: areawidth, matrix: matrix }; _this.renderdomoutline( ctx, firstchild, griddata, fillstyle, codetable, fontadvancetable, glyphshapetable ); } else { for (idx = 0; idx < txtlength; idx++) { index = codetable.indexof(txt[idx].charcodeat(0)); if (index === -1) { continue; } var addxoffset = fontadvancetable[index] * fontscale; if (wordwrap && multiline) { if (wordwidth + addxoffset > areawidth) { xoffset = cachexoffset; yoffset += cacheyoffset; wordwidth = 0; } } var m2 = _multiplicationmatrix(matrix, [fontscale, 0, 0, fontscale, xoffset, yoffset]); ctx.settransform(m2[0],m2[1],m2[2],m2[3],m2[4],m2[5]); _this.renderglyph(glyphshapetable[index], ctx); xoffset += addxoffset; wordwidth += addxoffset; } } yoffset += leading; } }; /** * @param ctx * @param child * @param griddata * @param fillstyle * @param codetable * @param fontadvancetable * @param glyphshapetable */ textfield.prototype.renderdomoutline = function ( ctx, child, griddata, fillstyle, codetable, fontadvancetable, glyphshapetable ) { var _this = this; var variables = _this.variables; var wordwrap = variables.wordwrap; var multiline = variables.multiline; var _multiplicationmatrix = _this.multiplicationmatrix; var stage = _this.getstage(); var fonts = stage.fonts; var face = child.face; var fontdata = fonts[face]; var codetable = codetable; var fatable = fontadvancetable; var shapetable = glyphshapetable; var color = fillstyle; if (fontdata) { codetable = fontdata.codetable; fatable = fontdata.fontadvancetable; shapetable = fontdata.glyphshapetable; } if (child.color) { color = child.color; } if (child.size) { griddata.size = child.size; } var childnodes = child.childnodes; var length = childnodes.length; for (var i = 0; i < length; i++) { var node = childnodes[i]; if (node instanceof htmlfontelement) { _this.renderdomoutline( ctx, node, griddata, color, codetable, fatable, shapetable ); } else { var size = griddata.size; var fontscale = size / 1024; var stable; var values = node.nodevalue; if (!values) { continue; } var vlength = values.length; for (var idx = 0; idx < vlength; idx++) { var txt = values[idx]; var index = codetable.indexof(txt.charcodeat(0)); if (index === -1) { index = codetable.indexof(txt.charcodeat(0)); if (index === -1) { continue; } color = fillstyle; griddata.addxoffset = fontadvancetable[index] * fontscale; stable = glyphshapetable; } else { griddata.addxoffset = fatable[index] * fontscale; stable = shapetable; } if (wordwrap && multiline) { if (griddata.wordwidth + griddata.addxoffset > griddata.areawidth) { griddata.xoffset = griddata.cachexoffset; griddata.yoffset += griddata.cacheyoffset; griddata.wordwidth = 0; } } var m2 = [fontscale, 0, 0, fontscale, griddata.xoffset, griddata.yoffset]; var m3 = _multiplicationmatrix(griddata.matrix, m2); ctx.settransform(m3[0], m3[1], m3[2], m3[3], m3[4], m3[5]); ctx.fillstyle = color; _this.renderglyph(stable[index], ctx); griddata.xoffset += griddata.addxoffset; griddata.wordwidth += griddata.addxoffset; } } } }; /** * @param child * @param codetable * @param fontadvancetable * @returns {number} */ textfield.prototype.getdomwidth = function (child, codetable, fontadvancetable) { var _this = this; var fontscale = _this.fontscale; var stage = _this.getstage(); var fonts = stage.fonts; var width = 0; var face = child.face; var fontdata = fonts[face]; var codetable = codetable; var fatable = fontadvancetable; if (fontdata) { codetable = fontdata.codetable; fatable = fontdata.fontadvancetable; } var childnodes = child.childnodes; var length = childnodes.length; for (var i = 0; i < length; i++) { var node = childnodes[i]; if (node instanceof htmlfontelement) { width += _this.getdomwidth(node, codetable, fatable); } else { var values = node.nodevalue; if (!values) { continue; } var vlength = values.length; for (var idx = 0; idx < vlength; idx++) { var txt = values[idx]; var index = codetable.indexof(txt.charcodeat(0)); if (index === -1) { index = codetable.indexof(txt.charcodeat(0)); if (index === -1) { continue; } width += (fontadvancetable[index] * fontscale); } else { width += (fatable[index] * fontscale); } } } } return width; }; /** * @param records * @param ctx */ textfield.prototype.renderglyph = function (records, ctx) { if (!records.data) { records.data = vtc.convert(records); } var shapes = records.data; var shapelength = shapes.length; for (var idx = 0; idx < shapelength; idx++) { var styleobj = shapes[idx]; var cmd = styleobj.cmd; ctx.beginpath(); cmd(ctx); ctx.fill(); } }; /** * @param ctx * @param splitdata * @param matrix * @param fonttype * @param fillstyle */ textfield.prototype.rendertext = function (ctx, splitdata, matrix, fonttype, fillstyle, _x) { var _this = this; var variables = _this.variables; var wordwrap = variables.wordwrap; var multiline = variables.multiline; var leading = variables.leading / 20; var rightmargin = variables.rightmargin / 20; var leftmargin = variables.leftmargin / 20; var indent = variables.indent / 20; var align = variables.align; var bounds = _this.getbounds(); var xmax = bounds.xmax / 20; var xmin = bounds.xmin / 20; var width = _ceil(xmax - xmin); var m2 = [matrix[0] * 20, matrix[1] * 20, matrix[2] * 20, matrix[3] * 20, matrix[4], matrix[5]]; var xscale = _sqrt(m2[0] * m2[0] + m2[1] * m2[1]); var yscale = _sqrt(m2[2] * m2[2] + m2[3] * m2[3]); var scale = _max(xscale, yscale); ctx.settransform(scale,m2[1],m2[2],scale,m2[4],m2[5]); var dx = xmin; var dy = (bounds.ymin / 20) + 2; if (align === "right") { ctx.textalign = "end"; dx += width - rightmargin - 2; } else if (align === "center") { ctx.textalign = "center"; dx += leftmargin + indent + ((width - leftmargin - indent - rightmargin) / 2); } else { dx += 2 + leftmargin + indent; } bounds = _this.getbounds(m2); var areawidth = (bounds.xmax - bounds.xmin) - ((leftmargin - rightmargin) * xscale); areawidth /= scale; var size = variables.size; var length = splitdata.length; for (var i = 0; i < length; i++) { var txt = ""; var obj = splitdata[i]; if (typeof obj !== "string") { txt = obj.innertext; } else { txt = obj; } if (txt === "") { dy += leading + size; continue; } var measuretext = ctx.measuretext(txt); var txttotalwidth = measuretext.width; if (typeof obj === "string") { if (wordwrap || multiline) { if (txttotalwidth > areawidth) { var txtlength = txt.length; var jointxt = ""; var joinwidth = 2 * scale; for (var t = 0; t < txtlength; t++) { var txtone = txt[t]; var textone = ctx.measuretext(txtone); joinwidth += textone.width; jointxt += txtone; var nextone = txt[t+1]; if (nextone) { textone = ctx.measuretext(nextone); joinwidth += textone.width; } if (joinwidth > areawidth || (t + 1) === txtlength) { ctx.filltext(jointxt, dx, dy, _ceil(joinwidth)); joinwidth = 2 * scale; jointxt = ""; dy += leading + size; } else if (nextone) { joinwidth -= textone.width; } } } else { ctx.filltext(txt, dx, dy, txttotalwidth); dy += leading + size; } } else { ctx.filltext(txt, dx, dy, txttotalwidth); dy += leading + size; } } else { var firstchild = obj.firstchild; var griddata = { startdx: dx, dx: dx, clonedy: dy, dy: dy, color: fillstyle, fonttype: fonttype, fillstyle: fillstyle, size: size, scale: scale, originsize: size, txttotalwidth: txttotalwidth, areawidth: areawidth, joinwidth: 0, jointxt: "", offset: 0, offsetarray: [] }; if (griddata.offsetarray.length === 0) { _this.offsetdomtext(ctx, firstchild, griddata); } // reset griddata.dx = dx; griddata.dy = dy; griddata.clonedy = dy; griddata.size = size; griddata.joinwidth = 0; griddata.jointxt = ""; griddata.offset = 0; if (griddata.offsetarray.length > 0) { var offsety = griddata.offsetarray[0]; if (offsety) { griddata.dy += offsety; griddata.clonedy = griddata.dy; } } _this.renderdomtext(ctx, firstchild, griddata); dy = griddata.dy; } } }; /** * @param ctx * @param child * @param griddata */ textfield.prototype.offsetdomtext = function(ctx, child, griddata) { var _this = this; var variables = _this.variables; var wordwrap = variables.wordwrap; var multiline = variables.multiline; var leading = variables.leading / 20; if (child.face) { griddata.face = child.face; } if (child.size) { var size = child.size|0; var changesize = griddata.originsize - size; if (changesize) { griddata.dy += changesize; if (changesize > 0) { griddata.dy -= 4; } else { var offsetarray = griddata.offsetarray; var offset = griddata.offset; var offsetsize = offsetarray[offset]; if (offsetsize) { offsetarray[offset] = _max(offsetsize, ~changesize); } else { offsetarray[offset] = ~changesize; } griddata.dy += 6; } } griddata.size = size; } var childnodes = child.childnodes; var length = childnodes.length; for (var i = 0; i < length; i++) { var node = childnodes[i]; if (node instanceof htmlfontelement) { _this.offsetdomtext(ctx, node, griddata); } else { var txt = node.nodevalue; if (wordwrap && multiline) { if (griddata.txttotalwidth > griddata.areawidth) { var txtlength = txt.length; for (var t = 0; t < txtlength; t++) { var textone = ctx.measuretext(txt[t]); griddata.joinwidth += textone.width; griddata.jointxt += txt[t]; var isover = (griddata.joinwidth > griddata.areawidth); if (isover || (t + 1) === txtlength) { if ((griddata.dx + textone.width) > griddata.areawidth) { griddata.dx = griddata.startdx; griddata.dy += leading + griddata.size; griddata.clonedy = griddata.dy; griddata.joinwidth = 2 * griddata.scale; isover = false; griddata.offset++; } griddata.jointxt = ""; if (isover) { griddata.dx = griddata.startdx; griddata.joinwidth = 22 * griddata.scale; griddata.dy += leading + griddata.size; griddata.clonedy = griddata.dy; griddata.offset++; } } } } else { griddata.dy += leading + griddata.size; griddata.clonedy = griddata.dy; griddata.offset++; } } else { griddata.dy += leading + griddata.size; griddata.clonedy = griddata.dy; griddata.offset++; } var mtext = ctx.measuretext(txt); griddata.dx += mtext.width; griddata.size = griddata.originsize; griddata.dy = griddata.clonedy; } } }; /** * @param ctx * @param child * @param griddata */ textfield.prototype.renderdomtext = function(ctx, child, griddata) { var _this = this; var variables = _this.variables; var wordwrap = variables.wordwrap; var multiline = variables.multiline; var leading = variables.leading / 20; if (child.face) { griddata.face = child.face; } if (child.color) { griddata.color = child.color; } if (child.size) { var size = child.size|0; var changesize = griddata.originsize - size; if (changesize) { griddata.dy += changesize; if (changesize > 0) { griddata.dy -= 4; } else { griddata.dy += 8; } } griddata.size = size; } var offsety; var childnodes = child.childnodes; var length = childnodes.length; for (var i = 0; i < length; i++) { var node = childnodes[i]; if (node instanceof htmlfontelement) { _this.renderdomtext(ctx, node, griddata); } else { ctx.fillstyle = griddata.color; ctx.font = griddata.fonttype + griddata.size + "px " + griddata.face; var text = node.nodevalue; var splits = text.split("\n"); var slen= splits.length; for (var idx = 0; idx < slen; idx++) { griddata.dx = griddata.startdx; var txt = splits[idx]; if (wordwrap && multiline) { if (griddata.txttotalwidth > griddata.areawidth) { var txtlength = txt.length; for (var t = 0; t < txtlength; t++) { var textone = ctx.measuretext(txt[t]); griddata.joinwidth += textone.width; griddata.jointxt += txt[t]; var isover = (griddata.joinwidth > griddata.areawidth); if (isover || (t + 1) === txtlength) { if ((griddata.dx + textone.width) > griddata.areawidth) { isover = 0; griddata.joinwidth = griddata.size; griddata.dx = griddata.startdx; griddata.offset++; griddata.dy += leading + griddata.size; if (griddata.offsetarray.length > 0) { offsety = griddata.offsetarray[griddata.offset]; if (offsety) { griddata.dy += offsety; } } griddata.clonedy = griddata.dy; } ctx.filltext(griddata.jointxt, griddata.dx, griddata.dy, _ceil(griddata.joinwidth)); griddata.jointxt = ""; if (isover) { griddata.dx = griddata.startdx; griddata.joinwidth = griddata.size; griddata.offset++; griddata.dy += leading + griddata.size; if (griddata.offsetarray.length > 0) { offsety = griddata.offsetarray[griddata.offset]; if (offsety) { griddata.dy += offsety; } } griddata.clonedy = griddata.dy; } } } } else { ctx.filltext(txt, griddata.dx, griddata.dy, _ceil(griddata.txttotalwidth)); griddata.offset++; griddata.dy += leading + griddata.size; if (griddata.offsetarray.length > 0) { offsety = griddata.offsetarray[griddata.offset]; if (offsety) { griddata.dy += offsety; } } griddata.clonedy = griddata.dy; } } else { ctx.filltext(txt, griddata.dx, griddata.dy, _ceil(griddata.txttotalwidth)); griddata.offset++; griddata.dy += leading + griddata.size; if (griddata.offsetarray.length > 0) { offsety = griddata.offsetarray[griddata.offset]; if (offsety) { griddata.dy += offsety; } } griddata.clonedy = griddata.dy; } var mtext = ctx.measuretext(txt); griddata.dx += mtext.width; griddata.color = griddata.fillstyle; griddata.size = griddata.originsize; griddata.dy = griddata.clonedy; } } } }; /** * @param stage * @param clipevent */ textfield.prototype.putframe = function (stage, clipevent) { var _this = this; _this.active = true; if (_this.inputactive === false) { _this.dispatchevent(clipevent, stage); } }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {boolean} */ textfield.prototype.renderhittest = function (ctx, matrix, stage, x, y) { var _this = this; var bounds = _this.getbounds(); var xmax = bounds.xmax; var xmin = bounds.xmin; var ymax = bounds.ymax; var ymin = bounds.ymin; var width = _ceil(xmax - xmin); var height = _ceil(ymax - ymin); var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); var m3 = _multiplicationmatrix(stage.getmatrix(), m2); ctx.settransform(m3[0],m3[1],m3[2],m3[3],m3[4],m3[5]); var m = _this._matrix; if (m) { xmin = -xmin; ymin = -ymin; var m4 = _multiplicationmatrix(m2, [1, 0, 0, 1, xmin, ymin]); var m5 = _multiplicationmatrix(stage.getmatrix(), m4); ctx.settransform(m5[0],m5[1],m5[2],m5[3],m5[4],m5[5]); } ctx.beginpath(); ctx.rect(xmin, ymin, width, height); return ctx.ispointinpath(x, y); }; // dummy textfield.prototype.initframe = function () {}; textfield.prototype.addactions = function () {}; textfield.prototype.gettags = function () { return undefined; }; /** * @constructor */ var simplebutton = function () { var _this = this; interactiveobject.call(_this); _this.actions = []; _this._downstate = new sprite(); _this._hitstate = new sprite(); _this._overstate = new sprite(); _this._upstate = new sprite(); }; /** * extends * @type {interactiveobject} */ simplebutton.prototype = object.create(interactiveobject.prototype); simplebutton.prototype.constructor = simplebutton; /** * properties */ object.defineproperties(simplebutton.prototype, { downstate: { get: function () { return this.getsprite("down"); }, set: function (sprite) { this.setsprite("down", sprite); } }, hitstate: { get: function () { return this.getsprite("hit"); }, set: function (sprite) { this.setsprite("hit", sprite); } }, overstate: { get: function () { return this.getsprite("over"); }, set: function (sprite) { this.setsprite("over", sprite); } }, upstate: { get: function () { return this.getsprite("up"); }, set: function (sprite) { this.setsprite("up", sprite); } } }); /** * * @returns {array|actionscript|*|actions} */ simplebutton.prototype.getactions = function () { return this.actions; }; /** * @param actions */ simplebutton.prototype.setactions = function (actions) { this.actions = actions; }; /** * @param status */ simplebutton.prototype.setbuttonstatus = function (status) { var _this = this; if (_this.getbuttonstatus() !== status) { _this.buttonreset(status); } _this.buttonstatus = status; }; /** * @param status * @returns {*} */ simplebutton.prototype.getsprite = function (status) { var _this = this; if (!status) { status = _this.buttonstatus; } status += "state"; return _this["_" + status]; }; /** * @param status * @param sprite */ simplebutton.prototype.setsprite = function (status, sprite) { var _this = this; var stage = _this.getstage(); var level = 0; switch (status) { case "down": level = 1; break; case "hit": level = 2; break; case "over": level = 3; break; case "up": level = 4; break; } stage.setplaceobject(new placeobject(), _this.instanceid, level, 0); sprite.setparent(_this); sprite.setlevel(level); sprite.setstage(stage); var container = sprite.getcontainer(); for (var depth in container) { if (!container.hasownproperty(depth)) { continue; } var instanceid = container[depth]; var obj = stage.getinstance(instanceid); obj.setparentsprite(sprite); } status += "state"; _this["_" + status] = sprite; }; /** * @param matrix * @param status * @returns {{xmin: number, xmax: number, ymin: number, ymax: number}} */ simplebutton.prototype.getbounds = function (matrix, status) { var _this = this; var xmax = 0; var ymax = 0; var xmin = 0; var ymin = 0; var sprite = _this.getsprite(status); var tags = sprite.getcontainer(); var length = tags.length; if (length) { var stage = _this.getstage(); var no = _number.max_value; xmax = -no; ymax = -no; xmin = no; ymin = no; var _multiplicationmatrix = _this.multiplicationmatrix; for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var tag = stage.getinstance(instanceid); if (!tag || tag.isclipdepth) { continue; } var matrix2 = (matrix) ? _multiplicationmatrix(matrix, tag.getmatrix()) : tag.getmatrix(); var bounds = tag.getbounds(matrix2, status); if (!bounds) { continue; } xmin = _min(xmin, bounds.xmin); xmax = _max(xmax, bounds.xmax); ymin = _min(ymin, bounds.ymin); ymax = _max(ymax, bounds.ymax); } } return {xmin: xmin, xmax: xmax, ymin: ymin, ymax: ymax}; }; /** * @param status */ simplebutton.prototype.buttonreset = function (status) { var _this = this; var sprite = _this.getsprite(); var container = sprite.getcontainer(); var nextsprite = _this.getsprite(status); var nextcontainer = nextsprite.getcontainer(); var stage = _this.getstage(); for (var depth in container) { if (!container.hasownproperty(depth)) { continue; } var instanceid = container[depth]; if (depth in nextcontainer && instanceid === nextcontainer[depth]) { continue; } var instance = stage.getinstance(instanceid); if (!instance) { continue; } instance.reset(); } }; /** * @param matrix * @param stage * @param visible * @param mask */ simplebutton.prototype.sethitrange = function (matrix, stage, visible, mask) { var _this = this; var isvisible = _min(_this.getvisible(), visible); if (_this.getenabled() && isvisible) { var buttonhits = stage.buttonhits; // enter if (istouch) { var actions = _this.getactions(); var alen = actions.length; if (alen) { for (var idx = 0; idx < alen; idx++) { var cond = actions[idx]; if (cond.condkeypress === 13) { buttonhits[buttonhits.length] = { button: _this, xmin: 0, xmax: stage.getwidth(), ymin: 0, ymax: stage.getheight(), condkeypress: cond.condkeypress, parent: _this.getparent() }; } } } } var status = "hit"; var hittest = _this.getsprite(status); var hittags = hittest.getcontainer(); if (!hittags.length) { status = "up"; hittest = _this.getsprite(status); hittags = hittest.getcontainer(); } if (hittags.length) { var m2 = _this.multiplicationmatrix(matrix, _this.getmatrix()); var bounds = _this.getbounds(m2, status); if (bounds) { buttonhits[buttonhits.length] = { button: _this, xmin: bounds.xmin, xmax: bounds.xmax, ymin: bounds.ymin, ymax: bounds.ymax, condkeypress: 0, parent: _this.getparent(), matrix: _this.clonearray(matrix) }; } } } }; /** * @param ctx * @param matrix * @param colortransform * @param stage * @param visible */ simplebutton.prototype.render = function (ctx, matrix, colortransform, stage, visible) { var _this = this; // colortransform var _multiplicationcolor = _this.multiplicationcolor; var rcolortransform = _multiplicationcolor(colortransform, _this.getcolortransform()); // matrix var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); // pre render var isvisible = _min(_this.getvisible(), visible); var obj = _this.prerender(ctx, m2, rcolortransform, stage, isvisible); // render var sprite = _this.getsprite(); var rmatrix = _multiplicationmatrix(obj.prematrix, sprite.getmatrix()); var rcolortransform2 = _multiplicationcolor(rcolortransform, sprite.getcolortransform()); isvisible = _min(sprite.getvisible(), visible); var cachekey = obj.cachekey; cachekey += sprite.render(obj.prectx, rmatrix, rcolortransform2, stage, isvisible); // post render if (obj.isfilter || obj.isblend) { obj.cachekey = cachekey; _this.postrender(ctx, matrix, colortransform, stage, obj); } return cachekey; }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {boolean} */ simplebutton.prototype.renderhittest = function (ctx, matrix, stage, x, y) { var _this = this; var sprite = _this.getsprite("hit"); var tags = sprite.getcontainer(); var length = tags.length; if (!length) { return false; } var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); var m3 = _multiplicationmatrix(m2, sprite.getmatrix()); if (length) { var loadstage = _this.getstage(); for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var tag = loadstage.getinstance(instanceid); if (!tag) { continue; } var hit = tag.renderhittest(ctx, m3, stage, x, y); if (hit) { return hit; } } } return false; }; /** * @param ctx * @param matrix * @param stage * @param x * @param y * @returns {*} */ simplebutton.prototype.hitcheck = function (ctx, matrix, stage, x, y) { var _this = this; var sprite = _this.getsprite("hit"); var tags = sprite.getcontainer(); var length = tags.length; if (!length) { return false; } var _multiplicationmatrix = _this.multiplicationmatrix; var m2 = _multiplicationmatrix(matrix, _this.getmatrix()); var m3 = _multiplicationmatrix(m2, sprite.getmatrix()); var hitobj = false; var hit = false; if (length) { var loadstage = _this.getstage(); tags.reverse(); for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var tagid = tags[depth]; var instance = loadstage.getinstance(tagid); if (instance instanceof shape || instance instanceof statictext || instance instanceof textfield ) { hit = instance.renderhittest(ctx, m3, stage, x, y); } else { hit = instance.hitcheck(ctx, m3, stage, x, y); } if (hit) { hitobj = hit; if (typeof hit !== "object") { var events = _this.events; if (events.press !== undefined || events.release !== undefined || events.releaseoutside !== undefined || events.rollover !== undefined || events.rollout !== undefined || events.dragover !== undefined || events.dragout !== undefined ) { stage.ishit = hit; hitobj = { parent : _this.getparent(), button : _this }; } } tags.reverse(); return hitobj; } } tags.reverse(); } return false; }; /** * @see movieclip.addactions */ simplebutton.prototype.addactions = function (stage) { var _this = this; var sprite = _this.getsprite(); var tags = sprite.getcontainer(); var length = tags.length; if (length) { var mystage = _this.getstage(); for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var tag = mystage.getinstance(instanceid); if (!tag) { continue; } tag.addactions(stage); } } }; /** * dummy * @returns {undefined} */ simplebutton.prototype.gettags = function () { return undefined; }; simplebutton.prototype.initframe = function () {}; /** * @constructor */ var movieclip = function () { var _this = this; sprite.call(_this); _this._currentframe = 1; _this.removetags = []; _this.actions = []; _this.labels = []; // flag _this.stopflag = false; _this.isaction = true; // clip _this.isclipdepth = false; _this.clipdepth = 0; // sound _this.sounds = []; _this.soundstopflag = false; }; /** * extends * @type {sprite} */ movieclip.prototype = object.create(sprite.prototype); movieclip.prototype.constructor = movieclip; /** * @param name * @param stage */ movieclip.prototype.dispatchonevent = function (name, stage) { var _this = this; var as = _this.variables[name]; if (as) { _this.setactionqueue(as, stage); } }; /** * @param name * @param depth * @returns {movieclip} */ movieclip.prototype.createemptymovieclip = function (name, depth) { var _this = this; var stage = _this.getstage(); if (name === undefined) { return undefined; } var mc = _this.getdisplayobject(name); if (!mc) { mc = new movieclip(); } depth += 16384; mc.setname(name); mc.setlevel(depth); mc.setparent(_this); mc.setstage(stage); var container = _this.getcontainer(); var totalframes = _this.gettotalframes() + 1; var placeobject = new placeobject(); var instanceid = _this.instanceid; for (var frame = 1; frame < totalframes; frame++) { if (!(frame in container)) { container[frame] = []; } container[frame][depth] = mc.instanceid; stage.setplaceobject(placeobject, instanceid, depth, frame); } return mc; }; /** * @param name * @param depth * @param x * @param y * @param width * @param height * @returns {textfield} */ movieclip.prototype.createtextfield = function (name, depth, x, y, width, height) { if (16384 > depth) { depth += 16384; } var _this = this; var textfield = new textfield(name, depth, width, height); textfield.setx(x); textfield.sety(y); textfield.setparent(_this); textfield.setstage(_this.getstage()); textfield.setinitparams(); var container = _this.getcontainer(); for (var frame in container) { if (!container.hasownproperty(frame)) { continue; } container[frame][depth] = textfield.instanceid; } return textfield; }; /** * @param r * @param g * @param b */ movieclip.prototype.setbackgroundcolor = function (r, g, b) { var _this = this; var stage = _this.getstage(); stage.setbackgroundcolor(r, g, b); }; /** * play */ movieclip.prototype.play = function () { this.stopflag = false; }; /** * stop */ movieclip.prototype.stop = function () { this.stopflag = true; }; /** * @param frame */ movieclip.prototype.gotoandplay = function (frame) { var _this = this; if (!_isnan(frame)) { frame = +frame; } else if (typeof frame === "string") { frame = _this.getlabel(frame); } if (typeof frame === "number" && frame > 0) { _this.setnextframe(frame); _this.play(); } }; /** * @param frame */ movieclip.prototype.gotoandstop = function (frame) { var _this = this; if (typeof frame === "string") { frame = _this.getlabel(frame); } frame |= 0; if (typeof frame === "number" && frame > _this.gettotalframes()) { frame = _this.gettotalframes(); _this.isaction = false; } if (frame > 0) { _this.setnextframe(frame); _this.stop(); } }; /** * stopallsounds */ movieclip.prototype.stopallsounds = function () { var stage = this.getstage(); var loadsounds = stage.loadsounds; var slen = loadsounds.length; var stopsound = function () { this.removeeventlistener("pause", stopsound); this.currenttime = 0; this.loop = false; }; if (slen > 0) { while (slen--) { if (!(slen in loadsounds)) { continue; } var audio = loadsounds[slen]; audio.addeventlistener("pause", stopsound); audio.pause(); } } stage.loadsounds = []; }; /** * @param url * @param target * @param sendvarsmethod * @returns {number} */ movieclip.prototype.loadmovie = function (url, target, sendvarsmethod) { var _this = this; var stage = _this.getstage(); var targetmc = null; if (!target) { target = _this.getname(); targetmc = _this; } if (!targetmc) { if (typeof target === "string") { var _level = target.substr(0, 6); if (_level === "_level") { target = +target.substr(6); } } if (typeof target === "number") { var parent = stage.getparent(); if (!parent) { parent = stage.getparent(); } var tags = parent.gettags(); targetmc = tags[target]; } else { targetmc = _this.getdisplayobject(target); } } if (targetmc) { _this.unloadmovie(targetmc); var xmlhttprequest = new xmlhttprequest(); var targeturl = url; var body = null; if (sendvarsmethod === 2) { var urls = url.split("?"); if (urls[1] !== undefined) { body = urls[1]; } targeturl = urls[0]; xmlhttprequest.open("post", targeturl, true); xmlhttprequest.setrequestheader("content-type", "application/x-www-form-urlencoded"); } else { xmlhttprequest.open("get", targeturl, true); } if (isxhr2) { xmlhttprequest.responsetype = "arraybuffer"; } else { xmlhttprequest.overridemimetype("text/plain; charset=x-user-defined"); } xmlhttprequest.onreadystatechange = function () { var readystate = xmlhttprequest.readystate; var status = xmlhttprequest.status; if (readystate === 4) { switch (status) { case 200: case 304: var _root = _this.getdisplayobject("_root"); var rootstage = _root.getstage(); var data = isxhr2 ? xmlhttprequest.response : xmlhttprequest.responsetext; var loadstage = new stage(); loadstages[loadstage.getid()] = loadstage; targetmc._url = url; targetmc.reset(); loadstage.setparent(targetmc); targetmc.setloadstage(loadstage); loadstage.parse(data, targeturl); loadstage.stop(); if (target === 0 || (typeof target !== "number" && !targetmc.getparent())) { stage.stop(); loadstage.setid(stage.getid()); loadstage.setname(stage.getname()); loadstage.backgroundcolor = stage.backgroundcolor; loadstage.initcanvas(); loadstage.loadstatus = 2; loadstage.loadevent(); delete loadstages[loadstage.getid()]; stages[stage.getid()] = loadstage; stage = null; } var ondata = targetmc.variables.ondata; if (typeof ondata === "function") { loadstage.executeeventaction(ondata, targetmc); } clipevent.type = "data"; targetmc.dispatchevent(clipevent, rootstage); targetmc.addactions(rootstage); break; } } }; xmlhttprequest.send(body); } }; /** * @param target * @returns {number} */ movieclip.prototype.unloadmovie = function (target) { var _this = this; var targetmc = null; if (target instanceof movieclip) { targetmc = target; } else { targetmc = _this.getdisplayobject(target); if (!targetmc) { return 0; } } // delete targetmc.reset(); targetmc.setloadstage(null); targetmc.setstage(_this.getstage()); targetmc.container = []; targetmc.actions = []; targetmc.instances = []; targetmc.labels = []; targetmc.sounds = []; targetmc.removetags = []; targetmc._totalframes = 1; targetmc._url = null; targetmc._lockroot = undefined; var loadstage = targetmc.getstage(); delete loadstages[loadstage.getid()]; }; /** * @param url * @param target * @param method * @returns {*} */ movieclip.prototype.geturl = function (url, target, method) { var _this = this; if (typeof url === "string") { var cmd = url.substr(0, 9); if (cmd === "fscommand") { var values = url.split(":"); cmd = values.pop(); var str = arguments[1]; if (str === undefined) { str = ""; } var stage = _this.getstage(); var fscommand = stage.abc.flash.system.fscommand; return fscommand.apply(stage, [cmd, str]); } } if (target && typeof target === "string") { switch (target.tolowercase()) { case "_self": case "_blank": case "_parent": case "_top": break; case "post": target = "_self"; method = "get"; break; case "get": target = "_self"; method = "get"; break; default: if (!method) { method = "get"; } _this.loadmovie(url, target, method); return 0; } } // form if (method === "post") { var form = _document.createelement("form"); form.action = url; form.method = method; if (target) { form.target = target; } var urls = url.split("?"); if (urls.length > 1) { var pears = urls[1].split("&"); var plen = pears.length; var _encodeuri = encodeuri; for (var pidx = 0; pidx < plen; pidx++) { var pear = pears[pidx].split("="); var input = _document.createelement("input"); input.type = "hidden"; input.name = pear[0]; input.value = _encodeuri(pear[1] || ""); form.appendchild(input); } } _document.body.appendchild(form); form.submit(); } else { var func = new func("location.href = '" + url + "';"); func(); } }; /** * @param url * @param target * @param method */ movieclip.prototype.loadvariables = function (url, target, method) { var _this = this; var targetmc = _this; if (target) { targetmc = _this.getdisplayobject(target); } if (targetmc) { var xmlhttprequest = new xmlhttprequest(); var body = null; if (method === "post") { var urls = url.split("?"); if (urls[1] !== undefined) { body = urls[1]; } xmlhttprequest.open(method, urls[0], true); xmlhttprequest.setrequestheader("content-type", "application/x-www-form-urlencoded"); } else { xmlhttprequest.open("get", url, true); } xmlhttprequest.onreadystatechange = function () { var readystate = xmlhttprequest.readystate; if (readystate === 4) { var status = xmlhttprequest.status; switch (status) { case 200: case 304: var responsetext = decodeuricomponent(xmlhttprequest.responsetext); var pairs = responsetext.split("&"); var length = pairs.length; for (var idx = 0; idx < length; idx++) { var pair = pairs[idx]; var values = pair.split("="); targetmc.setvariable(values[0], values[1]); } var _root = _this.getdisplayobject(); var rootstage = _root.getstage(); var stage = _this.getstage(); var ondata = targetmc.variables.ondata; if (typeof ondata === "function") { stage.executeeventaction(ondata, targetmc); } clipevent.type = "data"; targetmc.dispatchevent(clipevent, rootstage); break; } } }; xmlhttprequest.send(body); } }; /** * @returns {boolean} */ movieclip.prototype.hittest = function () { var _this = this; var targetmc = arguments[0]; var x = 0; var y = 0; var bool = false; if (!(targetmc instanceof movieclip)) { x = arguments[0]; y = arguments[1]; bool = arguments[2]; if (!x || !y) { return false; } } var bounds = _this.gethitbounds(); var xmax = bounds.xmax; var xmin = bounds.xmin; var ymax = bounds.ymax; var ymin = bounds.ymin; if (targetmc instanceof movieclip) { var targetbounds = targetmc.gethitbounds(); var txmax = targetbounds.xmax; var txmin = targetbounds.xmin; var tymax = targetbounds.ymax; var tymin = targetbounds.ymin; return (txmax > xmin && tymax > ymin && xmax > txmin && ymax > tymin); } else { if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) { if (bool) { var matrix = [1,0,0,1,0,0]; var mc = _this; var _multiplicationmatrix = _this.multiplicationmatrix; while (true) { var parent = mc.getparent(); if (!parent.getparent()) { break; } matrix = _multiplicationmatrix(parent.getmatrix(), matrix); mc = parent; } var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); var ctx = stage.hitcontext; var scale = stage.getscale(); x *= scale; y *= scale; y *= _devicepixelratio; x *= _devicepixelratio; return _this.renderhittest(ctx, matrix, stage, x, y); } else { return true; } } return false; } }; /** * @returns {{xmin: *, xmax: *, ymin: *, ymax: *}} * @returns {*} */ movieclip.prototype.gethitbounds = function () { var _this = this; var mc = _this; var matrix = _this.getmatrix(); var _multiplicationmatrix = _this.multiplicationmatrix; while (true) { var parent = mc.getparent(); if (!parent.getparent()) { break; } matrix = _multiplicationmatrix(parent.getmatrix(), matrix); mc = parent; } return _this.getbounds(matrix); }; /** * @param depth * @returns {*} */ movieclip.prototype.getinstanceatdepth = function (depth) { var _this = this; var parent = _this.getparent(); if (!parent) { parent = _this.getdisplayobject("_root"); } var tags = parent.gettags(); depth += 16384; return tags[depth]; }; /** * swapdepths */ movieclip.prototype.swapdepths = function () { var _this = this; var mc = arguments[0]; var depth = 0; var parent = _this.getparent(); if (parent) { var tags = parent.gettags(); if (mc instanceof movieclip) { if (parent === mc.getparent()) { depth = _this.getdepth() + 16384; var swapdepth = mc.getdepth() + 16384; _this.setdepth(depth, swapdepth, mc); } } else { depth = arguments[0]; if (_isnan(depth)) { depth = parent.getnexthighestdepth(); } if (16384 > depth) { depth += 16384; } if (depth in tags) { var id = tags[depth]; if (id !== _this.instanceid) { var stage = _this.getstage(); var instance = stage.getinstance(id); _this.swapdepths(instance); } } else { _this.setdepth(depth, null, null); } } } }; /** * @param id * @param name * @param depth * @param object * @returns {*} */ movieclip.prototype.attachmovie = function (id, name, depth, object) { var movieclip = null; var _this = this; if (_isnan(depth)) { depth = _this.getnexthighestdepth(); } if (depth < 16384) { depth += 16384; } var mc = _this.getdisplayobject(name); if (mc) { mc.removemovieclip(); } var stage = _this.getstage(); var exportassets = stage.exportassets; if (id in exportassets) { var characterid = exportassets[id]; var tag = stage.getcharacter(characterid); if (tag) { movieclip = new movieclip(); movieclip.setstage(stage); movieclip.setparent(_this); movieclip.setcharacterid(characterid); movieclip.setlevel(depth); movieclip.setname(name); movieclip.settarget(_this.gettarget() + "/" + name); // init action var initaction = stage.initactions[characterid]; if (typeof initaction === "function") { movieclip.active = true; initaction.apply(movieclip); movieclip.reset(); } // registerclass var regclass = stage.registerclass[characterid]; if (regclass) { movieclip.variables.registerclass = new regclass(); } var swftag = new swftag(stage, null); swftag.build(tag, movieclip); var placeobject = new placeobject(); var instanceid = _this.instanceid; var totalframe = _this.gettotalframes() + 1; var container = _this.getcontainer(); for (var frame = 1; frame < totalframe; frame++) { if (!(frame in container)) { container[frame] = []; } container[frame][depth] = movieclip.instanceid; stage.setplaceobject(placeobject, instanceid, depth, frame); } if (object) { for (var prop in object) { if (!object.hasownproperty(prop)) { continue; } movieclip.setproperty(prop, object[prop]); } } var _root = _this.getdisplayobject("_root"); var rootstage = _root.getstage(); movieclip.addactions(rootstage); } } return movieclip; }; /** * @returns {number} */ movieclip.prototype.getnexthighestdepth = function () { var depth = 0; var _this = this; var container = _this.getcontainer(); for (var idx in container) { if (!container.hasownproperty(idx)) { continue; } var children = container[idx]; depth = _max(depth, children.length); } if (16384 > depth) { depth = 0; } return depth; }; /** * @returns {*} */ movieclip.prototype.getbytesloaded = function () { var _this = this; var stage = _this.getstage(); var bitio = stage.bitio; return (!bitio) ? stage.filesize : bitio.byte_offset; }; /** * @returns {number|*|filelength} */ movieclip.prototype.getbytestotal = function () { var _this = this; var stage = _this.getstage(); return stage.filesize; }; /** * updateafterevent */ movieclip.prototype.updateafterevent = function () { var _this = this; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); stage.touchrender(); }; /** * @returns {*} */ movieclip.prototype.duplicatemovieclip = function () { var _this = this; var _root = _this.getdisplayobject("_root"); var stage = _root.getstage(); var target = arguments[0]; var name = arguments[1]; var depth = arguments[2]; var targetmc = _this.getdisplayobject(name); var parent; var object; if (!targetmc && stage.getversion() > 4) { target = arguments[0]; depth = arguments[1]; if (_isnan(depth)) { parent = _this.getparent(); if (!parent) { parent = stage.getparent(); } depth = parent.getnexthighestdepth(); } object = arguments[2]; targetmc = _this; } if (16384 > depth) { depth += 16384; } var clonemc; if (targetmc !== undefined && targetmc.getcharacterid() !== 0) { stage = targetmc.getstage(); parent = targetmc.getparent(); if (!parent) { parent = stage.getparent(); } var char = stage.getcharacter(targetmc.characterid); var swftag = new swftag(stage); if (char instanceof array) { clonemc = new movieclip(); clonemc.setstage(stage); clonemc.setparent(parent); clonemc.setlevel(depth); clonemc.settotalframes(targetmc.gettotalframes()); clonemc.setcharacterid(targetmc.characterid); swftag.build(char, clonemc); } else { var tag = { characterid: targetmc.characterid, ratio: 0, depth: depth }; clonemc = swftag.buildobject(tag, parent); } clonemc.setname(target); if (targetmc._matrix) { clonemc._blendmode = targetmc._blendmode; clonemc._filters = targetmc._filters; clonemc._matrix = _this.clonearray(targetmc._matrix); clonemc._colortransform = _this.clonearray(targetmc._colortransform); } var totalframe = parent.gettotalframes() + 1; var container = parent.getcontainer(); var instanceid = parent.instanceid; var placeobjects = stage.placeobjects[instanceid]; var level = targetmc.getlevel(); for (var frame = 1; frame < totalframe; frame++) { if (!(frame in container)) { container[frame] = []; } container[frame][depth] = clonemc.instanceid; if (frame in placeobjects) { var placeobject = placeobjects[frame][level]; if (placeobject) { if (!(frame in placeobjects)) { placeobjects[frame] = []; } placeobjects[frame][depth] = placeobject.clone(); } } } if (object) { for (var prop in object) { if (!object.hasownproperty(prop)) { continue; } clonemc.setproperty(prop, object[prop]); } } clonemc.addactions(stage); } return clonemc; }; /** * @param name */ movieclip.prototype.removemovieclip = function (name) { var _this = this; var targetmc = _this; if (typeof name === "string") { var target = _this.getdisplayobject(name); if (target) { targetmc = target; } } var depth = targetmc.getdepth() + 16384; var level = targetmc.getlevel(); if (targetmc instanceof movieclip && depth >= 16384) { targetmc.reset(); targetmc.removeflag = true; var parent = targetmc.getparent(); var container = parent.getcontainer(); var instanceid = targetmc.instanceid; var tagid; for (var frame = parent.gettotalframes() + 1; --frame;) { if (!(frame in container)) { continue; } var tags = container[frame]; if (depth in tags) { tagid = tags[depth]; if (tagid === instanceid) { delete container[frame][depth]; } } if (depth !== level && 16384 > level) { if (!(level in tags)) { tags[level] = instanceid; } } } } }; /** * initframe */ movieclip.prototype.initframe = function () { var _this = this; _this.active = true; var stage = _this.getstage(); var tags = _this.gettags(); var length = tags.length; if (length) { tags.reverse(); for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var instance = stage.getinstance(instanceid); if (!instance) { continue; } instance.initframe(); } tags.reverse(); } var initaction = stage.initactions[_this.getcharacterid()]; if (typeof initaction === "function") { initaction.apply(_this); } }; /** * @param stage * @param clipevent */ movieclip.prototype.putframe = function (stage, clipevent) { var _this = this; var mystage = _this.getstage(); var prevtags; var stopflag = _this.stopflag; if (!stopflag && _this.active) { var frame = _this.getcurrentframe(); var totalframes = _this.gettotalframes(); if (totalframes > 1) { if (_this.isload) { prevtags = _this.gettags(); frame++; } if (frame > totalframes) { frame = 1; _this.resetcheck(); } _this.setcurrentframe(frame); _this.remove(stage); _this.isaction = true; _this.soundstopflag = false; } } if (_this.removeflag) { return 0; } _this.active = true; if (prevtags !== undefined) { if (_this.isswap) { _this.resetswap(); } var tags = _this.gettags(); var length = tags.length; if (length && tags.tostring() !== prevtags.tostring()) { for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; if (depth in prevtags && instanceid === prevtags[depth]) { continue; } var instance = mystage.getinstance(instanceid); if (instance && instance instanceof movieclip) { stage.newtags.unshift(instance); } } } } if (_this.isload) { clipevent.type = "enterframe"; _this.dispatchevent(clipevent, stage); _this.dispatchonevent("onenterframe", stage); _this.addtouchevent(stage); if (_this.isaction) { _this.isaction = false; var as = _this.getactions(_this.getcurrentframe()); if (as) { _this.setactionqueue(as, stage); } } } else { // init action var initaction = mystage.initactions[_this.getcharacterid()]; if (typeof initaction === "function") { initaction.apply(_this); } } }; /** * nextframe */ movieclip.prototype.nextframe = function () { var _this = this; var frame = _this.getcurrentframe(); frame++; _this.setnextframe(frame); _this.stop(); }; /** * prevframe */ movieclip.prototype.prevframe = function () { var _this = this; var frame = _this.getcurrentframe(); frame--; _this.setnextframe(frame); _this.stop(); }; /** * @returns {number} */ movieclip.prototype.getcurrentframe = function () { return this._currentframe; }; /** * @param frame */ movieclip.prototype.setcurrentframe = function (frame) { this._currentframe = frame; }; /** * @param frame */ movieclip.prototype.setnextframe = function (frame) { var _this = this; if (frame > 0 && _this.getcurrentframe() !== frame) { _this.isaction = true; if (frame > _this.gettotalframes()) { frame = _this.gettotalframes(); _this.isaction = false; } var maxframe = _max(frame, _this.getcurrentframe()) + 1; var minframe = _min(frame, _this.getcurrentframe()); var stage = _this.getstage(); var tags = _this.gettags(); var checked = []; var nexttags = _this.gettags(frame); var tag, tagid, depth, nexttag, nexttagid; var length = _max(tags.length, nexttags.length); if (length) { for (depth = 0; depth < length; depth++) { if (!(depth in tags) && !(depth in nexttags)) { continue; } tagid = tags[depth]; nexttagid = nexttags[depth]; if (!tagid && !nexttagid) { continue; } tag = stage.getinstance(tagid); nexttag = stage.getinstance(nexttagid); if (tagid && nexttagid) { if (tagid === nexttagid) { checked[tagid] = true; continue; } tag.reset(); nexttag.reset(); checked[tagid] = true; checked[nexttagid] = true; } else if (tag) { tag.reset(); checked[tagid] = true; } else if (nexttag) { nexttag.reset(); checked[nexttagid] = true; } } } if (checked.length) { for (var chkframe = minframe; chkframe < maxframe; chkframe++) { var container = _this.gettags(chkframe); if (!container.length) { continue; } for (depth in container) { if (!container.hasownproperty(depth)) { continue; } tagid = container[depth]; if (tagid in checked) { continue; } checked[tagid] = true; tag = stage.getinstance(tagid); tag.reset(); } } } _this.setcurrentframe(frame); _this.soundstopflag = false; var _root = _this.getdisplayobject("_root"); var rootstage = _root.getstage(); _this.addactions(rootstage); } }; /** * @returns {number} */ movieclip.prototype.gettotalframes = function () { return this._totalframes; }; /** * @param frame */ movieclip.prototype.settotalframes = function (frame) { this._totalframes = frame; this._framesloaded = frame; }; /** * addlabel * @param frame * @param name */ movieclip.prototype.addlabel = function (frame, name) { if (typeof name !== "string") { name += ""; } this.labels[name.tolowercase()] = frame|0; }; /** * @param name * @returns {*} */ movieclip.prototype.getlabel = function (name) { if (typeof name !== "string") { name += ""; } return this.labels[name.tolowercase()]; }; /** * @param frame * @param obj */ movieclip.prototype.addsound = function (frame, obj) { var _this = this; if (!(frame in _this.sounds)) { _this.sounds[frame] = []; } _this.sounds[frame].push(obj); }; /** * @returns {*} */ movieclip.prototype.getsounds = function () { var _this = this; return _this.sounds[_this.getcurrentframe()]; }; /** * @param sound */ movieclip.prototype.startsound = function (sound) { var _this = this; var stage = _this.getstage(); var soundid = sound.soundid; var tag = stage.getcharacter(soundid); if (!tag) { return 0; } var soundinfo = tag.soundinfo; startsound(sound.audio, soundinfo); _this.soundstopflag = true; }; /** * @param frame * @returns {*} */ movieclip.prototype.gettags = function (frame) { var _this = this; var key = frame || _this.getcurrentframe(); return _this.container[key] || []; }; /** * @param frame * @param tags */ movieclip.prototype.setremovetag = function (frame, tags) { var rtags = this.removetags; rtags[frame] = []; var length = tags.length; for (var i = 0; i < length; i++) { var tag = tags[i]; rtags[frame][tag.depth] = 1; } }; /** * @param frame * @returns {*} */ movieclip.prototype.getremovetags = function (frame) { return this.removetags[frame]; }; /** * @param stage */ movieclip.prototype.remove = function (stage) { var _this = this; var removetags = _this.getremovetags(_this.getcurrentframe()); if (removetags) { var mystage = _this.getstage(); var frame = _this.getcurrentframe() - 1; var tags = _this.gettags(frame); for (var idx in tags) { if (!tags.hasownproperty(idx)) { continue; } var instanceid = tags[idx]; var tag = mystage.getinstance(instanceid); if (!tag) { continue; } if (tag instanceof movieclip) { var depth = tag.getdepth() + 16384; if (!(depth in removetags)) { continue; } clipevent.type = "unload"; _this.dispatchevent(clipevent, stage); tag.reset(); } else { if (!(idx in removetags)) { continue; } tag.reset(); } } } }; /** * resetcheck */ movieclip.prototype.resetcheck = function () { var _this = this; var instances = _this.getinstances(); var stage = _this.getstage(); for (var id in instances) { if (!instances.hasownproperty(id)) { continue; } var instance = stage.getinstance(id); if (!instance || (!instance.getratio() && !instance.removeflag)) { continue; } instance.reset(); } }; /** * resetswap */ movieclip.prototype.resetswap = function () { var _this = this; var stage = _this.getstage(); var currenttags = _this.gettags(); var totalframes = _this.gettotalframes() + 1; for (var frame = 1; frame < totalframes; frame++) { var tags = _this.gettags(frame); var length = tags.length; if (length) { var resettags = []; for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } depth |= 0; var tagid = tags[depth]; var instance = stage.getinstance(tagid); if (!instance) { delete tags[depth]; continue; } if (instance.active) { continue; } if (instance.getlevel() !== depth) { if (!(instance.getlevel() in currenttags)) { instance._depth = null; resettags[instance.getlevel()] = tagid; } delete tags[depth]; } } length = resettags.length; if (length) { for (var level in resettags) { if (!resettags.hasownproperty(level)) { continue; } tags[level] = resettags[level]; } } } } _this.isswap = false; }; /** * reset */ movieclip.prototype.reset = function () { var _this = this; var stage = _this.getstage(); var instances = _this.getinstances(); for (var id in instances) { if (!instances.hasownproperty(id)) { continue; } var instance = stage.getinstance(id); if (instance instanceof movieclip && instance.getdepth() >= 0) { instance.removemovieclip(); if (instance.getdepth() < 0) { instance.removeflag = false; } } else { instance.reset(); } } var parent = _this.getparent(); if (parent && _this.getlevel() !== _this.getdepth()+16384) { parent.isswap = true; } _this.play(); _this.setcurrentframe(1); _this.clear(); _this.initparams(); _this.variables = {}; }; /** * init */ movieclip.prototype.initparams = function () { var _this = this; _this.active = false; _this.removeflag = false; _this.isload = false; _this.ismask = false; _this.isaction = true; _this.soundstopflag = false; _this._droptarget = null; _this._depth = null; _this._mask = null; _this._matrix = null; _this._colortransform = null; _this._filters = null; _this._blendmode = null; _this.buttonstatus = "up"; _this.mouseenabled = true; _this.setvisible(true); _this.setenabled(true); }; /** * @param stage */ movieclip.prototype.addtouchevent = function (stage) { var _this = this; var events = _this.events; var moveeventhits = stage.moveeventhits; var downeventhits = stage.downeventhits; var upeventhits = stage.upeventhits; var keydowneventhits = stage.keydowneventhits; for (var name in events) { if (!events.hasownproperty(name)) { continue; } var as = events[name]; switch (name) { case "mousedown": downeventhits[downeventhits.length] = {as: as, mc: _this}; break; case "mousemove": moveeventhits[moveeventhits.length] = {as: as, mc: _this}; break; case "mouseup": upeventhits[upeventhits.length] = {as: as, mc: _this}; break; case "keydown": if (istouch) { downeventhits[downeventhits.length] = { as: as, mc: _this }; } else { keydowneventhits[keydowneventhits.length] = { as: as, mc: _this }; } break; case "keyup": upeventhits[upeventhits.length] = {as: as, mc: _this}; break; } } var variables = _this.variables; var onmousedown = variables.onmousedown; if (onmousedown) { downeventhits[downeventhits.length] = {mc: _this}; } var onmousemove = variables.onmousemove; if (onmousemove) { moveeventhits[moveeventhits.length] = {mc: _this}; } var onmouseup = variables.onmouseup; if (onmouseup) { upeventhits[upeventhits.length] = {mc: _this}; } }; /** * @param script * @returns {*} */ movieclip.prototype.createactionscript = function (script) { return (function (clip, origin) { var as = new actionscript([], origin.constantpool, origin.register, origin.initaction); as.cache = origin.cache; as.scope = clip; return function () { as.reset(); as.variables["this"] = this; return as.execute(clip); }; })(this, script); }; /** * @param script * @param parent */ movieclip.prototype.createactionscript2 = function (script, parent) { return (function (clip, origin, chain) { return function () { var as = new actionscript([], origin.constantpool, origin.register, origin.initaction); as.parentid = origin.id; // todo as.cache = origin.cache; as.scope = clip; as.parent = (chain) ? chain : null; if (as.register.length) { as.initvariable(arguments); } as.variables["this"] = this; return as.execute(clip); }; })(this, script, parent); }; /** * addframescript */ movieclip.prototype.addframescript = function () { var _this = this; var args = arguments; var length = args.length; for (var i = 0; i < length; i++) { var frame = args[i++]; var script = args[i]; if (typeof frame === "string") { frame = _this.getlabel(frame); } else { frame += 1; } frame = frame|0; if (frame > 0 && _this.gettotalframes() >= frame) { var actions = _this.actions; if (!(frame in actions)) { actions[frame] = []; } if (script === null) { actions[frame] = []; } else { var alen = actions[frame].length; actions[frame][alen] = script; } } } }; /** * @param stage */ movieclip.prototype.addactions = function (stage) { var _this = this; _this.active = true; var mystage = _this.getstage(); if (_this.isaction) { _this.isaction = false; if (!_this.isload) { // as3 _this.buildavm2(); // registerclass var regclass = mystage.registerclass[_this.getcharacterid()]; if (typeof regclass === "function") { _this.variables.registerclass = new regclass(); } // clipevent clipevent.type = "initialize"; _this.dispatchevent(clipevent, stage); clipevent.type = "construct"; _this.dispatchevent(clipevent, stage); clipevent.type = "load"; _this.dispatchevent(clipevent, stage); var onload = _this.variables.onload; if (typeof onload === "function") { _this.setactionqueue(onload, stage); } _this.addtouchevent(stage); } var action = _this.getactions(_this.getcurrentframe()); if (action) { _this.setactionqueue(action, stage); } } var tags = _this.gettags(); var length = tags.length; if (length) { for (var depth in tags) { if (!tags.hasownproperty(depth)) { continue; } var instanceid = tags[depth]; var instance = mystage.getinstance(instanceid); if (!instance) { continue; } instance.addactions(stage); } } }; /** * @param frame * @returns {*} */ movieclip.prototype.getactions = function (frame) { return this.actions[frame]; }; /** * @param frame * @param actionscript */ movieclip.prototype.setactions = function (frame, actionscript) { var _this = this; var actions = _this.actions; if (!(frame in actions)) { actions[frame] = []; } var length = actions[frame].length; actions[frame][length] = _this.createactionscript(actionscript); }; /** * @param frame * @param action */ movieclip.prototype.overwriteaction = function (frame, action) { var _this = this; if (typeof frame === "string") { frame = _this.getlabel(frame); } frame = frame|0; if (frame > 0 && _this.gettotalframes() >= frame) { _this.actions[frame] = [action]; } }; /** * @param frame * @param action */ movieclip.prototype.addaction = function (frame, action) { var _this = this; if (typeof frame === "string") { frame = _this.getlabel(frame); } frame = frame|0; if (frame > 0 && _this.gettotalframes() >= frame) { var actions = _this.actions; if (!(frame in actions)) { actions[frame] = []; } var length = actions[frame].length; actions[frame][length] = action; } }; /** * @param frame */ movieclip.prototype.executeactions = function (frame) { var _this = this; var actions = _this.getactions(frame); if (actions !== undefined) { var length = actions.length; for (var i = 0; i < length; i++) { actions[i].apply(_this); } } }; /** * assetpropflags */ movieclip.prototype.assetpropflags = function () { // object, properties, n, allowfalse }; /** * @param rgb * @param alpha */ movieclip.prototype.beginfill = function (rgb, alpha) { var graphics = this.getgraphics(); graphics.beginfill(rgb, alpha); }; /** * @param width * @param rgb * @param alpha * @param pixelhinting * @param noscale * @param capsstyle * @param jointstyle * @param miterlimit */ movieclip.prototype.linestyle = function (width, rgb, alpha, pixelhinting, noscale, capsstyle, jointstyle, miterlimit) { var graphics = this.getgraphics(); graphics.linestyle(width, rgb, alpha, pixelhinting, noscale, capsstyle, jointstyle, miterlimit); }; /** * @param dx * @param dy */ movieclip.prototype.moveto = function (dx, dy) { var graphics = this.getgraphics(); graphics.moveto(dx, dy); }; /** * @param dx * @param dy */ movieclip.prototype.lineto = function (dx, dy) { var graphics = this.getgraphics(); graphics.lineto(dx, dy); }; /** * @param cx * @param cy * @param dx * @param dy */ movieclip.prototype.curveto = function (cx, cy, dx, dy) { var graphics = this.getgraphics(); graphics.curveto(cx, cy, dx, dy); }; /** * clear */ movieclip.prototype.clear = function () { var graphics = this.getgraphics(); graphics.clear(); }; /** * endfill */ movieclip.prototype.endfill = function () { var graphics = this.getgraphics(); graphics.endfill(); }; /** * buildavm2 */ movieclip.prototype.buildavm2 = function () { var _this = this; var stage = _this.getstage(); var symbol = stage.symbols[_this.getcharacterid()]; if (symbol) { var symbols = symbol.split("."); var classmethod = symbols.pop(); var length = symbols.length; var classobj = stage.avm2; var abcobj = stage.abc; for (var i = 0; i < length; i++) { classobj = classobj[symbols[i]]; abcobj = abcobj[symbols[i]]; } // build abc var doabc = abcobj[classmethod]; var abcobj = new doabc(_this); classobj[classmethod] = abcobj; _this.avm2 = abcobj; // avm2 init var avm2 = abcobj[classmethod]; if (typeof avm2 === "function") { _this.actions = []; avm2.apply(_this); } } }; /** * @constructor */ var moviecliploader = function () { var _this = this; _this.events = { onloadstart: undefined, onloadprogress: undefined, onloadcomplete: undefined, onloadinit: undefined, onloaderror: undefined }; }; /** * @param url * @param target * @returns {boolean} */ moviecliploader.prototype.loadclip = function (url, target) { if (!url || !target) { return false; } var _this = this; var events = _this.events; var xmlhttprequest = new xmlhttprequest(); xmlhttprequest.open("get", url, true); if (isxhr2) { xmlhttprequest.responsetype = "arraybuffer"; } else { xmlhttprequest.overridemimetype("text/plain; charset=x-user-defined"); } var onloadprogress = events.onloadprogress; if (!onloadprogress) { onloadprogress = _this.onloadprogress; } if (typeof onloadprogress === "function") { xmlhttprequest.onprogress = function (e) { onloadprogress.apply(_this, [target, e.loaded, e.total]); }; } var onloadcomplete = events.onloadcomplete; if (!onloadcomplete) { onloadcomplete = _this.onloadcomplete; } if (typeof onloadcomplete === "function") { xmlhttprequest.onloadend = function (e) { var eventstatus = e.currenttarget.status; if (eventstatus === 200) { onloadcomplete.apply(_this, [target, eventstatus]); } }; } xmlhttprequest.onreadystatechange = function () { var readystate = xmlhttprequest.readystate; if (readystate === 4) { var status = xmlhttprequest.status; var onloadstart = events.onloadstart; if (!onloadstart) { onloadstart = _this.onloadstart; } if (typeof onloadstart === "function") { xmlhttprequest.onloadstart = function () { onloadstart.apply(_this, [target]); }; } switch (status) { case 200: case 304: var _root = target.getdisplayobject("_root"); var rootstage = _root.getstage(); var data = isxhr2 ? xmlhttprequest.response : xmlhttprequest.responsetext; var loadstage = new stage(); loadstages[loadstage.getid()] = loadstage; target._url = url; target.reset(); target.setloadstage(loadstage); loadstage.setparent(target); loadstage.parse(data, url); loadstage.stop(); // onloadinit var onloadinit = events.onloadinit; if (!onloadinit) { onloadinit = _this.onloadinit; } if (typeof onloadinit === "function") { var queue = (function (as, loader, mc) { return function () { return as.apply(loader, [mc]); }; })(onloadinit, _this, target); target.events.load = [queue]; } target.addactions(rootstage); break; default: var onloaderror = events.onloaderror; if (!onloaderror) { onloaderror = _this.onloaderror; } if (typeof onloaderror === "function") { onloaderror.apply(_this, [target, "error", status]); } break; } } }; xmlhttprequest.send(null); return true; }; /** * @param listener * @returns {boolean} */ moviecliploader.prototype.addlistener = function (listener) { var _this = this; if (listener && typeof listener === "object") { var events = ["onloadstart", "onloadprogress", "onloadcomplete", "onloadinit", "onloaderror"]; var variables = listener.variables; for (var i = 0; i < 5; i++) { var event = events[i]; if (typeof listener[event] === "function") { _this.events[event] = listener[event]; } else if (variables && typeof variables[event] === "function") { _this.events[event] = variables[event]; } } } return true; }; /** * @param listener * @returns {boolean} */ moviecliploader.prototype.removelistener = function (listener) { var _this = this; if (listener && typeof listener === "object") { var events = ["onloadstart", "onloadprogress", "onloadcomplete", "onloadinit", "onloaderror"]; for (var i = 0; i < 5; i++) { var event = events[i]; var variables = listener.variables; if (typeof listener[event] === "function" || (variables && typeof variables[event] === "function") ) { _this.events[event] = undefined; } } } return true; }; /** * @param target * @returns {{bytesloaded: number, bytestotal: number}} */ moviecliploader.prototype.getprogress = function (target) { return { bytesloaded: 0, bytestotal: 0 }; }; /** * @constructor */ var loadvars = function () { var _this = this; _this.xmlhttprequest = new xmlhttprequest(); _this.variables = {}; _this.target = _this; _this.events = { ondata: undefined, onload: undefined }; }; /** * properties */ object.defineproperties(loadvars.prototype, { ondata: { get: function () { return this.getproperty("ondata"); }, set: function (ondata) { this.setproperty("ondata", ondata); } }, onload: { get: function () { return this.getproperty("onload"); }, set: function (onload) { this.setproperty("onload", onload); } } }); /** * @param name * @returns {*} */ loadvars.prototype.getproperty = function (name) { return this.variables[name]; }; /** * @param name * @param value */ loadvars.prototype.setproperty = function (name, value) { this.variables[string(name)] = value; }; /** * @param url * @returns {boolean} */ loadvars.prototype.load = function (url) { var _this = this; var xmlhttprequest = _this.xmlhttprequest; xmlhttprequest.open("get", url, true); xmlhttprequest.onreadystatechange = function () { var readystate = xmlhttprequest.readystate; if (readystate === 4) { var src = decodeuricomponent(xmlhttprequest.responsetext); _this.decode(src); var ondata = _this.ondata; if (typeof ondata === "function") { ondata.apply(src, [src]); } var onload; var status = xmlhttprequest.status; switch (status) { case 200: case 304: onload = _this.onload; if (typeof onload === "function") { onload.apply(src, [true]); } return true; default: onload = _this.onload; if (typeof onload === "function") { onload.apply(src, [false]); } return false; } } }; xmlhttprequest.send(null); }; /** * @param url * @param target * @param method * @returns {boolean} */ loadvars.prototype.send = function (url, target, method) { var _this = this; var xmlhttprequest = _this.xmlhttprequest; var sendmethod = method ? method.touppercase() : "get"; xmlhttprequest.open(sendmethod, url, true); if (sendmethod === "post") { xmlhttprequest.setrequestheader("content-type", "application/x-www-form-urlencoded"); } if (target instanceof loadvars) { _this.target = target; } xmlhttprequest.send(_this.tostring()); return true; }; /** * @param url * @param target * @param method * @returns {boolean} */ loadvars.prototype.sendandload = function (url, target, method) { var _this = this; _this.send(url, target, method); return _this.load(url); }; /** * @param header * @param headervalue */ loadvars.prototype.addrequestheader = function (header, headervalue) { var xmlhttprequest = this.xmlhttprequest; if (header instanceof array) { var length = header.length; for (var i = 0; i < length;) { xmlhttprequest.setrequestheader(header[i++], headervalue[i++]); } } else { xmlhttprequest.setrequestheader(header, headervalue); } }; /** * @param querystring */ loadvars.prototype.decode = function (querystring) { var variables = this.variables; var array = querystring.split("&"); var length = array.length; for (var i = 0; i < length; i++) { var values = array[i]; var splitdata = values.split("="); if (splitdata.length < 1) { continue; } variables[string(splitdata[0])] = splitdata[1]; } }; /** * @returns {number} */ loadvars.prototype.getbytesloaded = function () { return 1; }; /** * @returns {number} */ loadvars.prototype.getbytestotal = function () { return 1; }; /** * @returns {string} */ loadvars.prototype.tostring = function () { var variables = this.variables; var array = []; for (var prop in variables) { if (!variables.hasownproperty(prop)) { continue; } array[array.length] = prop + "=" + variables[prop]; } return array.join("&"); }; /** * @constructor */ var xml = function () { var _this = this; _this.ignorewhite = false; _this.loaded = false; _this.status = 0; _this.variables = {}; }; /** * properties */ object.defineproperties(xml.prototype, { ondata: { get: function () { return this.getproperty("ondata"); }, set: function (ondata) { this.setproperty("ondata", ondata); } }, onload: { get: function () { return this.getproperty("onload"); }, set: function (onload) { this.setproperty("onload", onload); } } }); /** * @param name * @returns {*} */ xml.prototype.getproperty = function (name) { return this.variables[name]; }; /** * @param name * @param value */ xml.prototype.setproperty = function (name, value) { this.variables[string(name)] = value; }; /** * @param url */ xml.prototype.load = function (url) { var _this = this; url = "" + url; var xmlhttprequest = new xmlhttprequest(); xmlhttprequest.open("get", url, true); xmlhttprequest.onreadystatechange = function () { var readystate = xmlhttprequest.readystate; if (readystate === 4) { var src = xmlhttprequest.responsexml; var ondata = _this.ondata; if (typeof ondata === "function") { ondata.apply(src, [src]); } var onload; var status = xmlhttprequest.status; switch (status) { case 200: case 304: onload = _this.onload; if (typeof onload === "function") { onload.apply(src, [true]); } return true; default: onload = _this.onload; if (typeof onload === "function") { onload.apply(src, [false]); } return false; } } }; xmlhttprequest.send(null); }; /** * @param url * @param target * @param method */ xml.prototype.send = function (url, target, method) { var sendmethod = method ? method.touppercase() : "get"; if (target) { console.log(target); } var xmlhttprequest = new xmlhttprequest(); xmlhttprequest.open(sendmethod, url, true); xmlhttprequest.send(null); return true; }; /** * @param url * @param resultxml */ xml.prototype.sendandload = function (url, resultxml) { var _this = this; _this.send(url); return _this.load(resultxml); }; /** * @constructor */ var sound = function () { var _this = this; _this.variables = {}; _this.sounds = []; _this.volume = 100; _this.pan = 0; _this.transform = {ll: 100, lr: 100, rl: 100, rr: 100}; _this.isstreamin = false; _this.movieclip = null; }; /** * properties */ object.defineproperties(sound.prototype, { onload: { get: function () { return this.getproperty("onload"); }, set: function (onload) { this.setproperty("onload", onload); } }, onsoundcomplete: { get: function () { return this.getproperty("onsoundcomplete"); }, set: function (onsoundcomplete) { this.setproperty("onsoundcomplete", onsoundcomplete); } } }); /** * @param name * @returns {*} */ sound.prototype.getproperty = function (name) { return this.variables[name]; }; /** * @param name * @param value */ sound.prototype.setproperty = function (name, value) { this.variables[string(name)] = value; }; /** * @param currenttime * @param loopcount */ sound.prototype.start = function (currenttime, loopcount) { var _this = this; var sounds = _this.sounds; var init = function (audio, time) { return function () { audio.currenttime = time; }; }; var end = function (audio, sound) { return function () { var volume = sound.volume; audio.loopcount--; if (audio.loopcount > 0) { audio.volume = volume / 100; audio.currenttime = 0; audio.play(); } var onsoundcomplete = sound.onsoundcomplete; if (onsoundcomplete) { onsoundcomplete.apply(sound, [true]); } }; }; var audio; for (var id in sounds) { if (!sounds.hasownproperty(id)) { continue; } audio = sounds[id]; audio.load(); if (currenttime) { audio.addeventlistener("canplay", init(audio, currenttime)); } if (typeof loopcount === "number" && loopcount > 0) { audio.loopcount = loopcount; audio.addeventlistener("ended", end(audio, _this)); } audio.play(); } }; /** * stop */ sound.prototype.stop = function (id) { var sounds = this.sounds; var audio; if (id) { audio = sounds[id]; if (audio) { audio.pause(); } } else { for (var key in sounds) { if (!sounds.hasownproperty(key)) { continue; } audio = sounds[key]; audio.pause(); } } }; /** * @param url * @param bool */ sound.prototype.loadsound = function (url, bool) { var _this = this; _this.isstreamin = bool; var sounds = _this.sounds; var audio = _document.createelement("audio"); audio.src = url; sounds[0] = audio; var onload = (function (audio, sound) { return function() { audio.load(); audio.preload = "auto"; audio.autoplay = false; audio.loop = false; var onload = sound.onload; if (typeof onload === "function") { onload.apply(sound, [true]); } }; })(audio, _this); audio.addeventlistener("canplaythrough", onload); var onerror = (function (audio, sound) { return function() { var onload = sound.onload; if (typeof onload === "function") { onload.apply(sound, [false]); } }; })(audio, _this); audio.addeventlistener("error", onerror); }; /** * @param id */ sound.prototype.attachsound = function (id) { var _this = this; var sounds = _this.sounds; if (!(id in sounds)) { var movieclip = _this.movieclip; var stage = movieclip.getstage(); var exportassets = stage.exportassets; if (id in exportassets) { var characterid = exportassets[id]; var tag = stage.sounds[characterid]; if (tag) { var audio = _document.createelement("audio"); audio.onload = function () { this.load(); this.preload = "auto"; this.autoplay = false; this.loop = false; }; audio.src = tag.base64; sounds[id] = audio; } } } }; /** * * @returns {number} */ sound.prototype.getvolume = function () { return this.volume; }; /** * * @param volume */ sound.prototype.setvolume = function (volume) { var _this = this; var sounds = _this.sounds; _this.volume = volume; for (var id in sounds) { if (!sounds.hasownproperty(id)) { continue; } var audio = sounds[id]; audio.volume = volume / 100; } }; /** * @returns {number|*} */ sound.prototype.getpan = function () { return this.pan; }; /** * @param pan */ sound.prototype.setpan = function (pan) { this.pan = pan; }; /** * @param object */ sound.prototype.settransform = function (object) { var transform = this.transform; for (var name in object) { if (!object.hasownproperty(name)) { continue; } switch (name) { case "ll": case "lr": case "rl": case "rr": transform[name] = object[name]; break; } } }; /** * @returns {{ll: number, lr: number, rl: number, rr: number}|*} */ sound.prototype.gettransform = function () { return this.transform; }; /** * @returns {number} */ sound.prototype.getbytesloaded = function () { return 1; }; /** * @returns {number} */ sound.prototype.getbytestotal = function () { return 1; }; /** * @constructor */ var sharedobject = function () { var _this = this; _this.data = null; _this.name = null; }; /** * @param name * @returns {sharedobject} */ sharedobject.prototype.getlocal = function (name) { var _this = this; _this.name = name; var data = window.localstorage.getitem(name); if (!data) { data = {}; } else { data = json.parse(data); } _this.data = data; return _this; }; /** * flush */ sharedobject.prototype.flush = function () { var _this = this; window.localstorage.setitem(_this.name, json.stringify(_this.data)); return true; }; /** * @param mc * @constructor */ var color = function (mc) { var _this = this; _this.movieclip = mc; _this.variables = {}; }; /** * * @param name * @returns {*} */ color.prototype.getproperty = function (name) { return this.variables[name]; }; /** * @param name * @param value */ color.prototype.setproperty = function (name, value) { this.variables[string(name)] = value; }; /** * @param int * @param alpha * @returns {{r: number, g: number, b: number, a: number}} */ color.prototype.inttorgba = function (int, alpha) { alpha = alpha || 100; return { r: (int & 0xff0000) >> 16, g: (int & 0x00ff00) >> 8, b: (int & 0x0000ff), a: (alpha / 100) }; }; /** * @param offset */ color.prototype.setrgb = function (offset) { var _this = this; var mc = _this.movieclip; if (mc instanceof movieclip) { offset |= 0; var obj = _this.inttorgba(offset); var colortransform = mc.getorigincolortransform(); if (colortransform) { var transform = [obj.r, obj.g, obj.b, obj.a * 255, 0, 0, 0, 0]; var multicolor = mc.clonearray(transform); var color = mc.multiplicationcolor(colortransform, multicolor); mc.setcolortransform(color); } } }; /** * @returns {*[]|*} */ color.prototype.gettransform = function () { var _this = this; var mc = _this.movieclip; if (mc instanceof movieclip) { return mc.getcolortransform(); } return undefined; }; /** * @param obj */ color.prototype.settransform = function (obj) { var _this = this; var mc = _this.movieclip; if (mc instanceof movieclip) { var colortransform = mc.getorigincolortransform(); var transform = [ obj.rb, obj.gb, obj.bb, obj.ab, obj.ra, obj.ga, obj.ba, obj.aa ]; var multicolor = mc.clonearray(transform); var color = mc.multiplicationcolor(colortransform, multicolor); mc.setcolortransform(color); } }; /** * @constructor */ var mouse = function () { this.events = {}; }; /** * @returns {undefined} */ mouse.prototype.show = function () { return undefined; }; /** * @returns {undefined} */ mouse.prototype.hide = function () { return undefined; }; /** * @param listener */ mouse.prototype.addlistener = function (listener) { var _this = this; if (listener && typeof listener === "object") { var events = ["onmousedown", "onmousemove", "onmouseup"]; var variables = listener.variables; for (var i = 0; i < 5; i++) { var event = events[i]; if (typeof listener[event] === "function") { _this.events[event] = listener[event]; } else if (variables && typeof variables[event] === "function") { _this.events[event] = variables[event]; } } } return true; }; /** * @param listener */ mouse.prototype.removelistener = function (listener) { var _this = this; if (listener && typeof listener === "object") { var events = ["onmousedown", "onmousemove", "onmouseup"]; for (var i = 0; i < 5; i++) { var event = events[i]; var variables = listener.variables; if (typeof listener[event] === "function" || (variables && typeof variables[event] === "function") ) { _this.events[event] = undefined; } } } return true; }; /** * @constructor */ var key = function () { var _this = this; _this.variables = {}; _this._listeners = []; }; /** * properties */ object.defineproperties(key.prototype, { onkeydown: { get: function () { return this.getproperty("onkeydown"); }, set: function (onkeydown) { this.setproperty("onkeydown", onkeydown); } }, onkeyup: { get: function () { return this.getproperty("onkeyup"); }, set: function (onkeyup) { this.setproperty("onkeyup", onkeyup); } } }); /** * @type {number} */ key.prototype.backspace = 8; key.prototype.capslock = 20; key.prototype.control = 17; key.prototype.deletekey = 46; key.prototype.down = 40; key.prototype.end = 35; key.prototype.enter = 13; key.prototype.escape = 27; key.prototype.home = 36; key.prototype.insert = 45; key.prototype.left = 37; key.prototype.pgdn = 34; key.prototype.pgdn = 34; key.prototype.pgup = 33; key.prototype.right = 39; key.prototype.shift = 16; key.prototype.space = 32; key.prototype.tab = 9; key.prototype.up = 38; /** * @param name * @returns {*} */ key.prototype.getproperty = function (name) { return this.variables[name]; }; /** * @param name * @param value */ key.prototype.setproperty = function (name, value) { this.variables[string(name)] = value; }; /** * * @param listener * @returns {boolean} */ key.prototype.addlistener = function (listener) { var _this = this; var onkeydown = listener.onkeydown; if (onkeydown) { _this.onkeydown = onkeydown; } var onkeyup = listener.onkeyup; if (onkeyup) { _this.onkeyup = onkeyup; } return true; }; /** * @param code * @returns {boolean} */ key.prototype.isdown = function (code) { return (this.getcode() === code); }; /** * @returns {*} */ key.prototype.getcode = function () { var keycode = (_keyevent) ? _keyevent.keycode : null; if (96 <= keycode && keycode <= 105) { var n = keycode - 96; switch (n) { case 0: keycode = 48; break; case 1: keycode = 49; break; case 2: keycode = 50; break; case 3: keycode = 51; break; case 4: keycode = 52; break; case 5: keycode = 53; break; case 6: keycode = 54; break; case 7: keycode = 55; break; case 8: keycode = 56; break; case 9: keycode = 57; break; } } return keycode; }; var keyclass = new key(); /** * @param event */ function keyupaction(event) { _keyevent = event; var onkeyup = keyclass.onkeyup; if (typeof onkeyup === "function") { onkeyup.apply(keyclass, [event]); } } /** * @param event */ function keydownaction(event) { _keyevent = event; var keycode = keyclass.getcode(); var i; var length; var obj; var onkeydown = keyclass.onkeydown; if (typeof onkeydown === "function") { onkeydown.apply(keyclass, [event]); } var idx; length = stages.length; for (var pidx = 0; pidx < length; pidx++) { if (!(pidx in stages)) { continue; } var stage = stages[pidx]; var keydowneventhits = stage.keydowneventhits; var klen = keydowneventhits.length; if (klen) { for (idx = 0; idx < klen; idx++) { obj = keydowneventhits[idx]; stage.executeeventaction(obj.as, obj.mc); } } var buttonhits = stage.buttonhits; var len = buttonhits.length; var isend = false; for (i = len; i--;) { if (!(i in buttonhits)) { continue; } var hitobj = buttonhits[i]; if (!hitobj) { continue; } var button = hitobj.button; if (!button) { continue; } var actions = button.getactions(); if (!actions) { continue; } var alen = actions.length; for (idx = 0; idx < alen; idx++) { if (!(idx in actions)) { continue; } var cond = actions[idx]; var condkeypress = cond.condkeypress; switch (condkeypress) { case 1: // left arrow condkeypress = 37; break; case 2: // right arrow condkeypress = 39; break; case 3: // home condkeypress = 36; break; case 4: // end condkeypress = 35; break; case 5: // insert condkeypress = 45; break; case 6: // delete condkeypress = 46; break; case 14: // up arrow condkeypress = 38; break; case 15: // down arrow condkeypress = 40; break; case 16: // page up condkeypress = 33; break; case 17: // page down condkeypress = 34; break; case 18: // tab condkeypress = 9; break; case 19: // escape condkeypress = 27; break; } if (condkeypress !== keycode) { continue; } stage.buttonaction(hitobj.parent, cond.actionscript); stage.touchrender(); isend = true; break; } if (isend) { break; } } } } /** * @constructor */ var global = function () { this.variables = {}; }; /** * * @param name * @returns {*} */ global.prototype.getvariable = function (name) { return this.variables[name]; }; /** * @param name * @param value * @returns {*} */ global.prototype.setvariable = function (name, value) { this.variables[name] = value; }; /** * @param name * @returns {*} */ global.prototype.getproperty = function (name) { return this.variables[name]; }; /** * @param name * @param value */ global.prototype.setproperty = function (name, value) { this.variables[name] = value; }; /** * @constructor * @param stage */ var packages = function (stage) { this.stage = stage; }; /** * @type {*} */ packages.prototype = { "flash": { "display": { "movieclip": movieclip, "sprite": sprite, "displayobjectcontainer": displayobjectcontainer, "interactiveobject": interactiveobject, "displayobject": displayobject, "graphics": graphics }, "events": { "eventdispatcher": eventdispatcher, "mouseevent": clipevent }, "text": { "statictext": statictext }, "media": { "sound": sound }, "system": { "fscommand": function () { var command = arguments[0]; var args = arguments[1]; if (args === undefined) { args = ""; } switch (command) { case "quit": case "fullscreen": case "allowscale": case "showmenu": case "exec": case "trapallkeys": break; default: if (command) { var _this = this; var method = (_this.tagid) ? _this.tagid : _this.getname(); var body = method +"_dofscommand(command, args);"; var fscommand = new func("command", "args", body); fscommand(command, args); } break; } return true; } } } }; /** * @constructor */ var stage = function () { var _this = this; _this.id = stageid++; _this.name = "swf2js_" + _this.id; _this.intervalid = 0; _this.framerate = 0; _this.filesize = 0; _this.stopflag = true; // options _this.optionwidth = 0; _this.optionheight = 0; _this.callback = null; _this.rendermode = iswebgl; _this.tagid = null; _this.flashvars = {}; _this.quality = "medium"; // low = 0.25, medium = 0.8, high = 1.0 _this.bgcolor = null; // event _this.mouse = new mouse(); // params _this.context = null; _this.canvas = null; _this.precontext = null; _this.hitcontext = null; _this.matrix = [1,0,0,1,0,0]; _this._matrix = [1,0,0,1,0,0]; _this._colortransform = [1,1,1,1,0,0,0,0]; _this.characters = []; _this.initactions = []; _this.exportassets = []; _this.packages = []; _this.registerclass = []; _this.buttonhits = []; _this.downeventhits = []; _this.moveeventhits = []; _this.upeventhits = []; _this.keydowneventhits = []; _this.keyupeventhits = []; _this.sounds = []; _this.loadsounds = []; _this.videos = []; _this.actions = []; _this.instances = []; _this.placeobjects = []; _this.fonts = []; _this.isaction = true; _this._global = new global(); _this.touchobj = null; _this.touchstatus = "up"; _this.overobj = null; _this.touchendaction = null; _this.imgunloadcount = 0; _this.scale = 1; _this.basewidth = 0; _this.baseheight = 0; _this.width = 0; _this.height = 0; _this.ishit = false; _this.istouchevent = false; _this.isload = false; _this.jpegtables = null; _this.backgroundcolor = "transparent"; _this.version = 8; _this.loadstatus = 0; _this.isclipdepth = false; _this.clipdepth = 0; _this.clipmc = false; _this.dragmc = null; _this.dragrules = null; _this.scalemode = "showall"; _this.align = ""; _this.avm2 = new packages(_this); _this.abc = new packages(_this); _this.symbols = []; _this.abcflag = false; // render _this.donetags = []; _this.newtags = []; // init var mc = new movieclip(); mc.setstage(_this); _this.setparent(mc); }; /** * @returns {number|*} */ stage.prototype.getid = function () { return this.id; }; /** * @param id */ stage.prototype.setid = function (id) { this.id = id; }; /** * @returns {*} */ stage.prototype.getparent = function () { return this.parent; }; /** * @param parent */ stage.prototype.setparent = function (parent) { this.parent = parent; }; /** * @returns {number|*} */ stage.prototype.getversion = function () { return this.version; }; /** * @param version */ stage.prototype.setversion = function (version) { this.version = version; }; /** * * @returns {string} */ stage.prototype.getbackgroundcolor = function () { return this.backgroundcolor; }; /** * @param r * @param g * @param b */ stage.prototype.setbackgroundcolor = function (r, g, b) { this.backgroundcolor = "rgb(" + r + "," + g + "," + b + ")"; }; /** * @returns {array} */ stage.prototype.getglobal = function () { return this._global; }; /** * play */ stage.prototype.play = function () { var _this = this; _this.stopflag = false; var enterframe = function (stage) { return function () { requestanimationframe(function () { if (stage.isload && !stage.stopflag) { stage.nextframe(); } }, 0); }; }; _this.intervalid = _setinterval(enterframe(_this), _this.getframerate()); }; /** * stop */ stage.prototype.stop = function () { var _this = this; _this.stopflag = true; _clearinterval(_this.intervalid); }; /** * @returns {*} */ stage.prototype.getname = function () { return this.name; }; /** * @param name */ stage.prototype.setname = function (name) { this.name = name; }; /** * @param options */ stage.prototype.setoptions = function (options) { if (options !== undefined) { var _this = this; _this.optionwidth = options.width || _this.optionwidth; _this.optionheight = options.height || _this.optionheight; _this.callback = options.callback || _this.callback; _this.tagid = options.tagid || _this.tagid; _this.rendermode = options.rendermode || _this.rendermode; _this.flashvars = options.flashvars || _this.flashvars; _this.quality = options.quality || _this.quality; _this.bgcolor = options.bgcolor || _this.bgcolor; // quality switch (_this.quality) { case "low": _devicepixelratio = devicepixelratio * 0.5; break; case "high": _devicepixelratio = devicepixelratio; break; } } }; /** * @returns {number} */ stage.prototype.getbasewidth = function () { return this.basewidth; }; /** * @param basewidth */ stage.prototype.setbasewidth = function (basewidth) { this.basewidth = basewidth; }; /** * * @returns {number} */ stage.prototype.getbaseheight = function () { return this.baseheight; }; /** * @param baseheight */ stage.prototype.setbaseheight = function (baseheight) { this.baseheight = baseheight; }; /** * * @returns {number} */ stage.prototype.getwidth = function () { return this.width; }; /** * @param width */ stage.prototype.setwidth = function (width) { if (width < 0) { width *= -1; } this.width = width; }; /** * @returns {number} */ stage.prototype.getheight = function () { return this.height; }; /** * @param height */ stage.prototype.setheight = function (height) { if (height < 0) { height *= -1; } this.height = height; }; /** * @returns {number} */ stage.prototype.getscale = function () { return this.scale; }; /** * @param scale */ stage.prototype.setscale = function (scale) { this.scale = scale; }; /** * @returns {*} */ stage.prototype.getmatrix = function () { return this.matrix; }; /** * @param matrix */ stage.prototype.setmatrix = function (matrix) { this.matrix = matrix; }; /** * @param id * @returns {*} */ stage.prototype.getcharacter = function (id) { return this.characters[id]; }; /** * @param id * @param obj */ stage.prototype.setcharacter = function (id, obj) { this.characters[id] = obj; }; /** * @param id * @returns {*} */ stage.prototype.getinstance = function (id) { return this.instances[id]; }; /** * @param instance */ stage.prototype.setinstance = function (instance) { this.instances[instance.instanceid] = instance; }; /** * @param instanceid * @param depth * @param frame * @returns {*} */ stage.prototype.getplaceobject = function (instanceid, depth, frame) { var placeobjects = this.placeobjects; if (!(instanceid in placeobjects)) { return null; } var placeobject = placeobjects[instanceid]; if (!(frame in placeobject)) { return null; } var tags = placeobject[frame]; if (!(depth in tags)) { return null; } return tags[depth]; }; /** * @param placeobject * @param instanceid * @param depth * @param frame */ stage.prototype.setplaceobject = function (placeobject, instanceid, depth, frame) { var _this = this; var placeobjects = _this.placeobjects; if (!(instanceid in placeobjects)) { placeobjects[instanceid] = []; } if (!(frame in placeobjects[instanceid])) { placeobjects[instanceid][frame] = []; } placeobjects[instanceid][frame][depth] = placeobject; }; /** * @param instanceid * @param depth * @param frame */ stage.prototype.copyplaceobject = function (instanceid, depth, frame) { var _this = this; var placeobject = _this.getplaceobject(instanceid, depth, frame - 1); _this.setplaceobject(placeobject, instanceid, depth, frame); }; /** * @param instanceid */ stage.prototype.removeplaceobject = function (instanceid) { delete this.placeobjects[instanceid]; // delete this.instances[instanceid]; }; /** * @returns {number} */ stage.prototype.getframerate = function () { return this.framerate; }; /** * @param fps */ stage.prototype.setframerate = function (fps) { this.framerate = (1000 / fps) | 0; }; /** * loadstatus countup */ stage.prototype.loadevent = function () { var _this = this; switch (_this.loadstatus) { case 2: _this.resize(); _this.loadstatus++; break; case 3: if (!_this.isload || !_this.stopflag || _this.imgunloadcount > 0) { break; } _this.loadstatus++; _this.loaded(); break; } if (_this.loadstatus !== 4) { _settimeout(function () { _this.loadevent(); }, 0); } }; /** * @param data * @param url */ stage.prototype.parse = function (data, url) { var _this = this; _this.isload = false; var bitio = new bitio(); var swftag = new swftag(_this, bitio); if (isxhr2) { bitio.setdata(new uint8array(data)); } else { bitio.init(data); } if (_this.setswfheader(bitio, swftag)) { var mc = _this.getparent(); mc._url = location.href; // parse var tags = swftag.parse(mc); // mc reset mc.container = []; var frame = 1; var totalframes = mc.gettotalframes() + 1; while (frame < totalframes) { mc.container[frame++] = []; } mc.instances = []; // build swftag.build(tags, mc); var query = url.split("?")[1]; if (query) { var values = query.split("&"); var length = values.length; while (length--) { var value = values[length]; var pair = value.split("="); if (pair.length > 1) { mc.setvariable(pair[0], pair[1]); } } } // flashvars var vars = _this.flashvars; for (var key in vars) { if (!vars.hasownproperty(key)) { continue; } mc.setvariable(key, vars[key]); } } _this.isload = true; }; /** * @param bitio * @param swftag * @returns {boolean} */ stage.prototype.setswfheader = function (bitio, swftag) { var _this = this; var data = bitio.data; if (data[0] === 0xff && data[1] === 0xd8) { _this.parsejpeg(data, swftag); return false; } // signature var signature = bitio.getheadersignature(); // version var version = bitio.getversion(); _this.setversion(version); // file size var filelength = bitio.getui32(); _this.filesize = filelength; switch (signature) { case "fws": // no zip break; case "cws": // zlib bitio.decompress(filelength, "zlib"); break; case "zws": // todo lzma alert("not support lzma"); //bitio.decompress(filelength, "lzma"); return false; } var bounds = swftag.rect(); var framerate = bitio.getui16() / 0x100; bitio.getui16(); // framecount _this.setbasewidth(_ceil((bounds.xmax - bounds.xmin) / 20)); _this.setbaseheight(_ceil((bounds.ymax - bounds.ymin) / 20)); _this.setframerate(framerate); _this.loadstatus++; return true; }; /** * @param data * @param swftag */ stage.prototype.parsejpeg = function (data, swftag) { var _this = this; var image = _document.createelement("img"); image.addeventlistener("load", function () { var width = this.width; var height = this.height; var canvas = cachestore.getcanvas(); canvas.width = width; canvas.height = height; var imagecontext = canvas.getcontext("2d"); imagecontext.drawimage(this, 0, 0, width, height); _this.setcharacter(1, imagecontext); var shapewidth = width * 20; var shapeheight = height * 20; _this.setbasewidth(width); _this.setbaseheight(height); var shape = { shaperecords: [ { fillstyle1: 1, statefillstyle0: 0, statefillstyle1: 1, statelinestyle: 0, statemoveto: 0, statenewstyles: 0, ischange: true }, { anchorx: shapewidth, anchory: 0, controlx: 0, controly: 0, ischange: false, iscurved: false }, { anchorx: shapewidth, anchory: shapeheight, controlx: 0, controly: 0, ischange: false, iscurved: false }, { anchorx: 0, anchory: shapeheight, controlx: 0, controly: 0, ischange: false, iscurved: false }, { anchorx: 0, anchory: 0, controlx: 0, controly: 0, ischange: false, iscurved: false }, 0 ], fillstyles: { fillstylecount: 1, fillstyles: [{ bitmapid: 1, bitmapmatrix: [20, 0, 0, 20, 0, 0], fillstyletype: 65 }] }, linestyles: { linestylecount: 0, linestyles: [] } }; var bounds = { xmin: 0, xmax: shapewidth, ymin: 0, ymax: shapeheight }; var data = vtc.convert(shape); _this.setcharacter(2, { tagtype: 22, data: data, bounds: bounds }); var parent = _this.getparent(); var obj = new shape(); obj.setparent(parent); obj.setstage(_this); obj.setdata(data); obj.settagtype(22); obj.setcharacterid(2); obj.setbounds(bounds); obj.setlevel(1); parent.container[1] = []; parent.container[1][1] = obj.instanceid; var placeobject = new placeobject(); _this.setplaceobject(placeobject, obj.instanceid, 1, 1); _this.init(); }); var length = data.length; var src = ""; for (var i = 0; i < length; i++) { src += _fromcharcode(data[i]); } var jpegdata = swftag.parsejpegdata(data); image.src = "data:image/jpeg;base64," + swftag.base64encode(jpegdata); }; /** * resize */ stage.prototype.resize = function () { var _this = this; var div = _document.getelementbyid(_this.getname()); if (!div) { return 0; } var owidth = _this.optionwidth; var oheight = _this.optionheight; var element = _document.documentelement; var innerwidth = _max(element.clientwidth, window.innerwidth || 0); var innerheight = _max(element.clientheight, window.innerheight || 0); var parent = div.parentnode; if (parent.tagname !== "body") { innerwidth = parent.offsetwidth; innerheight = parent.offsetheight; } var screenwidth = (owidth > 0) ? owidth : innerwidth; var screenheight = (oheight > 0) ? oheight : innerheight; var basewidth = _this.getbasewidth(); var baseheight = _this.getbaseheight(); var scale = _min((screenwidth / basewidth), (screenheight / baseheight)); var width = basewidth * scale; var height = baseheight * scale; if (width !== _this.getwidth() || height !== _this.getheight()) { // div var style = div.style; style.width = width + "px"; style.height = height + "px"; style.top = 0; style.left = ((screenwidth / 2) - (width / 2)) + "px"; width *= devicepixelratio; height *= devicepixelratio; _this.setscale(scale); _this.setwidth(width); _this.setheight(height); // main var canvas = _this.context.canvas; canvas.width = width; canvas.height = height; // pre var precanvas = _this.precontext.canvas; precanvas.width = width; precanvas.height = height; var hitcanvas = _this.hitcontext.canvas; hitcanvas.width = width; hitcanvas.height = height; // tmp if (isandroid && ischrome) { var tmpcanvas = tmpcontext.canvas; tmpcanvas.width = width; tmpcanvas.height = height; } var mc = _this.getparent(); var mscale = scale * _devicepixelratio / 20; _this.setmatrix(mc.clonearray([mscale, 0, 0, mscale, 0, 0])); } }; /** * loaded */ stage.prototype.loaded = function () { // reset var _this = this; _this.buttonhits = []; _this.downeventhits = []; _this.moveeventhits = []; _this.upeventhits = []; _this.keydowneventhits = []; _this.keyupeventhits = []; _this.actions = []; // dom _this.deletenode(); var div = _document.getelementbyid(_this.getname()); if (div) { var mc = _this.getparent(); mc.initframe(); mc.addactions(_this); _this.executeaction(); // callback var callback = _this.callback; if (typeof callback === "function") { callback.call(window, mc); } _this.render(); _this.rendermain(); var ctx = _this.context; var canvas = ctx.canvas; // load sound if (istouch) { var loadsounds = _this.loadsounds; var slen = loadsounds.length; if (slen) { var loadsound = function () { canvas.removeeventlistener(startevent, loadsound); for (var i = slen; i--;) { if (!(i in loadsounds)) { continue; } var audio = loadsounds[i]; audio.load(); } }; canvas.addeventlistener(startevent, loadsound); } } canvas.addeventlistener(startevent, function (event) { _event = event; _this.touchstart(event); }); canvas.addeventlistener(moveevent, function (event) { _event = event; _this.touchmove(event); }); canvas.addeventlistener(endevent, function (event) { _event = event; _this.touchend(event); }); div.appendchild(canvas); _this.play(); } }; /** * deletenode */ stage.prototype.deletenode = function (tagid) { var div = _document.getelementbyid(tagid ? tagid : this.getname()); if (div) { var childnodes = div.childnodes; var length = childnodes.length; if (length) { while (length--) { div.removechild(childnodes[length]); } } } }; /** * nextframe */ stage.prototype.nextframe = function () { var _this = this; _this.downeventhits = []; _this.moveeventhits = []; _this.upeventhits = []; _this.keydowneventhits = []; _this.keyupeventhits = []; // mouse event var parent = _this.getparent(); var mouse = _this.mouse; var mouseevents = mouse.events; var onmousedown = mouseevents.onmousedown; if (onmousedown) { _this.downeventhits[_this.downeventhits.length] = {as: onmousedown, mc: parent}; } var onmousemove = mouseevents.onmousemove; if (onmousemove) { _this.moveeventhits[_this.moveeventhits.length] = {as: onmousemove, mc: parent}; } var onmouseup = mouseevents.onmouseup; if (onmouseup) { _this.upeventhits[_this.upeventhits.length] = {as: onmouseup, mc: parent}; } _this.putframe(); _this.addactions(); _this.executeaction(); _this.render(); _this.rendermain(); }; /** * putframe */ stage.prototype.putframe = function () { var _this = this; _this.newtags = []; var donetags = _this.donetags; var length = donetags.length; if (length) { clipevent.type = "enterframe"; var i = 0; while (i < length) { var tag = donetags[i]; tag.putframe(_this, clipevent); i++; } } }; /** * addactions */ stage.prototype.addactions = function () { var _this = this; var newtags = _this.newtags; var length = newtags.length; if (length) { var i = 0; while (i < length) { var tag = newtags[i]; tag.addactions(_this); i++; } } }; /** * render */ stage.prototype.render = function () { var _this = this; _this.buttonhits = []; _this.donetags = []; var ctx = _this.precontext; ctx.globalcompositeoperation = "source-over"; ctx.settransform(1, 0, 0, 1, 0, 0); var backgroundcolor = _this.getbackgroundcolor(); if (!backgroundcolor || backgroundcolor === "transparent") { // pre clear var canvas = ctx.canvas; ctx.clearrect(0, 0, canvas.width + 1, canvas.height + 1); // main clear var mainctx = _this.context; mainctx.clearrect(0, 0, canvas.width + 1, canvas.height + 1); } else { ctx.fillstyle = backgroundcolor; ctx.fillrect(0, 0, _this.getwidth() + 1, _this.getheight() + 1); } var mc = _this.getparent(); mc.render(ctx, _this._matrix, _this._colortransform, _this, true); }; /** * executeaction */ stage.prototype.executeaction = function () { var _this = this; if (_this.isaction && _this.actions.length) { _this.isaction = false; var i = 0; while (i < _this.actions.length) { var obj = _this.actions[i]; i++; var mc = obj.mc; var args = obj.args || []; if (!mc.active) { continue; } var actions = obj.as; if (typeof actions === "function") { actions.apply(mc, args); } else { var length = actions.length; if (!length) { continue; } var idx = 0; while (idx < length) { if (!(idx in actions)) { continue; } var action = actions[idx]; if (typeof action === "function") { action.apply(mc, args); } idx++; } } } } _this.actions = []; _this.isaction = true; }; /** * @param mc * @param as */ stage.prototype.buttonaction = function (mc, as) { var _this = this; _this.downeventhits = []; _this.moveeventhits = []; _this.upeventhits = []; _this.keydowneventhits = []; _this.keyupeventhits = []; as.execute(mc); _this.executeaction(); }; /* * main canvas */ stage.prototype.rendermain = function () { var _this = this; var precontext = _this.precontext; var precanvas = precontext.canvas; var width = precanvas.width; var height = precanvas.height; if (width > 0 && height > 0) { var ctx = _this.context; ctx.settransform(1,0,0,1,0,0); ctx.drawimage(precanvas, 0, 0, width, height); } }; /** * reset */ stage.prototype.reset = function () { var _this = this; _this.instanceid = 0; var mc = new movieclip(); mc.reset(); mc.setstage(_this); _this.parent = mc; _this.characters = []; _this.instances = []; _this.buttonhits = []; _this.downeventhits = []; _this.moveeventhits = []; _this.upeventhits = []; _this.keydowneventhits = []; _this.keyupeventhits = []; _this.sounds = []; _this.loadsounds = []; _this.actions = []; }; /** * init */ stage.prototype.init = function () { var _this = this; var tagid = _this.tagid; var div; if (_this.getid() in stages) { if (tagid) { if (_document.readystate === "loading") { var retry = function () { window.removeeventlistener("domcontentloaded", retry); _this.init(); }; window.addeventlistener("domcontentloaded", retry); return 0; } var container = _document.getelementbyid(tagid); if (!container) { alert("not found tag id:" + tagid); return 0; } div = _document.getelementbyid(_this.getname()); if (div) { _this.deletenode(); } else { div = _document.createelement("div"); div.id = _this.getname(); container.appendchild(div); } } else { _document.body.insertadjacenthtml("beforeend", "
"); } } div = _document.getelementbyid(_this.getname()); if (div) { _this.initstyle(div); _this.loading(); } if (!_this.canvas) { _this.initcanvas(); } _this.loadstatus++; _this.loadevent(); }; /** * @param div */ stage.prototype.initstyle = function (div) { var style; var _this = this; style = div.style; style.position = "relative"; style.top = "0"; style.backgroundcolor = "transparent"; style.overflow = "hidden"; style["-webkit-backface-visibility"] = "hidden"; var parent = div.parentnode; var owidth = _this.optionwidth; var oheight = _this.optionheight; var width; var height; if (parent.tagname === "body") { width = (owidth > 0) ? owidth : window.innerwidth; height = (oheight > 0) ? oheight : window.innerheight; } else { width = (owidth > 0) ? owidth : parent.offsetwidth; height = (oheight > 0) ? oheight : parent.offsetheight; } style.width = width + "px"; style.height = height + "px"; style['-webkit-user-select'] = "none"; }; /** * init canvas */ stage.prototype.initcanvas = function () { var _this = this; var style; var canvas = _document.createelement("canvas"); canvas.width = 1; canvas.height = 1; style = canvas.style; style.zindex = 0; style.position = "absolute"; style.top = 0; style.left = 0; style.zoom = 100 / _devicepixelratio + "%"; style["-webkit-tap-highlight-color"] = "rgba(0,0,0,0)"; style.moztransformorigin = "0 0"; style.moztransform = "scale(" + 1 / _devicepixelratio + ")"; if (isandroid) { canvas.addeventlistener("touchcancel", function () { _this.touchend(_event); }); } if (!istouch) { window.addeventlistener("keydown", keydownaction); window.addeventlistener("keyup", keyupaction); window.addeventlistener("keyup", function (event) { _keyevent = event; _this.touchend(event); }); } _this.context = canvas.getcontext("2d"); _this.canvas = canvas; var precanvas = _document.createelement("canvas"); precanvas.width = 1; precanvas.height = 1; _this.precontext = precanvas.getcontext("2d"); var hitcanvas = _document.createelement("canvas"); hitcanvas.width = 1; hitcanvas.height = 1; _this.hitcontext = hitcanvas.getcontext("2d"); }; /** * loading */ stage.prototype.loading = function () { var _this = this; var div = _document.getelementbyid(_this.getname()); var loadingid = _this.getname() + "_loading"; var css = ""; div.innerhtml = css; var loadingdiv = _document.createelement("div"); loadingdiv.id = loadingid; div.appendchild(loadingdiv); }; /** * @param url * @param options */ stage.prototype.reload = function (url, options) { var _this = this; _this.stop(); if (_this.loadstatus === 4) { _this.deletenode(); } _this.loadstatus = 0; _this.isload = false; _this.reset(); var swf2js = window.swf2js; return swf2js.load(url, { optionwidth: options.optionwidth || _this.optionwidth, optionheight: options.optionheight || _this.optionheight, callback: options.callback || _this.callback, tagid: options.tagid || _this.tagid, rendermode: options.rendermode || _this.rendermode, flashvars: options.flashvars || _this.flashvars, quality: options.quality || _this.quality, bgcolor: options.bgcolor || _this.bgcolor, stage: _this }); }; /** * @param url * @param frame * @param width * @param height * @returns {*} */ stage.prototype.output = function (url, frame, width, height) { var _this = this; if (!_this.isload || _this.stopflag) { _settimeout(function () { _this.output(url, frame, width, height); }, 500); return 0; } _this.stop(); frame = frame || 1; width = width || _this.getwidth(); height = height || _this.getheight(); // resize var mc = _this.getparent(); mc.reset(); mc.gotoandstop(frame); if (width !== _this.getwidth() || height !== _this.getheight()) { _this.optionwidth = width; _this.optionheight = height; _this.resize(); } // action mc.addactions(); // backgroundcolor var canvas = _this.precontext.canvas; var style = canvas.style; style.backgroundcolor = _this.backgroundcolor; // render _this.render(); // output var xmlhttprequest = new xmlhttprequest(); xmlhttprequest.open("post", url, true); xmlhttprequest.setrequestheader("content-type", "application/x-www-form-urlencoded"); xmlhttprequest.onreadystatechange = function () { var readystate = xmlhttprequest.readystate; if (readystate === 4) { var status = xmlhttprequest.status; switch (status) { case 200: case 304: console.log("output success"); break; default : alert(xmlhttprequest.statustext); break; } } }; var base64 = canvas.todataurl(); xmlhttprequest.send("data=" + encodeuricomponent(base64)); }; /** * @param event */ stage.prototype.hitcheck = function (event) { var _this = this; _this.ishit = false; var buttonhits = _this.buttonhits; var length = buttonhits.length; if (!length) { return 0; } var div = _document.getelementbyid(_this.getname()); var bounds = div.getboundingclientrect(); var x = window.pagexoffset + bounds.left; var y = window.pageyoffset + bounds.top; var touchx = 0; var touchy = 0; if (istouch) { var changedtouche = event.changedtouches[0]; touchx = changedtouche.pagex; touchy = changedtouche.pagey; } else { touchx = event.pagex; touchy = event.pagey; } touchx -= x; touchy -= y; var scale = _this.getscale(); touchx /= scale; touchy /= scale; var ctx = _this.hitcontext; var hitcanvas = ctx.canvas; var hitwidth = hitcanvas.width; var hitheight = hitcanvas.height; var chkx = touchx * scale * _devicepixelratio; var chky = touchy * scale * _devicepixelratio; if (_this.abcflag) { var parent = _this.getparent(); ctx.settransform(1, 0, 0, 1, 0, 0); ctx.clearrect(0, 0, hitwidth, hitheight); var ret = parent.hitcheck(ctx, [1,0,0,1,0,0], _this, chkx, chky); return (typeof ret === "object") ? ret : false; } for (var i = length; i--;) { if (!(i in buttonhits)) { continue; } var hitobj = buttonhits[i]; if (hitobj === undefined) { continue; } var hit = false; if (touchx >= hitobj.xmin && touchx <= hitobj.xmax && touchy >= hitobj.ymin && touchy <= hitobj.ymax ) { var matrix = hitobj.matrix; if (matrix) { var mc = hitobj.parent; var button = hitobj.button; ctx.settransform(1, 0, 0, 1, 0, 0); ctx.clearrect(0, 0, hitwidth, hitheight); if (button) { hit = button.renderhittest(ctx, matrix, _this, chkx, chky); } else { hit = mc.renderhittest(ctx, matrix, _this, chkx, chky); } } else { hit = true; } } if (hit) { event.preventdefault(); _this.ishit = true; return hitobj; } } return 0; }; /** * @param actions * @param caller * @param event */ stage.prototype.executeeventaction = function (actions, caller, event) { var args = event || []; if (actions) { if (typeof actions === "function") { actions.apply(caller, args); } else { var length = actions.length; if (length) { var i = 0; while (i < length) { var action = actions[i]; if (typeof action === "function") { action.apply(caller, args); } i++; } } } this.executeaction(); } }; /** * @param event */ stage.prototype.touchstart = function (event) { var _this = this; if (_this.touchstatus === "up") { _this.touchstatus = "down"; _this.ishit = false; _this.istouchevent = true; _this.touchendaction = null; var downeventhits = _this.downeventhits; var length = downeventhits.length; var mc, as; if (length) { event.preventdefault(); for (var i = 0; i < length; i++) { var obj = downeventhits[i]; mc = obj.mc; as = obj.as; if (!as) { as = mc.variables.onmousedown; } _this.executeeventaction(as, obj.mc); } _this.downeventhits = []; } var hitobj = _this.hitcheck(event); if (_this.ishit) { mc = hitobj.parent; if (mc.active) { mc.setbuttonstatus("down"); if (mc instanceof textfield) { _this.appendtextarea(mc, hitobj); } else { _this.executepress(mc, hitobj); } } if (_this.touchobj === null) { _this.touchobj = hitobj; } } } }; /** * @param mc * @param hitobj */ stage.prototype.executepress = function (mc, hitobj) { var _this = this; var isrender = false; var events; var press; var onpress; var rollover; var onrollover; var cevent = new clipevent(); events = mc.events; if (istouch) { rollover = events.rollover; if (rollover) { cevent.type = "rollover"; cevent.target = mc; _this.executeeventaction(rollover, mc, [cevent]); isrender = true; } onrollover = mc.variables.onrollover; if (typeof onrollover === "function") { _this.executeeventaction(onrollover, mc); isrender = true; } } events = mc.events; press = events.press; if (press) { cevent.type = "press"; cevent.target = mc; _this.executeeventaction(press, mc, [cevent]); isrender = true; } onpress = mc.variables.onpress; if (typeof onpress === "function") { _this.executeeventaction(onpress, mc); isrender = true; } var button = hitobj.button; if (button) { events = button.events; if (istouch) { rollover = events.rollover; if (rollover) { cevent.type = "rollover"; cevent.target = button; _this.executeeventaction(rollover, button, [cevent]); } onrollover = button.variables.onrollover; if (typeof onrollover === "function") { _this.executeeventaction(onrollover, button); } } button.setbuttonstatus("down"); if (istouch) { _this.executebuttonaction(button, mc, "condidletooverup"); } var actions = button.getactions(); var length = actions.length; if (length) { var touchobj = _this.touchobj; for (var idx = 0; idx < length; idx++) { if (!(idx in actions)) { continue; } var cond = actions[idx]; if (cond.condoverdowntooverup && touchobj === null) { _this.touchendaction = cond.actionscript; continue; } // enter var keypress = cond.condkeypress; if (hitobj.condkeypress === 13 && hitobj.condkeypress !== keypress) { continue; } if (istouch) { if (keypress === 13 || (keypress >= 48 && keypress <= 57) || cond.condoveruptooverdown ) { _this.buttonaction(mc, cond.actionscript); } } else { if (cond.condoveruptooverdown) { _this.buttonaction(mc, cond.actionscript); } } } } press = events.press; if (press) { cevent.type = "press"; cevent.target = button; _this.executeeventaction(press, button, [cevent]); } onpress = button.variables.onpress; if (typeof onpress === "function") { _this.executeeventaction(onpress, button); } var sprite = button.getsprite(); sprite.startsound(); button.addactions(_this); _this.executeaction(); isrender = true; } if (isrender) { _this.touchrender(); } }; /** * @param textfield * @param hitobj */ stage.prototype.appendtextarea = function (textfield, hitobj) { var _this = this; textfield.inputactive = true; var element = _document.getelementbyid(textfield.gettagname()); if (!element) { element = textfield.input; var variable = textfield.getproperty("variable"); var text; if (variable) { var mc = textfield.getparent(); text = mc.getproperty(variable); if (text === undefined) { text = textfield.getvariable("text"); } } if (text !== undefined) { element.value = text; } var maxlength = textfield.getvariable("maxchars"); if (maxlength) { element.maxlength = maxlength; } var border = textfield.getvariable("border"); if (border) { element.style.border = "1px solid black"; var color = textfield.getvariable("backgroundcolor"); element.style.backgroundcolor = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")"; } var scale = _this.getscale(); var left = hitobj.xmin; var top = hitobj.ymin; var width = hitobj.xmax - left; var height = hitobj.ymax - top; element.style.left = _ceil(left * scale) - 3 + "px"; element.style.top = _ceil(top * scale) - 3 + "px"; element.style.width = _ceil(width * scale) + 6 + "px"; element.style.height = _ceil(height * scale) + 6 + "px"; var div = _document.getelementbyid(_this.getname()); if (div) { div.appendchild(element); element.focus(); var focus = function (el) { return function () { el.focus(); }; }; _settimeout(focus(element), 10); } } }; /** * @param event */ stage.prototype.touchmove = function (event) { var _this = this; var overobj = _this.overobj; var moveeventhits = _this.moveeventhits; var length = moveeventhits.length; var mc, as, button, events; var dragover, ondragover, dragout, ondragout, rollover, onrollover, rollout, onrollout; var cevent = new clipevent(); if (length) { event.preventdefault(); for (var i = 0; i < length; i++) { var obj = moveeventhits[i]; mc = obj.mc; as = obj.as; if (!as) { as = mc.variables.onmousemove; } _this.executeeventaction(as, mc); } _this.moveeventhits = []; } if (!istouch || (istouch && _this.istouchevent)) { var hitobj = null; var touchobj = _this.touchobj; if (touchobj || _this.touchstatus === "up") { hitobj = _this.hitcheck(event); } var sprite; var isrender = false; if (!istouch) { var canvas = _this.canvas; if (_this.ishit || touchobj) { if (hitobj) { canvas.style.cursor = "pointer"; } else { canvas.style.cursor = "auto"; } } else { canvas.style.cursor = "auto"; } } if (touchobj) { button = touchobj.button; mc = touchobj.parent; if (mc.active) { _this.overobj = hitobj; if (hitobj && hitobj.parent.instanceid === mc.instanceid && hitobj.button === button ) { if (mc.getbuttonstatus() === "up") { mc.setbuttonstatus("down"); events = mc.events; dragover = events.dragover; if (dragover) { cevent.type = "dragover"; cevent.target = mc; isrender = true; _this.executeeventaction(dragover, mc, [cevent]); } ondragover = mc.variables.ondragover; if (typeof ondragover === "function") { isrender = true; _this.executeeventaction(ondragover, mc); } } if (button && button.getbuttonstatus() === "up") { button.setbuttonstatus("down"); sprite = button.getsprite(); sprite.startsound(); events = button.events; dragover = events.dragover; if (dragover) { cevent.type = "dragover"; cevent.target = button; isrender = true; _this.executeeventaction(dragover, button, [cevent]); } ondragover = button.variables.ondragover; if (typeof ondragover === "function") { isrender = true; _this.executeeventaction(ondragover, button); } button.addactions(_this); _this.executeaction(); } } else { if (mc.getbuttonstatus() === "down") { events = mc.events; dragout = events.dragout; if (dragout) { cevent.type = "dragout"; cevent.target = mc; isrender = true; _this.executeeventaction(dragout, mc, [cevent]); } ondragout = mc.variables.ondragout; if (typeof ondragout === "function") { isrender = true; _this.executeeventaction(ondragout, mc); } } mc.setbuttonstatus("up"); if (button) { if (button.getbuttonstatus() === "down") { button.setbuttonstatus("up"); events = button.events; dragout = events.dragout; if (dragout) { cevent.type = "dragout"; cevent.target = button; isrender = true; _this.executeeventaction(dragout, button, [cevent]); } ondragout = button.variables.ondragout; if (typeof ondragout === "function") { isrender = true; _this.executeeventaction(ondragout, button); } button.addactions(_this); _this.executeaction(); } } } } } else if (hitobj) { if (overobj) { button = overobj.button; if (button && button !== hitobj.button) { mc = overobj.parent; if (mc.active) { button.setbuttonstatus("up"); _this.executebuttonaction(button, mc, "condoveruptoidle"); } } } button = hitobj.button; mc = hitobj.parent; if (!istouch && mc.active) { if (!overobj || overobj.parent !== mc) { events = mc.events; rollover = events.rollover; if (rollover) { cevent.type = "rollover"; cevent.target = mc; isrender = true; _this.executeeventaction(rollover, mc, [cevent]); } onrollover = mc.variables.onrollover; if (typeof onrollover === "function") { isrender = true; _this.executeeventaction(onrollover, mc); } } } if (button) { button.setbuttonstatus("over"); sprite = button.getsprite(); sprite.startsound(); if (!istouch) { if (!overobj || overobj.button !== button) { isrender = true; _this.executebuttonaction(button, mc, "condidletooverup"); events = button.events; rollover = events.rollover; if (rollover) { cevent.type = "rollover"; cevent.target = button; isrender = true; _this.executeeventaction(rollover, button, [cevent]); } onrollover = button.variables.onrollover; if (typeof onrollover === "function") { _this.executeeventaction(onrollover, button); } } } button.addactions(_this); _this.executeaction(); } _this.overobj = hitobj; } else if (_this.touchstatus === "up") { _this.overobj = null; } // rollout if (!touchobj && overobj) { button = overobj.button; mc = overobj.parent; if (mc.active) { if (!hitobj || hitobj.parent !== mc) { mc.setbuttonstatus("up"); events = mc.events; rollout = events.rollout; if (rollout) { cevent.type = "rollout"; cevent.target = mc; isrender = true; _this.executeeventaction(rollout, mc, [cevent]); } onrollout = mc.variables.onrollout; if (typeof onrollout === "function") { isrender = true; _this.executeeventaction(onrollout, mc); } } if (button && (!hitobj || hitobj.button !== button)) { button.setbuttonstatus("up"); _this.executebuttonaction(button, mc, "condoveruptoidle"); events = button.events; rollout = events.rollout; if (rollout) { cevent.type = "rollout"; cevent.target = button; isrender = true; _this.executeeventaction(rollout, button, [cevent]); } onrollout = button.variables.onrollout; if (typeof onrollout === "function") { isrender = true; _this.executeeventaction(onrollout, button); } button.addactions(_this); _this.executeaction(); } } } if (isrender) { _this.touchrender(); } } var dragmc = _this.dragmc; if (dragmc) { event.preventdefault(); dragmc.executedrag(); _this.ishit = true; } }; /** * @param event */ stage.prototype.touchend = function (event) { var _this = this; var cevent = new clipevent(); var button, mc, as, events, release, onrelease, releaseoutside, onreleaseoutside; var touchobj = _this.touchobj; if (touchobj) { button = touchobj.button; if (button) { button.setbuttonstatus("up"); } } var upeventhits = _this.upeventhits; var length = upeventhits.length; if (length) { event.preventdefault(); for (var i = 0; i < length; i++) { var obj = upeventhits[i]; mc = obj.mc; as = obj.as; if (!as) { as = mc.variables.onmouseup; } _this.executeeventaction(as, obj.mc); } _this.upeventhits = []; } var hitobj = _this.hitcheck(event); var dragmc = _this.dragmc; if (dragmc) { hitobj = touchobj; _this.ishit = true; } var isrender = false; if (touchobj) { mc = touchobj.parent; mc.setbuttonstatus("up"); button = touchobj.button; if (_this.ishit) { var touchendaction = _this.touchendaction; if (mc.active) { if (mc === hitobj.parent) { if (touchendaction !== null) { _this.buttonaction(mc, touchendaction); isrender = true; } events = mc.events; release = events.release; if (release) { cevent.type = "release"; cevent.target = mc; _this.executeeventaction(release, mc, [cevent]); isrender = true; } onrelease = mc.variables.onrelease; if (typeof onrelease === "function") { _this.executeeventaction(onrelease, mc); isrender = true; } } if (button) { if (button === hitobj.button) { events = button.events; release = events.release; if (release) { cevent.type = "release"; cevent.target = button; _this.executeeventaction(release, button, [cevent]); } onrelease = button.variables.onrelease; if (typeof onrelease === "function") { _this.executeeventaction(onrelease, button); } } var status = "up"; if (!istouch) { if (hitobj && hitobj.button === button) { status = "over"; } } button.setbuttonstatus(status); var sprite = button.getsprite("hit"); sprite.startsound(); button.addactions(_this); _this.executeaction(); isrender = true; } } } if (mc.active && (!hitobj || mc !== hitobj.parent)) { events = mc.events; releaseoutside = events.releaseoutside; if (releaseoutside) { cevent.type = "releaseoutside"; cevent.target = mc; _this.executeeventaction(releaseoutside, mc, [cevent]); isrender = true; } onreleaseoutside = mc.variables.onreleaseoutside; if (typeof onreleaseoutside === "function") { _this.executeeventaction(onreleaseoutside, mc); isrender = true; } } if (button && (!hitobj || button !== hitobj.button)) { isrender = true; events = button.events; releaseoutside = events.releaseoutside; if (releaseoutside) { cevent.type = "releaseoutside"; cevent.target = button; _this.executeeventaction(releaseoutside, button, [cevent]); isrender = true; } onreleaseoutside = button.variables.onreleaseoutside; if (typeof onreleaseoutside === "function") { _this.executeeventaction(onreleaseoutside, button); } button.setbuttonstatus("up"); button.addactions(_this); _this.executeaction(); } } _this.ishit = false; _this.istouchevent = false; _this.touchobj = null; _this.touchstatus = "up"; if (!istouch) { _this.hitcheck(event); var canvas = _this.canvas; if (_this.ishit) { canvas.style.cursor = "pointer"; } else { canvas.style.cursor = "auto"; } } if (hitobj) { var rollover, onrollover; mc = hitobj.parent; if (!touchobj || mc !== touchobj.parent) { events = mc.events; rollover = events.rollover; if (rollover) { isrender = true; cevent.type = "rollover"; cevent.target = mc; _this.executeeventaction(rollover, mc, [cevent]); } onrollover = mc.variables.onrollover; if (typeof onrollover === "function") { isrender = true; _this.executeeventaction(onrollover, mc); } } button = hitobj.button; if (button) { if (!touchobj || button !== touchobj.button) { events = button.events; rollover = events.rollover; if (rollover) { isrender = true; cevent.type = "rollover"; cevent.target = button; _this.executeeventaction(rollover, button, [cevent]); } onrollover = button.variables.onrollover; if (typeof onrollover === "function") { isrender = true; _this.executeeventaction(onrollover, button); } } } } if (isrender) { event.preventdefault(); _this.touchrender(); } _keyevent = null; }; /** * @param button * @param mc * @param status */ stage.prototype.executebuttonaction = function (button, mc, status) { var _this = this; var actions = button.getactions(); var length = actions.length; if (length) { for (var idx = 0; idx < length; idx++) { if (!(idx in actions)) { continue; } var cond = actions[idx]; if (!cond[status]) { continue; } _this.buttonaction(mc, cond.actionscript); } } }; /** * touchrender */ stage.prototype.touchrender = function () { var _this = this; _this.render(); _this.rendermain(); }; /** * @constructor */ var swf2js = function () {}; /** * @type {dropshadowfilter} */ swf2js.prototype.dropshadowfilter = dropshadowfilter; /** * @type {blurfilter} */ swf2js.prototype.blurfilter = blurfilter; /** * @type {glowfilter} */ swf2js.prototype.glowfilter = glowfilter; /** * @type {bevelfilter} */ swf2js.prototype.bevelfilter = bevelfilter; /** * @type {gradientglowfilter} */ swf2js.prototype.gradientglowfilter = gradientglowfilter; /** * @type {convolutionfilter} */ swf2js.prototype.convolutionfilter = convolutionfilter; /** * @type {colormatrixfilter} */ swf2js.prototype.colormatrixfilter = colormatrixfilter; /** * @type {gradientbevelfilter} */ swf2js.prototype.gradientbevelfilter = gradientbevelfilter; /** * @type {bitmapfilter} */ swf2js.prototype.bitmapfilter = bitmapfilter; /** * @type {loadvars} */ swf2js.prototype.loadvars = loadvars; /** * @param url * @param options */ swf2js.prototype.load = function (url, options) { // develop only if (url === "develop") { url = location.search.substr(1).split("&")[0]; } if (url) { var stage = (options && options.stage instanceof stage) ? options.stage : new stage(); stage.setoptions(options); stages[stage.getid()] = stage; stage.init(); var xmlhttprequest = new xmlhttprequest(); xmlhttprequest.open("get", url, true); if (isxhr2) { xmlhttprequest.responsetype = "arraybuffer"; } else { xmlhttprequest.overridemimetype("text/plain; charset=x-user-defined"); } xmlhttprequest.onreadystatechange = function () { var readystate = xmlhttprequest.readystate; if (readystate === 4) { var status = xmlhttprequest.status; switch (status) { case 200: case 304: var data = (isxhr2) ? xmlhttprequest.response : xmlhttprequest.responsetext; stage.parse(data, url); cachestore.reset(); break; default : alert(xmlhttprequest.statustext); break; } } }; xmlhttprequest.send(null); } else { alert("please set swf url"); } }; /** * @param url * @param options * @returns {*} */ swf2js.prototype.reload = function(url, options) { if (!stageid) { return this.load(url, options); } var stage = stages[0]; for (var i in stages) { if (!stages.hasownproperty(i)) { continue; } var target = stages[i]; target.stop(); if (i) { target.deletenode(target.tagid); target = void 0; } } stageid = 1; stages = []; loadstages = []; stages[0] = stage; stage.reload(url, options); }; /** * @param width * @param height * @param fps * @param options * @returns {movieclip} */ swf2js.prototype.createrootmovieclip = function(width, height, fps, options) { var stage = new stage(); width = width || 240; height = height || 240; fps = fps || 60; stage.setbasewidth(width); stage.setbaseheight(height); stage.setframerate(fps); stage.setoptions(options); stages[stage.getid()] = stage; stage.init(); stage.isload = true; if (_document.readystate === "loading") { var reload = function() { window.removeeventlistener("domcontentloaded", reload, false); stage.resize(); stage.loaded(); }; window.addeventlistener("domcontentloaded", reload, false); } return stage.getparent(); }; window.swf2js = new swf2js(); })(window);}