如何获得嵌入式图像/ swf的大小?(How to get the size of an embedded image / swf?)
通常情况下,如果您从URL加载图像,您可以执行以下操作:
m_image = new Image(); m_image.addEventListener(Event.COMPLETE, image_completeHandler, false, 0, true); m_image.source = "http://www.example.com/image.jpg"; private function image_completeHandler(event:Event):void { // Image content has now loaded, we need to wait for it to validate it's size m_image.addEventListener(FlexEvent.UPDATE_COMPLETE, image_updateCompleteHandler, false, 0, true); } private function image_updateCompleteHandler(event:FlexEvent):void { // Do stuff with width / height }
但是,如果将源设置为嵌入式图像类,则完整的事件不会触发。 所以我的问题是,如何获得嵌入式图像/ swf的宽度/高度?
Normally if you were loading an image from a URL you would do the following:
m_image = new Image(); m_image.addEventListener(Event.COMPLETE, image_completeHandler, false, 0, true); m_image.source = "http://www.example.com/image.jpg"; private function image_completeHandler(event:Event):void { // Image content has now loaded, we need to wait for it to validate it's size m_image.addEventListener(FlexEvent.UPDATE_COMPLETE, image_updateCompleteHandler, false, 0, true); } private function image_updateCompleteHandler(event:FlexEvent):void { // Do stuff with width / height }
But, if you set the source to an embedded image class, the complete event doesn't appear to fire. So my question is, how can you get the width / height of an embedded image / swf?
原文:https://stackoverflow.com/questions/1229949
更新时间:2022-02-15 14:02
最满意答案
该行评估函数并将
undefined
的返回值设置为Dog.prototype.bark
:Dog.prototype.bark = barkWithMe();
将其更改为:
Dog.prototype.bark = barkWithMe;
This line evaluates the function and sets the return value
undefined
toDog.prototype.bark
:Dog.prototype.bark = barkWithMe();
Change it to:
Dog.prototype.bark = barkWithMe;
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
使用函数作为原型(Using function as prototype)[2022-04-03]
是的,由于JavaScript原型继承的灵活性,两种方式都是允许的。 首先让我们看看这两种情况下的原型链。 为了简单,我只考虑文字对象。 Object.prototype与函数原型 最后使用literal创建的对象Object.prototype (internal [[Prototype]] )的最后一个值是Object.prototype 。 例如: /*Example 1*/ var o = { foo: 1, bar: 2 } Prototypical chain: o -> Object.pro ... -
为什么一些原型函数会覆盖工作而其他原因不起作用?(Why do some prototype function overrides work and others do not? [duplicate])[2023-01-01]
在JavaScript中没有覆盖的真正概念。 使用new实例化时,只需在新对象中引用原型对象(如__proto__ ),对对象中不存在的属性的任何访问都将路由到原型对象。 仍然,调用“构造函数”函数,以便在调用者使用之前有机会修改新对象。 在构造函数中,正如您所知,新对象被引用this对象。 在您的情况下,您实际上将swingSword函数添加到之前不存在的新对象。 如果没有,所有对swingSword属性(函数)的访问都将回swingSword原型。 换句话说,你“覆盖”原型功能,而不是相反! 确保您了解 ... -
添加到另一个原型的实例的原型:JavaScript(Adding to the prototype of an instance of another prototype: JavaScript)[2023-12-11]
组织代码,以便在创建原型对象后定义所有原型方法。 例如: Pirault.prototype = Object.create(Person.prototype); Pirault.prototype.constructor = Pirault; Pirault.prototype.mySkill = function(){ console.log('My skill is '+this.skill); } 演示 。 就目前而言,你正确地在原型上定义一个方法 - 但是当一个对象(由Object.c ... -
为什么对Function.prototype函数的引用不起作用(Why do references to Function.prototype functions not work)[2021-12-04]
请注意,所有函数共享相同的call方法,从Function.prototype继承。 Object.prototype.hasOwnProperty.call === Function.prototype.call // true 当你在一个函数上调用call时,该函数就成为this call值,所以call可以调用该函数。 这是你的第一个代码,它的工作原理。 但是,在你的第二个代码中,你不会把call作为一个对象的方法。 因此,它的this值在严格模式下是undefined ,或者是在非严格模式下的全局 ... -
该行评估函数并将undefined的返回值设置为Dog.prototype.bark : Dog.prototype.bark = barkWithMe(); 将其更改为: Dog.prototype.bark = barkWithMe; This line evaluates the function and sets the return value undefined to Dog.prototype.bark: Dog.prototype.bark = barkWithMe(); Change ...
-
因为它的原型继承。 以下方法可行: myClass.prototype.age = 22; var myobj = new myClass(); window.alert(myobj.age); 在您的示例中,您将向类原型添加属性。 只有在实例化该类的对象时才能看到这些。 要实现您想要的,只需依赖expando属性: myClass.age = 22; window.alert(myClass.age); 如果它有用,可以将第一个示例视为在C#中声明类的公共属性。 您只能在实例化时访问它。 第二个例 ...
-
var a = []做了一件事:它将a设置为new Array的实例但没有任何成员,因此继承了prototype[0] 。 var b = [1]做了两件事:它将b设置为new Array的实例(与a ),但是然后直接设置subscript [0] = 1 (绕过JavaScript的原型系统),这意味着[0] = 1 覆盖 “ defineProperty ”属性,从而完全避免了prototype[0] defineProperty 。 这与对象的工作方式相同: Object.defineProperty ...
-
将原型添加到对象(add prototype to object)[2022-03-04]
由于Base是一个构造函数,如果你想要一个使用Base.prototype作为其基础的单个对象,正如Brian Peacock在下面指出的那样你可以使用构造函数: var concrete2 = new Base(); concrete2.notify(); // Works 如果要向concrete2实例添加更多功能,可以直接执行此操作: concrete2.doSomethingElse = function() { /* ... */ }; 这是因为你已经有了构造函数,所以创建由该构造函数原型支持 ...