Panel not reading XML file in PS, works in browser

General Discussion of Scripting for Flex, Flash & CS SDK

Moderators: Tom, Kukurykus

bdeshazer

Panel not reading XML file in PS, works in browser

Post by bdeshazer »

I'm new to Flash Builder/Flex (as in, I started working with both yesterday). I'm using Flash Builder 4 downloaded yesterday from Adobe.

I wanted to build a custom PS panel so I worked my way through a couple of the Panel Developer's Guide examples and then proceeded to try and build my own. When working through the examples I could not get them to work if I created the project using Flex 4.1 but specifying Flex 3.5 worked so that is what I've been using.

For my panel I'm reading a local xml file that I created and that is in the same folder as my swf (bin-debug) and binding one of the fields to a combobox control and another to a listbox control. I used the "Data Services" option in Flash Builder to create the connection to the XML file, and it created a "services.myname" package with a _Super_ class and a sub-class, but I haven't done anything with those. The data shows up just fine when the swf runs in a browser using the "Run" menu option from Flash Builder.

When I copy the SWF and the XML file to Plug-ins/Panels/MYPANELFOLDER and then start Photoshop the panel appears with the controls but there is no data in the combobox or the listbox controls.

I'm using PS CS5 and the platform is Mac OSX 10.6. I'm using the CSXSLibrary-2.0-sdk-3.4.swc but that is hopefully a non-issue as I'm not making any CSXS calls yet.

I hope that this is some super-simple fundamental whose concept I'm not grasping yet, and would appreciate any pointers on making this work.

Thank you,

Brent
bdeshazer

Panel not reading XML file in PS, works in browser

Post by bdeshazer »

Still banging my head on this but narrowed the problem down to a problem reading the xml file from the local file system. If I post the XML file up on a web site and reference it by URL then everything works just fine inside PS.

I found a reference in the FAQ section of the Panel Developer's Guide to Adobe Flash Player trust permissions, but creating the .cfg file like they suggested didn't solve the problem.

...
Mike Hale

Panel not reading XML file in PS, works in browser

Post by Mike Hale »

I can't help with reading the xml file from the panel side but a workaround would be to read it from the javascript side and pass it to the panel from there.
bdeshazer

Panel not reading XML file in PS, works in browser

Post by bdeshazer »

Mike Hale wrote:I can't help with reading the xml file from the panel side but a workaround would be to read it from the javascript side and pass it to the panel from there.

Thanks Mike, I've posted on the Adobe forums, we'll see if someone has a way to make this work via the HTTPService request...

Still feeling my way around with Flex/mxml/AS, I'm not sure how difficult it would be to substitute an XML file read with the HTTPService with one read using your suggestion and still be able to do all the data binding / "XML stuff" that I currently have working (except from within PS )

If you had any sample code that you think would work for this I'd appreciate seeing it!

Brent
bdeshazer

Panel not reading XML file in PS, works in browser

Post by bdeshazer »

Tried adding the "-use-network=false" compiler directive to the properties of my project, didn't help either... Mike's suggestion is looking more and more likely the route I'm going to have to try.
undavide

Panel not reading XML file in PS, works in browser

Post by undavide »

Hello Brent,
using an XML to populate a ComboBox is something that should be far more easy that it actually is, IMHO. I've had to spend many days scratching my head and ask for help everywhere in order to make it work.
Let me see if I can help you (I did this in a project that I had to drop unfinished a couple of months ago, so I hope I'm able to reconstruct what I wrote )
My needs were as follow: I had a quite complicated UI and I wanted to call presets (which would set all the sliders, checkboxes, etc) via combobox. The combobox would read an XML containing all the data.

the main mxml:

Code: Select all...

public var prefsFile:File;          // The preferences prefsFile         
[Bindable]
public var prefsXML:XML;          // The XML data
public var stream:FileStream;       // The FileStream object used to read and write prefsFile data.
public var PresetList:XMLList;       // presets in XML format - put in a XMLList;
[Bindable] 
public var PresetLabelList:XMLList;   // an XMLList populated with PresetList labels only - which will act as a ComboBox dataProvider
public var stream:FileStream;       // The FileStream object used to read and write prefsFile data.

...

public function appComplete():void

   prefsFile = File.desktopDirectory;               // or maybe: applicationStorageDirectory or what you like
   // trace("WARNING:" + prefsFile.nativePath)            // see "Building an extension" in the "Programmer's Guide" for
                                    // all kind ofUSER's FOLDERS to be used via SyncRequestResult and CSXSInterface

   prefsFile = prefsFile.resolvePath("myPrefFile.xml");       
   readXML();   
   PresetList = new XMLList(prefsXML);                  // Create and populate PresetList as XMLList
   PresetLabelList = new XMLList(PresetList.preset.child("label"));    // Create PresetLabelList with labels only - coming from the XML
}

private function readXML():void
{
   stream = new FileStream();
   if (prefsFile.exists) {
   stream.open(prefsFile, FileMode.READ);
   processXMLData();
   }
   else // there are functions that create the XML if it doesn't exist
   {
      createDefaultXMLData();
      writeXMLData();
   }
   stage.nativeWindow.visible = true; // couldn't remember why this line is here...
}

private function processXMLData():void
{
   prefsXML = XML(stream.readUTFBytes(stream.bytesAvailable));
   stream.close();         
}
...

<mx:ComboBox x="61" y="459"
   id="presetsCombo"
   width="140" selectedIndex="0" fontSize="9"
   editable="false"
   dataProvider="{PresetLabelList}" />

my XML structure looks like this:

Code: Select all<presets>
   <preset>
      <label>Default</label>
      <rounds>1</rounds>
      <parameters>
         <radius1>100</radius1>
         <radius2></radius2>
         <radius3></radius3>
         <opacity1>100</opacity1>
         <opacity2></opacity2>
         <opacity3></opacity3>
         <blendmode1>0</blendmode1>
         <blendmode2></blendmode2>
         <blendmode3></blendmode3>
      </parameters>
      <overlap>true</overlap>
      <candelete>false</candelete>
   </preset>
</presets>   

Give it a try and let me know if I've forgot to add something in the copy-paste process
Regards,

Davide
bdeshazer

Panel not reading XML file in PS, works in browser

Post by bdeshazer »

Davide, I just came back to post that I successfully implemented a solution in Javascript and saw your reply. Thanks for taking the time, sorry I didn't see it before now. I may take a look at the file stream solution for the next version of this panel.

Thanks,

Brent
undavide

Panel not reading XML file in PS, works in browser

Post by undavide »

Hi Brent,
no problem, it may help someone else in the future (PS-Scripts is a wonderful resource and I'm honored to contribute the few times I've solutions and not only questions
Cheers,

Davide
RipsMiel

Panel not reading XML file in PS, works in browser

Post by RipsMiel »

Hi there, I have found your code and surely it has helped much to me. My problem is I cannot find any codes that allow rendering of auto play flash videos. My friend likes to have his site flash videos and slideshow as well, I have made the slideshow but not the flash video can anyone help me?
undavide

Panel not reading XML file in PS, works in browser

Post by undavide »

RipsMiel wrote: I cannot find any codes that allow rendering of auto play flash videos.

Try looking there. near the page's end there's the link to the Photoshop Panel Developer's Guide.
You can find in there ("Other Examples" section) the Photoshop TV panel - which embeds and plays flash video. Me, I've never had to play video, luckily, but this sample may help you.
Cheers
Davide