2

Here is my problem: I have 2 SWF files for a crossword puzzle: first one is for creating puzzles and outputting XML files upon clicking the "Save" button and second SWF is displaying those puzzles to the users by listing and loading those XML files and upon clicking it loads the selected XML file into SWF. This is okay so far here. But I need to use web interface so that a user inside a website sees those XML list on the web page and upon clicking/selecting, the second SWF will load with the related XML file. I need this because I will organize those XML files with some modules inside drupal such as Organic Groups. So each user will see different lists of XML files. For example, I have 2 groups created with my organic groups module inside drupal, each group has a different editor. So those editors will create puzzles and will set them for their groups with Organic groups module.

After some research I think I figured a possible and reasonable way to achieve this with a help of a friend. So, to wrap up things so far;

-I have a puzzle maker swf and a puzzle player swf. -Puzzle maker actually generates some xml files that could be played by Puzzle player(swf). -These xml files are to be stored in Drupal. -The stored xml files behaviour is same as Organic groups behaviour. Where the files belonging to a particular group is accessible to the group members.

So the idea of implementation is here,

1.) A custom page for creating puzzle using Puzzle maker(swf). A "Puzzle Data" content-type to hold the xml files. This node is under organic groups.

2.) The editors creates puzzle (things okay so far here) and the xml file will be downloaded to editor's computer.

3.) Now the editor may upload the xml file and attach it to "Puzzle Data" node.

4.) Now I may create a view to display all the "Puzzle Data" nodes in a Organic Group with Views module.

5.) Now comes the tricky part. The actual node display should be a Puzzle Player(swf) that uses the "xml" file uploaded to the node.

After some research I may achieve this either Creating a custom node template or creating a custom field formatter. So here I need a bit help with the php codes part so that each node will post/sent the attached xml file to puzzle player(swf) attached to the node.

(Btw this 2 step: downloading xml and later uploading it to a node is something unwanted, maybe puzzle maker(swf) can be embedded inside node/add path for Puzzle Data content type and editors may download xml so will upload it again into the field on the same page. )

0

You would create a new node.tpl.php by copying the existing one from your theme or from the node module (part of core). Rename your copy node--mycontenttype.tpl.php and place it in your theme directory (along side your other .tpl files).

Install devel and use dpm() to explore the $content variable. Hide the XML field and extract it's file id (fid) and pass it to file_load. This should return an object containing your file path, again use dpm() to explore this array and get your file.

https://api.drupal.org/api/drupal/includes%21file.inc/function/file_load/7

Embed your .swf directly into your new node.tpl.php and pass the XML to it as you would any other Flash argument.

0

This is how I fixed the issue. Created a custom node--puzzle.tpl.php for my puzzleplay.swf file. This custom node template takes the URL of the xml file that attached to "field_xml" field inside "puzzle" node-type. Then, this url is send to AS3 with Flashvars so that eachtime there is a node with a xml file attached to field_xml, puzzleplay.swf loads that specific xml from the url sent with Flashvars.

node--puzzle.tpl.php:

 <?php
    $xmlpath = file_create_url($node->field_xml['und']['0']['uri']);
    ?>
    <object 
    <param name="AllowScriptAccess" value="always">
    <param name="allowFullScreen" value="true" />
    <param name="quality" value="high" />
    <param name="flashVars" value="xmlPath= <?php echo $xmlpath; ?>" />
    <param name="movie" value="/path/to/puzzleplay.swf" />
    <embed allowScriptAccess="always" flashvars="xmlPath=<?php echo $xmlpath; ?>"src="/path/to/puzzleplay.swf" type="application/x-shockwave-flash" ></embed>
</object>

AS3 Code:

var XML_URL:String = root.loaderInfo.parameters.xmlPath;
var myXMLURL:URLRequest = new URLRequest(XML_URL); 
var myLoader:URLLoader = new URLLoader(myXMLURL); 
myLoader.addEventListener("complete", xmlLoaded); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.