Dear All,

I have one php based application now i want to make interactive application of the same . i started work on flex for php . but now the problem is menu . in current application i have javascript file for menu with few php code i want add this menu to new flex based pages but i am not getting how to do this. i have also tried adding js file to index-html page but not fixed yet.

Can anyone tell me how do i do this ?

Regards,
Merry Christmas To All :)

Dani AI

Generated

As noted, you cannot "embed" raw JavaScript inside a Flex/SWF, but ActionScript and page JavaScript can talk to each other using the ExternalInterface API. For the two practical options are: keep your PHP/JS menu in the HTML wrapper and let the SWF call JS to update/highlight the menu, or expose ActionScript methods that the page JS calls to push PHP-generated menu data into your Flex UI. (help.adobe.com)

Example pattern (minimal):

/* MXML / ActionScript (creationComplete -> init) */
import flash.external.ExternalInterface;
private function init():void {
  if (ExternalInterface.available) {
    ExternalInterface.addCallback("flashUpdateMenu", flashUpdateMenu);
    try { ExternalInterface.call("jsRegisterFlash", ExternalInterface.objectID); }
    catch (e:Error) { trace("EI call failed: "+e.message); }
  }
}
private function flashUpdateMenu(json:String):void {
  // parse JSON and update Flex menu
}
/* JS wrapper */
function jsRegisterFlash(id){
  window.myFlash = document.getElementById(id) || window[id];
}
function sendMenuToFlash(menuObj){
  var json = JSON.stringify(menuObj);
  if (window.myFlash && typeof window.myFlash.flashUpdateMenu === "function")
    window.myFlash.flashUpdateMenu(json);
  else console.warn("Flash not ready; retry later");
}
// PHP can echo JSON into a JS var and call sendMenuToFlash(menu);

This uses ExternalInterface.call(...) for Flash->JS and ExternalInterface.addCallback(...) for JS->Flash. Always check ExternalInterface.available before calling. (help.adobe.com)

Embedding and timing gotchas: ensure the SWF tag has a clean id/name (avoid problematic characters), set the wrapper parameter allowScriptAccess (sameDomain or always) if cross-window calls are needed, and embed with SWFObject or use its callback + PercentLoaded polling so calls happen after the movie is ready. Local file (file://) security and sandbox rules can block ExternalInterface unless content is trusted. (help.adobe.com)

Important context for later readers: browser and platform support for Flash has ended (Adobe ended Flash Player support on Dec 31, 2020), so SWF-based UIs will not run reliably in modern browsers. For any long-term project prefer migrating the UI/menu to HTML5/JS or consider Apache Royale (FlexJS) if keeping MXML/AS semantics is required. (adobe.com)

Recommended Answers

All 3 Replies

Are you talking about Adobe Flex? If so, how are you creating your app? Just one project that will be entire app or will you have a couple of PHP pages and each one with a different Flex app?

yes i am talking about adobe flex and right now only few php pages to each different flex page.

Ok, so let me tell you, you can't add JS inside Flex, but ActionScript can communicate with JavaScript.
So, you can either make the JS call functions inside the Flex App to set/change the menu or you can make the Flex App call functions in JavaScript, if you are using an HTML menu.

To make this communication you need to use the Flex ExternalInterface class and also set the correct parameters in the embeded flash object in your html markup.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.