PDA

View Full Version : flex3 calling functions in embedded swf problem


ben_ek
08-13-2008, 05:18 PM
i'm a newbie to flex so i'm hoping there is going to be a simple answer to this problem. it's caused a massive headache...

i have been using a swfLoader to load a swf, then triggering function calls within the swf from flex by using the following in the script tag of my mxml

var mc:MovieClip = MovieClip(myMP3player.content);
mc.loadMP3Player("file:///"+path, artist, title);

where loadMP3Player is the function in the linked swf and myMP3player is the id of the swfLoader.

this works great, no problems... but when i change the code so that the swf is embedded, rather than loaded at runtime the code above gives a

"ReferenceError:Error #1069 Property loadMP3Player not found" error

when i try to trigger the function.

i have tried many different ways of referencing and embedding the swf, all have the same result. i.e. swf loads fine and the flex project compiles without errors, but i am unable to call the function. see the code snippet for my details.

any help will be really appreciated.

btw: i need to embed the swf as i am distributing the finished article as an air app.

//this works

<mx:Panel backgroundColor="#FFFFFF" width="280" height="130" layout="vertical" id="mp3PreviewPanel" title="Track preview (drag track to play)" dragDrop="audioDragDrop(event);" dragEnter="audioDragEnter(event);" >

<mx:SWFLoader id="myMP3player" source="mp3player.swf" />

</mx:Panel>



var mc:MovieClip = MovieClip(myMP3player.content);
mc.loadMP3Player("file:///"+path, artist, title);


//--------------------------------

//this doesn't work (exactly the same as above except swf is embedded). swf appears in app ok.

<mx:Panel backgroundColor="#FFFFFF" width="280" height="130" layout="vertical" id="mp3PreviewPanel" title="Track preview (drag track to play)" dragDrop="audioDragDrop(event);" dragEnter="audioDragEnter(event);" >

<mx:SWFLoader id="myMP3player" source="[Embed(source='mp3player.swf')]" />

</mx:Panel>

var mc:MovieClip = MovieClip(myMP3player.content);
mc.loadMP3Player("file:///"+path, artist, title);

//ReferenceError:Error #1069 Property loadMP3Player not found


//-------

//this doesn't work either (swf appears in app ok)

[Embed(source=".mp3player.swf")]
[Bindable]
public var mp3PlayerClass:Class;

[Bindable]
public var myMP3playerClip:MovieClip= new mp3PlayerClass();



<mx:SWFLoader id="myMP3player" trustContent="true" source="{myMP3playerClip}" />



var mc:MovieClip = MovieClip(myMP3player.content);
//this call doesn't work
mc.loadMP3Player("file:///"+path, artist, title);
//this call doesn't work either
myMP3playerClip.loadMP3Player("file:///"+path, artist, title);
//this call doesn't work either
myMP3playerClip.content.loadMP3Player("file:///"+path, artist, title);

//ReferenceError:Error #1069 Property loadMP3Player not found

ahmednuaman
09-06-2008, 04:40 PM
Hi Ben, try creating the mc of the MP3 player after it has been loaded, ie attach a listener to the loading object.