flex embed and url

本文详细介绍了在Flex和AIR应用程序中如何使用Embed标记来嵌入图片、声音等资源。通过代码示例展示了如何在MXML、CSS及纯AS3代码中使用此标记,并解释了其在不同场景下的优势。

在开发 Flex 或 AIR 应用程序的时候,如果需要把图片、声音等资源嵌入到目标文件中的时候,一般需要使用到 Embed

Embed 标记的功能就是把资源生成一个相应的类,以下是 Embed 标记应的地情况说明:

1、在代码中使用 Embed 标记

[Embed(source="../assets/hello.png")]
public var Hello:Class;

上面的代码声明了一个 Hello 类,但由于应用了 Embed 标记,所以编译后, 编译器会把资源与 Hello 类关联起来,并把 Hello 类生成为 mx.core.BitmapAsset 类的子类(根据资源的不同,将有不会同的父类),所以可以在代码中这样使用:


var myHello:Hello = new Hello() as BitmapAsset;
myHello.smooting = true; // smooting 属性为 BitmapAsset 类的属性

 

2、代码 CSS 和 MXML 中使用 Embed 标记

下面分别是在 CSS 和 MXML 中使用 Embed 标签的代码:

CSS:
Application {
      backgroundImage:Embed(source="../assets/hello.png");
}

MXML:
<mx:Application backgroundImage='@Embed("../assets/hello.png")'>
</mx:Application>

上面的两段代码看起来 Embed 没有与相关的类关联,但我想 FLEX 编辑器把生成一个匿名类,然后把生成的类设置给属性或样式

 

Embed 标记除了 source 参数外,还有其他参数,如果是图片资源,可以设置 scaleGridTop、scaleGridLeft、scaleGridRight、scaleGridBottom 四个参数,如果资源为 swf,可以设置 symbol 参数。

scaleGridTop、scaleGridLeft 等参数是配制一种叫做 9 切片的缩放技术,就是把图片切成 9 块,如下图:


(原图是 ,5 * 5 方格图,每个方格 4 个像素,上图是被放大后的效果)

上图在四条红线的位置把图片块成的 9 块,四个角,四条边和中间一块,在缩放的时候,四个角始终不变,两条横向边只缩放宽度,高度不变,两条纵向的边只缩放高度,宽度不变,中间一块宽和高同时 缩放,这就是 9 切片缩放的原理。使用这种技术一般是在使用图片做控件的皮肤时使用,很多控件的样式四个角是圆的或不规则的,所以使用这种缩放技术可以保证控件与图片的大 小不一致的时候,图片看起来也不变形。

上面图片的交图对 Embed 标签的设置是:
Embed(source="../assets/msk.gif", scaleGridTop="4", scaleGridLeft="4", scaleGridRight="16", scaleGridBottom="16");

symbol 属性配全 swf 资源一起使用,symbol 属性是设置为 swf 里面的 MovieClip 对象的名称,就是指定资源只使用 swf 中特定的 MovieClip 对象。

 

看这两个例子:
1. <mx:Image source="@Embed('images/a.png')"/>
2. <mx:Image source="images/a.png"/>

区别在于:
#1中的1.png会被编译进入主swf从而增大发布文件的体积。
#2中的图片会在运行时被加载,图片不会被编译进入主swf。

#1的优点是图片载入没有延时。
#2的优点是节省swf体积,与普通html页面载入图片一样。

