Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1402 connectés 

  FORUM HardWare.fr
  Programmation
  Flash/ActionScript

  [Flash/Actionscript] Ouverture d'un swf à l'intérieur d'un swf

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Flash/Actionscript] Ouverture d'un swf à l'intérieur d'un swf

n°1575795
Shor-T
Posté le 16-06-2007 à 11:37:13  profilanswer
 

Bonjour chers programmeurs d'HFR !! :hello:

 

Je viens vous solliciter pour m'aider concernant flash. Je dois implémenter un menu qui charge des fichiers swf dans ma fenêtre flash, avec chargement dynamique, le problème est que je n'arrive pas à le faire, le reste fonctionne sauf ça, je pensais que vous pourriez m'aider :jap:

 

Voici le code ActionScript qui charge mes mon menu :

 
Code :
  1. /**
  2. This class allows you to create a dynamic menu based on an XML file.
  3. Example usage:
  4. In your FLA file, add the following code into the main timeline. Make sure that the XML file points to the appropriate file containing your navigation.
  5. new XmlMenu("menu.xml", this);
  6. */
  7. class XmlMenu {
  8. /* typically the variable, m_parent_mc, will point to the main timeline.
  9.    This MovieClip will end up being a container for the entire menu,
  10.    and where you'll attach your various navigation menu MovieClip instances. */
  11. private var m_parent_mc:MovieClip;
  12. /* the m_menu_array Array holds the references to the main menu movie clips.
  13.    This allows you to loop through each main navigation link and hide the dropdown sub-navigation if it is open. */
  14. private var m_menu_array:Array;
  15. /* Constructor, this method takes two parameters, xmlpath_str
  16.    (which is the path to the XML file containing the navigation),
  17.    and parent_mc (which is a reference to a movie clip/timeline
  18.    where you'll attach your various menu items). */
  19. function XmlMenu(xmlpath_str:String, parent_mc:MovieClip) {
  20.  this.m_parent_mc = parent_mc;
  21.  this.m_menu_array = new Array();
  22.  // call this class' initXML function which parses your XML navigation file.
  23.  initXML(xmlpath_str);
  24. }
  25. /* This function, initXML, takes a single parameter (xmlpath_str) and is responsible for
  26.    loading and parsing the XML document and converting it into an array of objects. */
  27. private function initXML(xmlpath_str:String):Void {
  28.  /* Set a reference to the current class.
  29.     You need to store this reference because Flash can get confused when you refer
  30.     to "this" within our XML onLoad method
  31.     (where "this" refers to the XML object rather than the XmlMenu class itself). */
  32.  var thisObj = this;
  33.  // create an array which contains the main navigation as well as each menu's sub-navigation links.
  34.  var menu_array:Array = new Array();
  35.  // The XML object which you will use to load and parse the XML navigation file.
  36.  var menu_xml:XML = new XML();
  37.  menu_xml.ignoreWhite = true;
  38.  // define your function which will be triggered when the XML file has completed loading.
  39.  menu_xml.onLoad = function(success:Boolean) {
  40.   /* if the XML file was successfully loaded and parsed,
  41.      convert it into an array of objects which we can pass to the XmlMenu class' initMenu method. */
  42.   if (success) {
  43.    // for each child node in the XML file (the child nodes here are the main menu navigation items.
  44.    for (var i = 0; i<this.firstChild.childNodes.length; i++) {
  45.     /* create a shortcut to the current node.
  46.        This allows us to simplify the code below so you
  47.        don't have as many firstChild and childNodes within the code. */
  48.     var shortcut = this.firstChild.childNodes[i];
  49.     // create an empty array for sub-navigation items.
  50.     var submenu_array:Array = new Array();
  51.     // for each child node of the main menu items, append the values to our submenu_array.
  52.     for (var j = 0; j<shortcut.childNodes.length; j++) {
  53.      /* append each sub-navigation item to our submenu_array Array.
  54.         Our XML file specifies the navigation's label and url in attributes rather than child nodes,
  55.         so if you modify the layout of the navigation XML file this code will need to be modified. */
  56.      submenu_array.push({caption:shortcut.childNodes[j].attributes.name, href:shortcut.childNodes[j].attributes.href});
  57.     }
  58.     // append each menu items, and it's array of submenu items.
  59.     menu_array.push({caption:shortcut.attributes['name'], href:shortcut.attributes['href'], subnav_array:submenu_array});
  60.    }
  61.    // call the XmlMenu class' initMenu method.
  62.    thisObj.initMenu(menu_array);
  63.   }
  64.  };
  65.  // load the navigation XML file.
  66.  menu_xml.load(xmlpath_str);
  67. }
  68. /* this method, initMenu, loops through the menu items and their respective
  69.    sub navigation items and builds the movie clips. */
  70. private function initMenu(nav_array:Array):Void {
  71.  // create a reference to the current class.
  72.  var thisObj = this;
  73.  // create variables which we will use to position the menu items.
  74.  var thisX:Number = 10;
  75.  var thisY:Number = 150;
  76.  var menuColor = new Array();
  77.  menuColor = new Array(["100","0", "0", "0", "50", "90", "50", "50"],["100","0", "0", "100", "0", "0", "50", "50"],["100","0", "100", "100", "0", "0", "50", "50"]);
  78.  for (var menuIndex = 0; menuIndex<nav_array.length; menuIndex++) {
  79.   // for each main menu item attach the menu_mc symbol from the library and position it along the x-axis.
  80.   var menuMC:MovieClip = this.m_parent_mc.attachMovie("menu_mc", "menu"+menuIndex+"_mc", menuIndex, {_x:thisX, _y:thisY});
  81.   /* store the current menu item's information within the MovieClip so you
  82.      always have a reference to the sub navigation and the current menu item's link */
  83.   //var maCouleur = new Color();
  84.   ///////////////////////////////////////////////////////////
  85.   // créer un objet Color appelé maCouleur pour la cible monAnimation
  86.   //maCouleur = new Color(menuMC);
  87.   //var maTransformationDeCouleur = new Object();
  88.   // définir les valeurs de maTransformationDeCouleur
  89.   //maTransformationDeCouleur = { ra: menuColor[menuIndex][0], rb: menuColor[menuIndex][1], ga: menuColor[menuIndex][2], gb: menuColor[menuIndex][3], ba: menuColor[menuIndex][4], bb: menuColor[menuIndex][5], aa: menuColor[menuIndex][6], ab: menuColor[menuIndex][7]  };
  90.   // associer l’objet de transformation de couleur à l’objet Color
  91.   // créé pour monAnimation
  92.   //maCouleur.setTransform(maTransformationDeCouleur);
  93.   ///////////////////////////////////////////////////////////////
  94.   menuMC.data = nav_array[menuIndex];
  95.   // add a reference to the current menu movie clip in the class' m_menu_array Array.
  96.   this.m_menu_array.push(menuMC);
  97.   // set the caption on the main menu button.
  98.   menuMC.label_txt.text = menuMC.data.caption;
  99.   // create a new movie clip on the Stage which will be used to hold the submenu items.
  100.   var subMC:MovieClip = this.m_parent_mc.createEmptyMovieClip("submenu"+menuIndex+"_mc", (menuIndex*20)+100);
  101.   // set the sub menu's X and Y position on the Stage.
  102.   subMC._x = thisX;
  103.   subMC._y = menuMC._height;
  104.   // set a variable in the submenu movie clip which stores whether the current sub menu item is visible
  105.   subMC.subMenuVisible = true;
  106.   // call the hideSubMenu method which hides the sub menu item.
  107.   hideSubMenu(subMC);
  108.   // within the sub menu movie clip store a reference to the menu movie clip
  109.   subMC.parentMenu = menuMC;
  110.   // hide the sub menu movie clip on the Stage.
  111.   subMC._visible = false;
  112.   // set a variable which we will use to track the current y-position of the sub-navigation items.
  113.   var yPos:Number = thisY;
  114.   var temp_subnav_array:Array = menuMC.data.subnav_array;
  115.   /* for each sub menu item, attach a new instance of the link_mc MovieClip from the Library,
  116.      set the text for the link and increment the yPos counter. */
  117.   for (var i = 0; i<temp_subnav_array.length; i++) {
  118.    var linkMC:MovieClip = subMC.attachMovie("link_mc", "link"+i+"_mc", i, {_x:0, _y:yPos});
  119.    //var maCouleur = new Color();
  120.   /////////////////////////////////////////////////////////////////////
  121.   // créer un objet Color appelé maCouleur pour la cible monAnimation
  122.   //maCouleur = new Color(linkMC);
  123.   //var maTransformationDeCouleur = new Object();
  124.   // définir les valeurs de maTransformationDeCouleur
  125.   //maTransformationDeCouleur = { ra: menuColor[menuIndex][0], rb: menuColor[menuIndex][1], ga: menuColor[menuIndex][2], gb: menuColor[menuIndex][3], ba: menuColor[menuIndex][4], bb: menuColor[menuIndex][5], aa: menuColor[menuIndex][6], ab: menuColor[menuIndex][7]  };
  126.   // associer l’objet de transformation de couleur à l’objet Color
  127.   // créé pour monAnimation
  128.   //maCouleur.setTransform(maTransformationDeCouleur);
  129.   /////////////////////////////////////////////////////////////
  130.    linkMC.data = temp_subnav_array[i];
  131.    linkMC.label_txt.text = linkMC.data.caption;
  132.    linkMC.onRelease = function() {
  133.     loadMovie("Addition.swf",999);
  134.     // trace(this.data.href);
  135.    };
  136.    yPos += linkMC._height;
  137.   }
  138.   // draw a slight 1 pixel drop shadow around the sub menu using the drawing API
  139.   var thisWidth:Number = subMC._width+1;
  140.   var thisHeight:Number = subMC._height+1;
  141.   subMC.beginFill(0x000000, 0);
  142.   subMC.moveTo(0, 0);
  143.   subMC.lineTo(thisWidth, 0);
  144.   subMC.lineTo(thisWidth, thisHeight);
  145.   subMC.lineTo(0, thisHeight);
  146.   subMC.lineTo(0, 0);
  147.   subMC.endFill();
  148.   //
  149.   menuMC.childMenu = subMC;
  150.   thisY += menuMC._height*i;
  151.  }
  152.  // define the onRollOver and onRelease for each main menu item.
  153.  for (var i in this.m_menu_array) {
  154.   this.m_menu_array[i].onRollOver = function() {
  155.    thisObj.showSubMenu(this.childMenu);
  156.   };
  157.   /*this.m_menu_array[i].onRelease = function() {
  158.    
  159.    //getURL(this.data.href, "_blank" );
  160.    // trace(this.data.href);
  161.   };*/
  162.  }
  163. }
  164. // the showSubMenu method displays the specified sub menu movie clip
  165. private function showSubMenu(target_mc:MovieClip):Void {
  166.  // create a reference to the current class.
  167.  var thisObj = this;
  168.  if (!target_mc.subMenuVisible) {
  169.   hideAllSubMenus();
  170.   target_mc._visible = true;
  171.   target_mc.subMenuVisible = true;
  172.   /* define a handler for the onMouseMove event.
  173.      This function is called whenever the mouse is moved,
  174.      whether or not it is over the specified movie clip. */
  175.    
  176.   /* :KLUDGE: You are using the onMouseMove handler here instead of onRollOut,
  177.      because using onRollOut caused the nested movie clips to stop responding
  178.      to their respective onRelease event handlers. */
  179.   target_mc.onMouseMove = function() {
  180.    // hit test both the main menu item, and the submenu to see if the mouse is over either one of them.
  181.    var subHit:Boolean = this.hitTest(_xmouse, _ymouse, true);
  182.    var menuHit:Boolean = this.parentMenu.hitTest(_xmouse, _ymouse, true);
  183.    /* if the mouse is not over the main menu or sub menu,
  184.       hide the submenu movie clip and delete the onMouseMove event listener since we don't need it any more. */
  185.    if (!((subHit || menuHit) && this.subMenuVisible)) {
  186.     thisObj.hideSubMenu(this);
  187.     delete this.onMouseMove;
  188.    }
  189.   };
  190.  }
  191. }
  192. // hide the specified sub menu Movie Clip, if it is visible.
  193. private function hideSubMenu(target_mc:MovieClip):Void {
  194.  if (target_mc.subMenuVisible) {
  195.   target_mc._visible = false;
  196.   target_mc.subMenuVisible = false;
  197.  }
  198. }
  199. // hide the sub menu for each menu item in the m_menu_array Array.
  200. private function hideAllSubMenus():Void {
  201.  for (var i in this.m_menu_array) {
  202.   hideSubMenu(this.m_menu_array[i].childMenu);
  203.  }
  204. }
  205. // toggle a specific menu's visibility.
  206. private function toggleSubMenu(target_mc:MovieClip):Void {
  207.  (target_mc.subMenuVisible) ? hideSubMenu(target_mc) : showSubMenu(target_mc);
  208. }
  209. }
 

