海正试图从父(闪存)加载变量到子(闪存)。它工作正常。无法从闪存(父级)发送变量到加载的Flex SWF(子)?
父SWF:(闪存)
var parentMessage:String = "Hello";
var swf:MovieClip;
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded);
l.load(new URLRequest("child.swf"));
function swfLoaded(e:Event):void
{
swf = MovieClip(e.target.content);
swf.passVariable(parentMessage);
}
孩子SWF(柔性)
public var childMessage:String;
function passVariable(_msg:String):void
{
childMessage = _msg;
trace("message passed from parent to child: " + childMessage);
}
不过,虽然有闪光灯沟通,展示其未加载。
错误消息
ReferenceError: Error #1069: Property passVariable not found on _child_mx_managers_SystemManager and there is no default value. at Function/()
请帮助我。
更新
闪光灯parent.swf
var parentMessage:String = "Hello";
var swf:MovieClip;
var l:Loader = new Loader();
l.load(new URLRequest("asd.swf"));
swf.addEventListener("applicationComplete", swfLoaded);
function swfLoaded(e:Event):void
{
var app:DisplayObject = swf.getChildAt(1);
app["passVariable"](parentMessage);
}
Child.swf在柔性
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" addedToStage="application1_addedHandler(event)" >
<fx:Script>
<![CDATA[
public var childMessage:String;
protected function application1_addedHandler(event:Event):void
{
passVariable(childMessage);
}
public function passVariable(_msg:String):void
{
childMessage = _msg;
trace("First message passed from parent to child: " + childMessage);
}
]]>
</fx:Script>
的ErrorMessage
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline/frame1()
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.managers::FocusManager/activate()
at spark.components::Application/initManagers()
at spark.components::Application/initialize()
at asd/initialize()
at mx.managers.systemClasses::ChildManager/childAdded()
at mx.managers.systemClasses::ChildManager/initializeTopLevelWindow()
at mx.managers::SystemManager/initializeTopLevelWindow()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::kickOff()
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::preloader_completeHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
谢谢我得到这样的错误,1061:调用一个可能未定义的方法passVariable通过引用与静态类型flash.display:DisplayObject。 – Ela 2012-03-27 12:32:17
@ user1268367我已经更新了答案。您可以使用动态属性。 – 2012-03-27 13:18:06
再次出现错误,ReferenceError:错误#1069:在_ViewPPT_mx_managers_SystemManager上找不到属性passVariable,并且没有默认值。 \t在功能/() –
Ela
2012-03-27 13:29:57