Quantcast
<OnLoad> element makes my little window invisible - WoWInterface
Thread Tools Display Modes
07-25-22, 08:34 PM   #1
Tinypower
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2022
Posts: 2
<OnLoad> element makes my little window invisible

So I have the following XML file. If I remove the line in red, the window appears alright---but it does not respond to mouse drag. If I keep this line, the window is invisible, but I can drag it---I know it because the close button can still be seen. What is causing this problem and how do I fix it?

Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<Frame name="BCHFrame" parent="UIParent" movable="true" enableMouse="true" inherits="BackdropTemplate" toplevel="true">
		<!--Anchors is a property element-->
		<Anchors>
			<!-- An anchor can be created with frame:SetPoint() method-->
			<Anchor point="LEFT" relativePoint="CENTER">
				<Offset>
					<AbsDimension x="150" y="0" />
				</Offset>
			</Anchor>
		</Anchors>
		
		<Size>
			<AbsDimension x="200" y="150" />
		</Size>
		<KeyValues>
			<!-- a list of backdropInfo: https://www.townlong-yak.com/framexml/live/Backdrop.lua -->
			<KeyValue key="backdropInfo" value="BACKDROP_DIALOG_32_32" type="global" />
		</KeyValues>
		<!-- Backdrop is now only available to frames that inherits backdrop template, and must only use BackdropInfo -->
		<!-- <Backdrop 
		bgFile="Interface\DialogFrame\UI-DialogBox-Background"
		tile="true"
		edgeFile="Interface\DialogFrame\UI-DialogBox-Border">
			<TileSize>
				<AbsValue val="32"/>
			</TileSize>
			<EdgeSize>
				<AbsValue val="32"/>
			</EdgeSize>
			<BackgroundInsets>
				<AbsInset left="11" right="12" top="12" bottom="11"/>
			</BackgroundInsets>
		</Backdrop> -->
		<Scripts>
			<OnLoad>self:RegisterForDrag("LeftButton")</OnLoad>
			<OnDragStart>self:StartMoving()</OnDragStart>
			<OnDragStop>self:StopMovingOrSizing()</OnDragStop>
		</Scripts>
		<Frames>
			<!-- close button -->
			<Button name="$parent_CloseButton" inherits="UIPanelCloseButton">
				<Anchors>
					<Anchor point="TOPRIGHT" relativePoint="TOPRIGHT">
						<Offset>
							<AbsDimension x="0" y="0" />
						</Offset>
					</Anchor>
				</Anchors>
			</Button>
		</Frames>
		
	</Frame>
</Ui>
Also, if I remove the line, but instead type in game:
Code:
/run BCHFrame:RegisterForDrag("LeftButton")
then everything seems running alright

Last edited by Tinypower : 07-25-22 at 08:38 PM.
  Reply With Quote
07-25-22, 09:24 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,540
If you have an OnLoad you can set the backdrop there:

Lua Code:
  1. <Ui xmlns="http://www.blizzard.com/wow/ui/"
  2.  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  3.     <Frame name="BCHFrame" parent="UIParent"  toplevel="true" movable="true" enableMouse="true" inherits="BackdropTemplate">
  4.         <!--Anchors is a property element-->
  5.         <Size>
  6.             <AbsDimension x="200" y="150" />
  7.         </Size>
  8.         <Anchors>
  9.             <!-- An anchor can be created with frame:SetPoint() method-->
  10.             <Anchor point="LEFT" relativePoint="CENTER">
  11.                 <Offset>
  12.                     <AbsDimension x="150" y="0" />
  13.                 </Offset>
  14.             </Anchor>
  15.         </Anchors>
  16.         <Frames>
  17.             <!-- close button -->
  18.             <Button name="$parent_CloseButton" inherits="UIPanelCloseButton">
  19.                 <Anchors>
  20.                     <Anchor point="TOPRIGHT" relativePoint="TOPRIGHT">
  21.                         <Offset>
  22.                             <AbsDimension x="0" y="0" />
  23.                         </Offset>
  24.                     </Anchor>
  25.                 </Anchors>
  26.             </Button>
  27.         </Frames>
  28.         <Scripts>
  29.             <OnLoad>
  30.                 self:SetBackdrop(BACKDROP_DIALOG_32_32)
  31.                 self:RegisterForDrag("LeftButton")
  32.             </OnLoad>
  33.             <OnDragStart>self:StartMoving()</OnDragStart>
  34.             <OnDragStop>self:StopMovingOrSizing()</OnDragStop>
  35.         </Scripts>
  36.     </Frame>
  37. </Ui>
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
07-25-22, 09:57 PM   #3
Tinypower
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jul 2022
Posts: 2
Originally Posted by Fizzlemizz View Post
If you have an OnLoad you can set the backdrop there:
Thank you very much! It works great!
  Reply With Quote
07-25-22, 10:49 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,136
To directly answer the question, BackdropTemplate uses its own OnLoad handler to set the backdrop. When you supply your own, the default behavior is to overwrite it and the original no longer runs. You can call self:OnBackdropLoaded() manually to run it in your own handler since the template still writes its function there. Alternatively, you can use the inherit property to run your handler before or after the template's by setting it to "prepend" or "append" respectively.

https://wowpedia.fandom.com/wiki/XML/Scripts
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-25-22 at 10:52 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » <OnLoad> element makes my little window invisible

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off