Flash 无法将变量从闪存(父级)发送到加载的flex swf(子级)?
我正在尝试将变量从父级(flash)加载到子级(flash)。工作正常 父swf:(闪存) 子swf(柔性) 但在与flash通信以调整其灵活性时,未加载 错误消息Flash 无法将变量从闪存(父级)发送到加载的flex swf(子级)?,flash,apache-flex,communication,Flash,Apache Flex,Communication,我正在尝试将变量从父级(flash)加载到子级(flash)。工作正常 父swf:(闪存) 子swf(柔性) 但在与flash通信以调整其灵活性时,未加载 错误消息 TypeError: Error #1009: Cannot access a property or method of a null object reference. at Untitled_fla::MainTimeline/frame1() TypeError: Error #1009: Cannot acce
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()
ReferenceError:错误#1069:在上找不到属性passVariable
_child_mx_managers_SystemManager,没有默认值。at函数/()
请帮帮我
更新
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()
flash中的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);
}
flex中的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>
在Flex应用程序中,最顶级的精灵是
SystemManager
。并且应用程序
对象作为系统管理器
的子对象添加。所以,你需要得到它
swf = MovieClip(e.target.content);
swf.addEventListener("applicationComplete", onApplicationReady);
private function onApplicationReady(evt:Event)
{
var app:DisplayObject = swf.getChildAt(0);
app["passVariable"](...);
}
请注意,Application
添加到“applicationComplete
”事件中
了解更多信息。在Flex应用程序中,最顶级的sprite是
SystemManager
。并且应用程序
对象作为系统管理器
的子对象添加。所以,你需要得到它
swf = MovieClip(e.target.content);
swf.addEventListener("applicationComplete", onApplicationReady);
private function onApplicationReady(evt:Event)
{
var app:DisplayObject = swf.getChildAt(0);
app["passVariable"](...);
}
请注意,Application
添加到“applicationComplete
”事件中
了解更多信息。您可能正在做以下两件事之一:
无论您遇到了什么问题,这表明将加载的swf强制转换到接口并在其上调用方法都会有所帮助。您可能正在做以下两件事之一:
// In your Flex app
/* called when your SWFLoader finishes loading the SWF */
private function onMySWFLoaded( p_event:Event ) :void
{
mySWFLoader.content.addEventListener( “clicked”, onSWFClick );
}
/* callback for the clicked event */
private function onSWFClick( event:Event ) :void
{
mx.controls.Alert.show( ‘Click event raised!’ );
}
//在Flash电影中
/* called when the button in your flash movie is clicked */
private function onButtonClick( p_event:Event ) :void
{
dispatchEvent( new Event( “clicked” );
}
如何在特定帧从flash调用flex函数
Embed(source=“../assets/swf/myFlashComponent.swf”, symbol=“Preloader”)]
private var FlashPreloaderSymbol:Class;
private var clip:MovieClip;
clip = new FlashPreloaderSymbol();
addChild(clip);
private function onFlexInitComplete( event:FlexEvent ):void
{
clip.addFrameScript(47, callMyFunction);
}
这个怎么样
使用SWFLoader实例加载AS3 swf文件
按如下方式调用函数:
mySWFLoader.content.functionName()
如何从flex监听flash事件
// In your Flex app
/* called when your SWFLoader finishes loading the SWF */
private function onMySWFLoaded( p_event:Event ) :void
{
mySWFLoader.content.addEventListener( “clicked”, onSWFClick );
}
/* callback for the clicked event */
private function onSWFClick( event:Event ) :void
{
mx.controls.Alert.show( ‘Click event raised!’ );
}
//在Flash电影中
/* called when the button in your flash movie is clicked */
private function onButtonClick( p_event:Event ) :void
{
dispatchEvent( new Event( “clicked” );
}
如何在特定帧从flash调用flex函数
Embed(source=“../assets/swf/myFlashComponent.swf”, symbol=“Preloader”)]
private var FlashPreloaderSymbol:Class;
private var clip:MovieClip;
clip = new FlashPreloaderSymbol();
addChild(clip);
private function onFlexInitComplete( event:FlexEvent ):void
{
clip.addFrameScript(47, callMyFunction);
}
我所能看到的是flex函数不是公共的 这会阻止其他类看到它 将定义更改为
public function passVariable(_msg:String):void
编辑
延伸我的评论
更好的方法是循环swf的所有子级,如果其中存在passVariable
函数,则调用它
function swfLoaded(e:Event):void {
for each(var app:DisplayObject in swf.getChildren()) {
if(app.passVariable != null) {
app["passVariable"](parentMessage);
}
}
}
我所能看到的是flex函数不是公共的 这会阻止其他类看到它 将定义更改为
public function passVariable(_msg:String):void
编辑
延伸我的评论
更好的方法是循环swf的所有子级,如果其中存在passVariable
函数,则调用它
function swfLoaded(e:Event):void {
for each(var app:DisplayObject in swf.getChildren()) {
if(app.passVariable != null) {
app["passVariable"](parentMessage);
}
}
}
感谢您收到这样的错误,1061:通过静态类型flash的引用调用可能未定义的方法passVariable。display:DisplayObject。@user1268367我已更新了答案。您可以使用动态属性。我再次收到错误,ReferenceError:error#1069:property passVariable未在_ViewPPT_mx_managers_SystemManager上找到,并且没有默认值。在函数/()中,感谢您收到如下错误:1061:通过静态类型flash的引用调用可能未定义的方法passVariable。display:DisplayObject。@user1268367我已更新了答案。您可以使用动态属性。我再次收到错误,ReferenceError:error#1069:property passVariable未在_ViewPPT_mx_managers_SystemManager上找到,并且没有默认值。在函数/()中,我需要将变量从flash(父)传递到flex(子)(即我在flash中加载swf)我需要将变量从flash(父)传递到flex(子)(即我在flash中加载swf)我也在尝试公共函数,TypeError:Error#1009:无法访问null对象引用的属性或方法。在Untitled_fla::MainTimeline/frame1()中,类型错误:错误#1009:无法访问空对象引用的属性或方法。在mx.managers::FocusManager/activate()mx.managers::SystemManager/at flash.events::EventDispatcher/dispatchEventFunction()在mx.preload::preload/timerHandler()从父级传递给子级的消息:null为什么不调试代码?Is
swf.getChildAt(1)代码>返回预期的Flex对象?更好的方法是(参见我编辑的答案)我也在尝试公共函数,TypeError:Error#1009:无法访问null对象引用的属性或方法。在Untitled_fla::MainTimeline/frame1()中,类型错误:错误#1009:无法访问空对象引用的属性或方法。在mx.managers::FocusManager/activate()mx.managers::SystemManager/at flash.events::EventDispatcher/dispatchEventFunction()在mx.preload::preload/timerHandler()从父级传递给子级的消息:null为什么不调试代码?Isswf.getChildAt(1)代码>返回预期的Flex对象?一个更好的方法是(参见我编辑的答案)蓝色文本(“本例”)是所谓的“超链接”,您可能不知道它实际上是cl