Voici le menu xml ou le fichier .as prend ses infos :

 


Code :
  1. <?xml version="1.0" encoding="iso-8859-1" ?>
  2. <navigation>
  3. <menu name="Apprends !">
  4. <submenu name="Addition" href="Addition.swf" />
  5. <submenu name="Multiplication" href="Multiplication.swf" />
  6. </menu>
  7. <menu name="Exerce toi !">
  8. <submenu name="Flash" href="Exercice1.swf" />
  9. <submenu name="ActionScript" href="Exercice2.swf" />
  10. </menu>
  11. <menu name="Joue !">
  12. <submenu name="Books" href="Jeu1.swf" />
  13. <submenu name="Software" href="Jeu2.swf" />
  14. </menu>
  15. </navigation>
 


Voici en fait l'endroit ou il faut charger le fichier swf, mais que je n'arrive pas à créer dynamiquement (qui se situe de la ligne 143 à 149) :

 
Code :
  1. linkMC.onRelease = function() {
  2.     loadMovie("Addition.swf",999);
  3.    };
 


En comptant sur votre aide, merci :jap:


Message édité par Shor-T le 16-06-2007 à 11:38:58

---------------
-= En kikoolol nous croyons =-
mood
Publicité
Posté le 16-06-2007 à 11:37:13  profilanswer
 

