<doc>
  <legacy_id>1286</legacy_id>
  <name>setResource</name>
  <type>function</type>
  <syntax>
    <example>setResource(<i>destinationFile</i>,<i>resourceType</i>,[<i>resID</i>],[<i>resName</i>],<i>flagsList</i>,<i>data</i>)</example>
  </syntax>
  <library></library>
  <objects>
  </objects>
  <synonyms>
  </synonyms>
  <classification>
    <category>Files, Folders, &amp; Resources</category>
  </classification>
  <references>
    <function tag="copyResource">copyResource Function</function>
    <function tag="deleteResource">deleteResource Function</function>
    <function tag="getResource">getResource Function</function>
    <function tag="getResources">getResources Function</function>
    <keyword tag="resfile">resfile Keyword</keyword>
  </references>
  <history>
    <introduced version="1.1">Added.</introduced>
  </history>
  <platforms>
    <mac/>
  </platforms>
  <classes>
    <desktop/>
    <web/>
  </classes>
  <security>
    <disk access="???"/>
  </security>
  <summary>Places data in a specified resource in a <glossary tag="Mac OS">Mac OS</glossary> <keyword tag="file">file</keyword>.</summary>
  <examples>
    <example>setResource("Include","BNDL",129,"document",RL,the bundleData of me)</example>
    <example>setResource(it,"ICON",128,,,getResource(it,"ICON",130))</example>
  </examples>
  <description>
    <p>Use the <b>setResource</b> <control_st tag="function">function</control_st> to create a <glossary tag="resource">resource</glossary> or change its data.</p><p/><p><b>Parameters:</b></p><p>The <i>destinationFile</i> is the location and name of the <keyword tag="file">file</keyword> that contains the <glossary tag="resource">resource</glossary> you want to set. If you specify a name but not a location, LiveCode assumes the <keyword tag="file">file</keyword> is in the <property tag="defaultFolder">defaultFolder</property>.</p><p/><p>The <i>resourceType</i> is the 4-character type of the <glossary tag="resource">resources</glossary> you want to change.</p><p/><p>The <i>resID</i> is an <keyword tag="integer">integer</keyword> or an <glossary tag="expression">expression</glossary> that <glossary tag="evaluate">evaluates</glossary> to an <keyword tag="integer">integer</keyword>.</p><p/><p>The <i>resName</i> is a <keyword tag="string">string</keyword> or an <glossary tag="expression">expression</glossary> that <glossary tag="evaluate">evaluates</glossary> to a <keyword tag="string">string</keyword>.</p><p/><p>The <i>flagsList</i> is a list that can contain one or more flag characters. The possible resource flags are as follows:</p><p><b>S        </b>System heap</p><p><b>U</b>        Purgeable</p><p><b>L</b>        Locked</p><p><b>P</b>        Protected</p><p><b>R</b>        Preload</p><p><b>C        </b>Compressed resource</p><p>The flags may be listed in any order. If a character is included, its corresponding resource flag is set to true. If the character is not included in the <i>flagsList</i>, its corresponding resource flag is set to false. If the <i>flagsList</i> is empty, all the flags are set to false.</p><p/><p>The <i>data</i> is text or <glossary tag="binary">binary</glossary> data, formatted appropriately for the resource type.</p><p/><p><b>Value:</b></p><p>The <b>setResource</b> <control_st tag="function">function</control_st> <glossary tag="return">returns</glossary> empty.</p><p/><p><b>Comments:</b></p><p>If the <i>destinationFile</i> does not exist, the <b>setResource</b> <control_st tag="function">function</control_st> creates the <keyword tag="file">file</keyword>. If the <i>destinationFile</i> exists but has no <glossary tag="resource fork">resource fork</glossary>, the <b>setResource</b> function creates the <glossary tag="resource fork">resource fork</glossary> and copies the <glossary tag="resource">resource</glossary> to it.</p><p/><p>If the <i>destinationFile</i> is open, the <function tag="result">result</function> is set to "<code>Can't open resource fork</code>".</p><p/><p>If the specified resource already exists, the <b>setResource</b> <control_st tag="function">function</control_st> replaces the data in the <glossary tag="resource">resource</glossary> with the <i>data</i>. Otherwise, the <b>setResource</b> <control_st tag="function">function</control_st> creates the <glossary tag="resource">resource</glossary>.</p><p/><p>You must specify either a <i>resID</i> or <i>resName</i> or both. If you specify one but not the other, the <b>setResource</b> <control_st tag="function">function</control_st> looks for an existing <glossary tag="resource">resource</glossary> with the specified name or ID, and replaces its contents without changing the existing ID or name.</p><p/><p>The <b>setResource</b> <control_st tag="function">function</control_st> is most useful when used with the <function tag="getResource">getResource</function> <control_st tag="function">function</control_st>. Use the <function tag="getResource">getResource</function> <control_st tag="function">function</control_st> to obtain resource data, process it as desired, then use the <b>setResource</b> <control_st tag="function">function</control_st> to change the <glossary tag="resource">resource</glossary>.</p><p/><p><code/><img src="202650"/> <b>Caution!</b><code/> Resource data must be in the specific format appropriate to the resource type. If you set a <glossary tag="resource">resource</glossary> to data that is incompatible with its resource type, you may damage the <glossary tag="resource">resource</glossary> or the entire <glossary tag="resource fork">resource fork</glossary> of the file. For information on the format of standard resource types, see Apple Computer's technical documentation, <i>Inside Macintosh</i>, located at &lt;<u>http://developer.apple.com/techpubs/macos8/mac8.html</u>&gt;.</p>
  </description>
</doc>