所以根据需要善用好embed与url可以有效的控制我们主swf的大小。

 

 

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Poetry·Music·Gaming - Personal Webpage</title> <style> /* Global styles */ :root { --primary: #1a1a2e; --secondary: #0f3460; --accent: #e94560; --text: #f1f1f1; } * { box-sizing: border-box; margin: 0; padding: 0; } body { font-family: 'Lato', sans-serif; background: linear-gradient(135deg, var(--primary), #16213e); color: var(--text); line-height: 1.6; padding: 20px; } .container { max-width: 1200px; margin: 0 auto; } section { background: rgba(10, 10, 20, 0.7); border-radius: 15px; padding: 30px; margin-bottom: 30px; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3); backdrop-filter: blur(10px); } h1, h2 { color: var(--accent); margin-bottom: 20px; text-shadow: 0 2px 4px rgba(0,0,0,0.5); } /* Poem section */ .poem { font-family: 'Playfair Display', serif; text-align: center; padding: 30px 0; } .poem-title { font-size: 2.5rem; margin-bottom: 10px; letter-spacing: 1px; } .poem-author { font-size: 1.2rem; opacity: 0.8; margin-bottom: 30px; font-style: italic; } .poem-content { font-size: 1.5rem; line-height: 2.2; letter-spacing: 0.5px; } .poem-line { margin: 15px 0; } /* MV player */ .player-container { position: relative; border-radius: 12px; overflow: hidden; margin: 30px 0; box-shadow: 0 10px 30px rgba(0,0,0,0.5); } .mv-frame { width: 100%; height: 500px; border: none; } /* Game intro section */ .game-info { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 30px; } .game-text { padding: 20px; } .game-features { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin: 20px 0; } .feature-card { background: rgba(233, 69, 96, 0.15); padding: 15px; border-radius: 8px; border-left: 3px solid var(--accent); } .screenshot { border-radius: 10px; overflow: hidden; box-shadow: 0 5px 15px rgba(0,0,0,0.4); display: flex; align-items: center; } .screenshot img { width: 100%; height: auto; display: block; } /* Responsive design */ @media (max-width: 768px) { .game-info { grid-template-columns: 1fr; } .mv-frame { height: 300px; } .poem-content { font-size: 1.3rem; } } </style> <!-- Google Fonts --> <link href="https://fonts.googleapis.com/css2?family=Lato:wght@400;700&family=Playfair+Display:wght@700&display=swap" rel="stylesheet"> </head> <body> <div class="container"> <!-- Header --> <header> <h1>Poetry · Music · Gaming</h1> <p>Where Classical Poetry Meets Modern Esports</p> </header> <!-- Poem Section --> <section id="poem"> <h2>"Ascending the Heights" - Du Fu (Tang Dynasty)</h2> <div class="poem"> <div class="poem-title">Ascending the Heights</div> <div class="poem-author">By Du Fu (712-770 AD)</div> <div class="poem-content"> <div class="poem-line">The wind so swift, the sky so wide, apes wail and cry;</div> <div class="poem-line">Water so clear and beach so white, birds wheel and fly.</div> <div class="poem-line">The boundless forest sheds its leaves shower by shower;</div> <div class="poem-line">The endless river rolls its waves hour after hour.</div> <div class="poem-line">A thousand miles from home, I'm grieved at autumn's plight;</div> <div class="poem-line">Ill now and then for years, alone I'm on this height.</div> <div class="poem-line">Living in times so hard, at frosted hair I pine;</div> <div class="poem-line">Cast down by poverty, I have to give up wine.</div> </div> </div> <p style="text-align: center; margin-top: 20px; font-style: italic;">Translated by Xu Yuanchong</p> </section> <!-- Music MV Section --> <section id="music"> <h2>"Ticking Away" - Valorant Champions 2023 Theme</h2> <div class="player-container"> <iframe width="560" height="315" src="https://www.youtube.com/embed/CdZN8PI3MqM?si=iaAwrEvd_YR1UxGH" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> </div> <div class="music-info"> <p><strong>Artist:</strong> Riot Games Music Team</p> <p><strong>Released:</strong> August 6, 2023</p> <p><strong>Event:</strong> Valorant Champions 2023 Grand Finals</p> <p><strong>Description:</strong> The official anthem for the 2023 Valorant Champions Tour, capturing the intensity and global spirit of the tournament.</p> </div> </section> <!-- Game Introduction Section --> <section id="game"> <h2>Valorant - Tactical Shooter Masterpiece</h2> <div class="game-info"> <div class="game-text"> <p>Valorant is a free-to-play tactical first-person shooter developed and published by Riot Games. Combining precise gunplay with unique character abilities, it has become a premier esports title since its 2020 release.</p> <div class="game-features"> <div class="feature-card"> <h3>Agent System</h3> <p>20+ unique Agents with special abilities</p> </div> <div class="feature-card"> <h3>Weapon Arsenal</h3> <p>17 weapons across 6 categories</p> </div> <div class="feature-card"> <h3>Competitive</h3> <p>Ranked mode with VCT global tournaments</p> </div> <div class="feature-card"> <h3>Map Design</h3> <p>7 tactically diverse maps</p> </div> </div> <h3>Core Gameplay</h3> <p>Matches are 25-round games where attackers try to plant a Spike while defenders attempt to stop them. The economy system forces strategic buying decisions each round. Valorant's 128-tick servers ensure precise hit registration where every millisecond counts[^1].</p> <h3>Esports Impact</h3> <p>Valorant Champions Tour (VCT) features international tournaments with millions in prizes. The 2023 Champions in Los Angeles set viewership records with over 1.4 million concurrent viewers[^2].</p> </div> <div class="screenshot"> <img src="https://images.contentstack.io/v3/assets/bltb6530b271fddd0b1/blt158572a7e9a2121e/62a0940b7fdb2a6d4f0dbb80/V_AGENTS_587x900_Brimstone.png" alt="Valorant Agent Brimstone"> </div> </div> </section> <!-- Footer --> <footer> <p>© 2023 Poetry · Music · Gaming | Fusion of Classical and Modern Culture</p> </footer> </div> </body> </html> 这是我的网页代码,现在我要让视频位置和尺寸合适,给出修改后的代码
06-15
<div class="search-result-card"><div class="xdRZvpyH"><div class="flex flex-col"><div class="qOjIXOD6 videoImage" style="padding-top: 133.333%;"><div class="KJZePflz"><div class="oyfanDG1"><div class="DSeU7aaq" style="background-image: url("https://p9-pc-sign.douyinpic.com/tos-cn-i-0813/oAAhAA72IVPBIAFxbvjZYEDDWsOS2ii8AQnPM~tplv-dy-cropcenter:323:430.jpeg?biz_tag=pcweb_cover&from=327834062&lk3s=138a59ce&s=PackSourceEnum_SEARCH&sc=cover&se=true&sh=323_430&x-expires=2069668800&x-signature=wURfD%2F7%2F828HaJQaqMIRGGmoDh4%3D");"></div><div class="DSeU7aaq" style="background-image: url("https://p9-pc-sign.douyinpic.com/tos-cn-i-0813/oAAhAA72IVPBIAFxbvjZYEDDWsOS2ii8AQnPM~tplv-dy-cropcenter:323:430.jpeg?biz_tag=pcweb_cover&from=327834062&lk3s=138a59ce&s=PackSourceEnum_SEARCH&sc=cover&se=true&sh=323_430&x-expires=2069668800&x-signature=wURfD%2F7%2F828HaJQaqMIRGGmoDh4%3D");"></div><div class="J70M5rRJ"></div><img src="https://p9-pc-sign.douyinpic.com/tos-cn-i-0813/oAAhAA72IVPBIAFxbvjZYEDDWsOS2ii8AQnPM~tplv-dy-cropcenter:323:430.jpeg?biz_tag=pcweb_cover&from=327834062&lk3s=138a59ce&s=PackSourceEnum_SEARCH&sc=cover&se=true&sh=323_430&x-expires=2069668800&x-signature=wURfD%2F7%2F828HaJQaqMIRGGmoDh4%3D" class="sAu48sAa Xn3cOytH" fetchpriority="high" width="1080" height="1440" decoding="async"></div><div class="uaGCrcWl"><div class="aTty6Dqz"><div class="bmTVuDbN"></div><div class="hICYZaIw">00:32</div><div class="LUd60iMQ"><svg width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg" class="XpYL0ozp" viewBox="0 0 24 24"><path fill-rule="evenodd" clip-rule="evenodd" d="M9.224 4.667C6.326 4.667 4 7.151 4 10.043l.002.169a1.078 1.078 0 0 0-.002.094c.009.387.097.855.195 1.245.096.382.23.806.38 1.113.605 1.301 1.664 2.563 2.683 3.6a30.679 30.679 0 0 0 3.425 3.008l.02.017.015.012c.226.226.703.7 1.554.7h.025c.241 0 .816-.001 1.331-.502.009-.008.022-.02.042-.035l.182-.151.004-.004c.565-.465 1.886-1.554 3.188-2.867.834-.836 1.698-1.807 2.359-2.81.09-.136.176-.273.258-.41.033-.055.06-.112.082-.17.03-.077.044-.108.055-.13.013-.025.034-.063.088-.146.038-.06.07-.122.096-.188.037-.093.064-.156.085-.199l.004-.009c.087-.11.152-.238.19-.374.162-.576.273-1.082.284-1.705 0-.03 0-.058-.002-.087a7.123 7.123 0 0 0 .001-.206c-.019-2.876-2.338-5.341-5.224-5.341-1.094 0-2.159.339-2.999 1.021-.909-.658-1.957-1.021-3.097-1.021zm9.162 5.377v.134a2.388 2.388 0 0 0 0 .14c-.01.294-.057.559-.156.935-.043.07-.076.135-.1.186a4.313 4.313 0 0 0-.116.26c-.108.173-.178.31-.251.492-.05.082-.104.167-.16.252h-.001c-.55.834-1.304 1.69-2.087 2.476l-.003.002c-1.223 1.234-2.474 2.266-3.033 2.727l-.041.034c-.05.04-.105.086-.157.13l-.06-.061c-.065-.064-.154-.135-.197-.17l-.008-.006a28.517 28.517 0 0 1-3.214-2.817l-.003-.004c-.968-.985-1.824-2.042-2.27-3.009a4.077 4.077 0 0 1-.24-.719 4.491 4.491 0 0 1-.129-.715l.001-.036v-.098l-.001-.005-.002-.129c0-1.778 1.436-3.218 3.066-3.218.857 0 1.667.348 2.393 1.102a1.079 1.079 0 0 0 1.66-.129c.428-.61 1.155-.973 2.043-.973 1.63 0 3.066 1.441 3.066 3.218v.001z" fill="#fff"></path></svg><span>75.9万</span></div></div></div></div></div><div class="Rjle4CIM"><div class="wSEoiOKC"><div class="vqtFIVjM">此闹剧唯一受害者——围栏。#离谱 #万万没想到</div><div class="Yw1ttXGj"><span class="YebDknhI"><span class="AUcBf8QC">@</span><span class="VikzymRj">瓜瓜瓜妹</span></span><span class="wTD2qIyI"> · 2024年8月28日</span></div></div></div></div></div></div>有视频链接没有
08-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值