n°1575799
craps_youp​la
Posté le 16-06-2007 à 11:39:13  profilanswer
 

lol


---------------
"Il y a vraiment aucun patelin qui s'appelle 'undefined' en France ?"
n°1575801
Shor-T
Posté le 16-06-2007 à 11:43:20  profilanswer
 
n°1576464
Zedlefou
In cabbage we trust !
Posté le 18-06-2007 à 18:51:13  profilanswer
 

J'ai tout lu, et puis je me suis endormi, et puis j me souviens de rien ... dsl.
Fait plus cour la prochaine fois.
Et fait le code toi même ;)


---------------
Jeu de simulation Boursière - Version BETA - https://www.facebook.com/wildstocks

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Flash/ActionScript

  [Flash/Actionscript] Ouverture d'un swf à l'intérieur d'un swf

 

Sujets relatifs
Du flash dans mon header[FLV] connaitre la compatibilité avec les versions du flash player
Menu flash...Help pour la fonction GeturlRecherche un pro du flash pour une petite modif
Imprimer une scene avec Flash[FLASH] Eviter la fenêtre de paramètres du flash player ?
empêcher le redémarrage d' une anim flash lorsque page précédente.flash besoin d'aide uregent!!
Flash mx et bibliothèque [FLASH] why ? (message d'erreur)
Plus de sujets relatifs à : [Flash/Actionscript] Ouverture d'un swf à l'intérieur d'un swf


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR