将 html/javascript-code 注入 Flex AS3 HTML class
Inject html/javascript-code into Flex AS3 HTML class
我需要将 html/javascript-code 注入到每个加载的 HTML 中。
程序使用了HTML
class。
我反汇编了原来的Flex3文件,发现this。
重要的?函数我modified/tested:
public function set htmlText(value:String) : void
{
_htmlText = value;
htmlTextChanged = true;
_location = null;
locationChanged = false;
invalidateProperties();
invalidateSize();
invalidateDisplayList();
dispatchEvent(new Event("htmlTextChanged"));
}
public function set location(value:String) : void
{
_location = value;
locationChanged = true;
_htmlText = null;
htmlTextChanged = false;
invalidateProperties();
invalidateSize();
invalidateDisplayList();
dispatchEvent(new Event("locationChange"));
}
我成功更改了设置位置的代码并设法只加载了 http://www.example.com/。
但是,当使用 location
设置位置时,htmlText
setter 似乎不会被调用。
这是我试过的:
public function set htmlText(value:String) : void
{
_htmlText = "<html><h1>test</h1></html>" + value;
htmlTextChanged = true;
_location = null;
locationChanged = false;
invalidateProperties();
invalidateSize();
invalidateDisplayList();
dispatchEvent(new Event("htmlTextChanged"));
}
我需要查看 flash.net.HTMLloader
,但找不到文件。
我希望有人能帮助我并告诉我 HTML-代码从何处加载以及在哪里呈现,以便我可以在之前对其进行修改。
提前致谢。
我不知道你想在你的 html 内容中注入什么,但我认为你可以在 HTMLLoader
of your HTML
component is fired, using the window
对象上的完整事件是:
The global JavaScript object for the content loaded into the HTML control..
因此您可以像在任何 JavaSript 代码中一样使用它(window
对象)。
// for the example, I took the page of your current question
var url:String = '
html_content.location = url;
html_content.htmlLoader.addEventListener(Event.COMPLETE, on_complete);
和
protected function on_complete(e:Event): void
{
var html_loader:HTMLLoader = html_content.htmlLoader;
var document = html_loader.window.document;
var _head = document.getElementsByTagName('head')[0];
// create a new css class
var _class = '.akmozo { background: #ff9900; color: white; padding: 2px; }';
var _style = document.createElement('style');
_style.appendChild(document.createTextNode(_class));
// create a new js function
var _js = 'function click_me(){ alert("Hello, how are you ?"); }';
var _script = document.createElement('script');
_script.appendChild(document.createTextNode(_js));
_head.appendChild(_style);
_head.appendChild(_script);
// change the page's top bar background color to green
if(document.querySelector('.topbar-wrapper'))
{
document.querySelector('.topbar-wrapper').style.backgroundColor = 'green';
}
// edit the title of your question,
// apply the new css class and call the js function
if(document.querySelector('.question-hyperlink'))
{
document.querySelector('.question-hyperlink').innerHTML += ' [ edited by <span class="akmozo" onclick="click_me()">AKMOZO</span> ]';
}
// change the SO logo to my avatar
if(document.getElementById('hlogo'))
{
document.getElementById('hlogo').style.backgroundImage = 'url(https://i.stack.imgur.com/YAKpv.png?s=50)';
document.getElementById('hlogo').style.backgroundRepeat = 'no-repeat';
}
// do some changes in your comment
if(document.querySelector('#comment-52605069'))
{
document.querySelector('#comment-52605069 .comment-copy').style.color = 'green';
document.querySelector('#comment-52605069 .comment-copy').style.fontWeight = 700;
document.querySelector('#comment-52605069 .comment-copy').style.fontSize = '24px';
document.querySelector('#comment-52605069 .comment-user').innerHTML = '<span class="akmozo">akmozo</span>';
}
}
这段代码会给你这样的东西:
当然,我只是想举例说明您可以做什么,您必须根据自己的需要改进和调整此代码。
希望能帮到你。
我需要将 html/javascript-code 注入到每个加载的 HTML 中。
程序使用了HTML
class。
我反汇编了原来的Flex3文件,发现this。
重要的?函数我modified/tested:
public function set htmlText(value:String) : void
{
_htmlText = value;
htmlTextChanged = true;
_location = null;
locationChanged = false;
invalidateProperties();
invalidateSize();
invalidateDisplayList();
dispatchEvent(new Event("htmlTextChanged"));
}
public function set location(value:String) : void
{
_location = value;
locationChanged = true;
_htmlText = null;
htmlTextChanged = false;
invalidateProperties();
invalidateSize();
invalidateDisplayList();
dispatchEvent(new Event("locationChange"));
}
我成功更改了设置位置的代码并设法只加载了 http://www.example.com/。
但是,当使用 location
设置位置时,htmlText
setter 似乎不会被调用。
这是我试过的:
public function set htmlText(value:String) : void
{
_htmlText = "<html><h1>test</h1></html>" + value;
htmlTextChanged = true;
_location = null;
locationChanged = false;
invalidateProperties();
invalidateSize();
invalidateDisplayList();
dispatchEvent(new Event("htmlTextChanged"));
}
我需要查看 flash.net.HTMLloader
,但找不到文件。
我希望有人能帮助我并告诉我 HTML-代码从何处加载以及在哪里呈现,以便我可以在之前对其进行修改。
提前致谢。
我不知道你想在你的 html 内容中注入什么,但我认为你可以在 HTMLLoader
of your HTML
component is fired, using the window
对象上的完整事件是:
The global JavaScript object for the content loaded into the HTML control..
因此您可以像在任何 JavaSript 代码中一样使用它(window
对象)。
// for the example, I took the page of your current question
var url:String = '
html_content.location = url;
html_content.htmlLoader.addEventListener(Event.COMPLETE, on_complete);
和
protected function on_complete(e:Event): void
{
var html_loader:HTMLLoader = html_content.htmlLoader;
var document = html_loader.window.document;
var _head = document.getElementsByTagName('head')[0];
// create a new css class
var _class = '.akmozo { background: #ff9900; color: white; padding: 2px; }';
var _style = document.createElement('style');
_style.appendChild(document.createTextNode(_class));
// create a new js function
var _js = 'function click_me(){ alert("Hello, how are you ?"); }';
var _script = document.createElement('script');
_script.appendChild(document.createTextNode(_js));
_head.appendChild(_style);
_head.appendChild(_script);
// change the page's top bar background color to green
if(document.querySelector('.topbar-wrapper'))
{
document.querySelector('.topbar-wrapper').style.backgroundColor = 'green';
}
// edit the title of your question,
// apply the new css class and call the js function
if(document.querySelector('.question-hyperlink'))
{
document.querySelector('.question-hyperlink').innerHTML += ' [ edited by <span class="akmozo" onclick="click_me()">AKMOZO</span> ]';
}
// change the SO logo to my avatar
if(document.getElementById('hlogo'))
{
document.getElementById('hlogo').style.backgroundImage = 'url(https://i.stack.imgur.com/YAKpv.png?s=50)';
document.getElementById('hlogo').style.backgroundRepeat = 'no-repeat';
}
// do some changes in your comment
if(document.querySelector('#comment-52605069'))
{
document.querySelector('#comment-52605069 .comment-copy').style.color = 'green';
document.querySelector('#comment-52605069 .comment-copy').style.fontWeight = 700;
document.querySelector('#comment-52605069 .comment-copy').style.fontSize = '24px';
document.querySelector('#comment-52605069 .comment-user').innerHTML = '<span class="akmozo">akmozo</span>';
}
}
这段代码会给你这样的东西:
当然,我只是想举例说明您可以做什么,您必须根据自己的需要改进和调整此代码。
希望能帮到你。